lkml.org 
[lkml]   [2021]   [Oct]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectGCC not detecting use of uninitialized variable?
The following code does not generate a warning when compiled with GCC 
11.2.1:


int foo;

void cc_test(void)
{
int a, b;

a = 0;
a = READ_ONCE(foo); // Should be: b = READ_ONCE(foo)
do {
a += b;
b = READ_ONCE(foo);
} while (a > 0);
WRITE_ONCE(foo, a);
}


But if the loop is changed to execute only once -- replace the while
test with "while (0)" -- then gcc does warn about the uninitialized use
of b.

Is this a known problem with gcc? Is it being too conservative about
detecting uses of uninitialized variables?

Alan Stern

\
 
 \ /
  Last update: 2021-10-27 22:13    [W:0.059 / U:0.152 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site