public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* GCC not detecting use of uninitialized variable?
@ 2021-10-27 20:12 Alan Stern
  2021-10-27 20:48 ` Willy Tarreau
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Stern @ 2021-10-27 20:12 UTC (permalink / raw)
  To: Kernel development list

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-28 15:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-27 20:12 GCC not detecting use of uninitialized variable? Alan Stern
2021-10-27 20:48 ` Willy Tarreau
2021-10-28  1:47   ` Alan Stern
2021-10-28  2:35     ` Willy Tarreau
2021-10-28 15:24       ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox