------- Comment #6 from rguenth at gcc dot gnu dot org 2009-01-09 22:57 ------- Ok, I'm convinced. That jump-threading is really weird. But only because __builtin_constant_p isn't a regular function that is executed on a path of the CFG, it really is supposed to be evaluating all paths through the CFG going through it. Which of course conflicts with what jump threading does.
OTOH void foo (bool b) { if (__builtin_constant_p (b)) boo (); else yeah (); } is then not equivalent to void foo (bool b) { if (b == true) { if (__builtin_constant_p (b)) ... } else if (b == false) { if (__builtin_constant_p (b)) .... } } That makes exact definition of the behavior of __builtin_constant_p not easier. That is, the manual states "You can use the built-in function @code{__builtin_constant_p} to determine if a value is known to be constant at compile-time and hence that GCC can perform constant-folding on expressions involving that value." which is true for the second variant but not for the first. Still if __builtin_constant_p were a regular function both programs would be equivalent. -- rguenth at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Last reconfirmed|0000-00-00 00:00:00 |2009-01-09 22:57:03 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789