https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89145
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization Status|UNCONFIRMED |NEW Last reconfirmed| |2019-02-01 CC| |msebor at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- I can confirm this, though it's a known limitation documented in the symtab_node::equal_address_to() function in symtab.c, and there probably is at least one bug about it in Bugzilla. /* TODO: Alias oracle basically assume that addresses of global variables are different unless they are declared as alias of one to another while the code folding comparsions doesn't. We probably should be consistent and use this fact here, too, but for the moment return false only when we are called from the alias oracle. */ This refers to assumptions about extern variables being distinct such as in the test case below: int bar (void) { int tmp = a; b = 0; if (tmp != a) // folded to false __builtin_abort (); // eliminated } As a data point, Clang folds the the equality in the test case in comment #0 to false. That said, GCC itself makes it easy to violate this assumptions by making it possible to define aliases such as in: int a; extern __attribute__ ((alias ("a"))) int b; extern int foo (void); int main (void) { int i = foo (); __builtin_printf ("%i\n", i); }