[Bug sanitizer/85777] [8/9/10 Regression] -fsanitize=undefined makes a -Wmaybe-uninitialized warning disappear
vincent-gcc at vinc17 dot net
gcc-bugzilla@gcc.gnu.org
Wed Mar 11 14:39:10 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85777
--- Comment #14 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Vincent Lefèvre from comment #1)
> I've cleaned up the testcase:
>
> int d;
> int h(void);
> void e(void)
> {
> int f[2];
> int g = 0;
> if (d)
> g++;
> if (d == 1)
> f[g++] = 2;
> (void) (f[0] || (g && h()));
> }
[...]
> but
>
> cventin% gcc-snapshot -Werror=uninitialized -Werror=maybe-uninitialized -O2
> -c file.c -fsanitize=undefined
> cventin%
I now get a warning/error as expected:
file.c: In function ‘e’:
file.c:11:12: error: ‘f[0]’ may be used uninitialized in this function
[-Werror=maybe-uninitialized]
11 | (void) (f[0] || (g && h()));
| ~^~~
cc1: some warnings being treated as errors
with gcc-10 (Debian 10-20200304-1) 10.0.1 20200304 (experimental) [master
revision 0b0908c1f27:cb0a7e0ca53:94f7d7ec6ebef49a50da777fd71db3d03ee03aa0].
But here's a new testcase:
int foo1 (void);
int foo2 (int);
int bar (void)
{
int i;
auto void cf (int *t) { foo2 (i); }
int t __attribute__ ((cleanup (cf)));
t = 0;
if (foo1 ())
i = foo1 ();
i = ! foo1 () || i;
foo2 (i);
return 0;
}
What's strange is that if I change the line
i = ! foo1 () || i;
to
i = foo1 () || i;
(i.e. if I just remove the "!", though this shouldn't change anything since GCC
does not have any knowledge on what foo1 returns), I get an error as expected:
uninit-test.c: In function ‘bar’:
uninit-test.c:15:15: error: ‘FRAME.1.i’ may be used uninitialized in this
function [-Werror=maybe-uninitialized]
15 | i = foo1 () || i;
| ~~~~~~~~^~~~
cc1: some warnings being treated as errors
More information about the Gcc-bugs
mailing list