[Bug regression/24956] Optimizer and uninitialised variables.
--- Comment #1 from falk at debian dot org 2005-11-20 13:33 --- There is no correct output when you use a variable uninitialized. It's undefined behavior. Printing any number, or crashing, would be completely valid behaviors as far as gcc is concerned. -- falk at debian dot org changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24956
[Bug regression/24956] Optimizer and uninitialised variables.
--- Comment #2 from pcarlini at suse dot de 2005-11-20 13:37 --- (In reply to comment #1) There is no correct output when you use a variable uninitialized. It's undefined behavior. Printing any number, or crashing, would be completely valid behaviors as far as gcc is concerned. Falk, of course you are right. However, when I saw the PR coming, I wondered whether the point was also that it would be nice having the warning emitted also at low optimization levels. Other compilers can do that, AFAIK. Maybe we already have something open about that, tough, as enhancement request. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24956
[Bug regression/24956] Optimizer and uninitialised variables.
--- Comment #3 from s_a_white at email dot com 2005-11-20 14:15 --- Sorry the summary may not be 100% correct, but it is related to the variable never being directly assigned. I do understand that using (i.e. assigning from an unintialised variable) will give you random junk, etc. However if you look at the example below you'll see the variable becomes fully assigned (the result is always known given a uint_least32_t being 32 bits). And indeed the first printf does display the correct answer. However whats happened is that some of the code inside the if statement has executed, which is should never have! Please if this code is actually invalid... and indeed somehow the code inside the if statement can legally be executed please could you reclose the bug and drop me a note on why? So far have never seen even highly optimising compilers (e.g. TI c6x, etc) do this. -- s_a_white at email dot com changed: What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24956
[Bug regression/24956] Optimizer and uninitialised variables.
--- Comment #4 from falk at debian dot org 2005-11-20 14:35 --- I already explained this. Using an uninitialized variable invokes undefined behavior. This means that producing random junk, executing random if statements, executing random if statements 17 times, formatting your hard disk, and making demons fly out of your nose are all perfectly valid results. The concept of undefined behavior should be explained in any C book. -- falk at debian dot org changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24956
[Bug regression/24956] Optimizer and uninitialised variables.
--- Comment #5 from pinskia at gcc dot gnu dot org 2005-11-20 15:18 --- Reopening to ... -- pinskia at gcc dot gnu dot org changed: What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24956
[Bug regression/24956] Optimizer and uninitialised variables.
--- Comment #6 from pinskia at gcc dot gnu dot org 2005-11-20 15:18 --- Mark as a dup of bug 22266. *** This bug has been marked as a duplicate of 22266 *** -- pinskia at gcc dot gnu dot org changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||DUPLICATE http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24956