From: Alejandro Colomar <alx.manpages@gmail.com>
To: gcc@gcc.gnu.org
Cc: Martin Uecker <uecker@tugraz.at>, Joseph Myers <joseph@codesourcery.com>
Subject: [BUG] -Wuninitialized: initialize variable with itself
Date: Sun, 13 Nov 2022 19:34:45 +0100 [thread overview]
Message-ID: <9711434a-daff-5422-d69b-2c8eaca5ad1e@gmail.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1522 bytes --]
Hi,
While discussing some idea for a new feature, I tested the following example
program:
int main(void)
{
int i = i;
return i;
}
It seems obvious that it should give a warning, and in Clang it does:
$ clang --version | head -n1
Debian clang version 14.0.6
$ clang -Wall -Wextra foo.c
foo.c:3:10: warning: variable 'i' is uninitialized when used within its own
initialization [-Wuninitialized]
int i = i;
~ ^
1 warning generated.
But for GCC it looks fine:
$ gcc --version | head -n1
gcc (Debian 12.2.0-9) 12.2.0
$ gcc -Wall -Wextra foo.c
$
Until you enable the analyzer, which catches the uninitialized use:
$ gcc -fanalyzer foo.c
foo.c: In function ‘main’:
foo.c:3:13: warning: use of uninitialized value ‘i’ [CWE-457]
[-Wanalyzer-use-of-uninitialized-value]
3 | int i = i;
| ^
‘main’: events 1-2
|
| 3 | int i = i;
| | ^
| | |
| | (1) region created on stack here
| | (2) use of uninitialized value ‘i’ here
|
I expect that GCC should be able to detect this bug with a simple warning. The
analyzer is quite unreadable compared to normal warnings.
Cheers,
Alex
--
<http://www.alejandro-colomar.es/>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2022-11-13 18:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-13 18:34 Alejandro Colomar [this message]
2022-11-13 18:40 ` Andrew Pinski
2022-11-13 18:41 ` Andrew Pinski
2022-11-13 18:43 ` Alejandro Colomar
2022-11-14 9:41 ` David Brown
2022-11-14 11:30 ` Alejandro Colomar
2022-11-14 15:10 ` NightStrike
2022-11-14 15:49 ` David Brown
2022-11-14 17:43 ` NightStrike
2022-11-13 18:45 ` Andrew Pinski
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=9711434a-daff-5422-d69b-2c8eaca5ad1e@gmail.com \
--to=alx.manpages@gmail.com \
--cc=gcc@gcc.gnu.org \
--cc=joseph@codesourcery.com \
--cc=uecker@tugraz.at \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).