With -Og we do no constant propagation after folding all remaining builtins which is a problem when RTL expansion issues errors such as those for function calls to functions with the error attribute.
Fixed as follows, bootstrap and regtest pending on x86_64-unknown-linux-gnu. Richard. 2013-06-24 Richard Biener <rguent...@suse.de> PR middle-end/56977 * passes.c (init_optimization_passes): Move pass_fold_builtins and pass_dce earlier with -Og. * gcc.dg/pr56977.c: New testcase. Index: gcc/passes.c =================================================================== *** gcc/passes.c (revision 200367) --- gcc/passes.c (working copy) *************** init_optimization_passes (void) *** 1536,1550 **** /* Perform simple scalar cleanup which is constant/copy propagation. */ NEXT_PASS (pass_ccp); NEXT_PASS (pass_object_sizes); /* Copy propagation also copy-propagates constants, this is necessary ! to forward object-size results properly. */ NEXT_PASS (pass_copy_prop); NEXT_PASS (pass_asan); NEXT_PASS (pass_tsan); NEXT_PASS (pass_rename_ssa_copies); - NEXT_PASS (pass_dce); - /* Fold remaining builtins. */ - NEXT_PASS (pass_fold_builtins); /* ??? We do want some kind of loop invariant motion, but we possibly need to adjust LIM to be more friendly towards preserving accurate debug information here. */ --- 1536,1550 ---- /* Perform simple scalar cleanup which is constant/copy propagation. */ NEXT_PASS (pass_ccp); NEXT_PASS (pass_object_sizes); + /* Fold remaining builtins. */ + NEXT_PASS (pass_fold_builtins); /* Copy propagation also copy-propagates constants, this is necessary ! to forward object-size and builtin folding results properly. */ NEXT_PASS (pass_copy_prop); + NEXT_PASS (pass_dce); NEXT_PASS (pass_asan); NEXT_PASS (pass_tsan); NEXT_PASS (pass_rename_ssa_copies); /* ??? We do want some kind of loop invariant motion, but we possibly need to adjust LIM to be more friendly towards preserving accurate debug information here. */ Index: gcc/testsuite/gcc.dg/pr56977.c =================================================================== *** gcc/testsuite/gcc.dg/pr56977.c (revision 0) --- gcc/testsuite/gcc.dg/pr56977.c (working copy) *************** *** 0 **** --- 1,10 ---- + /* { dg-do compile } */ + /* { dg-options "-Og" } */ + + __attribute__((__error__("error"))) void error (); + + void f (int i) { + if (__builtin_constant_p (i)) { + error (); + } + }