From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Daniel P. Berrangé" <berrange@redhat.com>,
"Juan Quintela" <quintela@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH] Change the default for Mixed declarations.
Date: Fri, 24 Mar 2023 09:43:37 +0100 [thread overview]
Message-ID: <30389414-2646-63ab-52eb-5ce08b3ab3b4@linaro.org> (raw)
In-Reply-To: <ZByhueDO9J9MLuSJ@redhat.com>
On 23/3/23 20:00, Daniel P. Berrangé wrote:
> On Tue, Feb 14, 2023 at 05:07:38PM +0100, Juan Quintela wrote:
>> Hi
>>
>> I want to enter a discussion about changing the default of the style
>> guide.
>>
>> There are several reasons for that:
>> - they exist since C99 (i.e. all supported compilers support them)
>> - they eliminate the posibility of an unitialized variable.
>
> Actually they don't do that reliably. In fact, when combined
> with usage of 'goto', they introduce uninitialized variables,
> despite the declaration having an initialization present, and
> thus actively mislead reviewers into thinking their code is
> safe.
> IMHO the status quo is bad because it is actively dangerous when
> combined with goto and we aren't using any compiler warnings to
> help us.
Thanks, TIL this, interesting.
> Either we allow it, but use -Wjump-misses-init to prevent mixing
> delayed declarations with gotos, and just avoid this when it triggers
> a false positive.
>
> Or we forbid it, rewrite current cases that use it, and then add
> -Wdeclaration-after-statement to enforce it.
I guess various macros (Q/LIST/FOO_FOREACH_BAR i.e.) already abuse that.
> IMHO if we are concerned about uninitialized variables then I think
> a better approach is to add -ftrivial-auto-var-init=zero, which will
> make the compiler initialize all variables to 0 if they lack an
> explicit initializer.
But we need to be aware of:
With the option '-ftrivial-auto-var-init', all the automatic
variables that do not have explicit initializers will be
initialized by the compiler. These additional compiler
initializations might incur run-time overhead, sometimes
dramatically.
Also:
‘pattern’ Initialize automatic variables with values which will
likely transform logic bugs into crashes down the line, are easily
recognized in a crash dump and without being values that programmers
can rely on for useful program semantics. The current value is
byte-repeatable pattern with byte "0xFE". The values used for
pattern initialization might be changed in the future.
If we use -ftrivial-auto-var-init, could the
-ftrivial-auto-var-init=pattern form could be more beneficial to us?
next prev parent reply other threads:[~2023-03-24 14:56 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-14 16:07 [PATCH] Change the default for Mixed declarations Juan Quintela
2023-03-23 19:00 ` Daniel P. Berrangé
2023-03-24 8:43 ` Philippe Mathieu-Daudé [this message]
2023-03-24 14:04 ` Alex Bennée
2023-03-24 17:39 ` Juan Quintela
2023-03-24 17:56 ` Alex Bennée
2023-03-27 9:12 ` Daniel P. Berrangé
2023-03-27 10:49 ` Markus Armbruster
2023-03-27 9:10 ` Daniel P. Berrangé
2023-03-27 10:45 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=30389414-2646-63ab-52eb-5ce08b3ab3b4@linaro.org \
--to=philmd@linaro.org \
--cc=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.