https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84658
--- Comment #15 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Martin Liška from comment #14) > (In reply to Richard Biener from comment #13) > > So you can loses the TREE_ADDRESSABLE restriction somewhat in requiring at > > most one decl to be TREE_ADDRESSABLE - that's the one you need to keep, the > > others may become aliases. Given TREE_ADDRESSABLE isn't reliable for > > !TREE_STATIC vars > > we can't merge any exported decls that way. Consider > > > > const int foo1; > > const int foo2; > > > > int *bar(); // in other TU, returns address of foo1 > > > > int main () > > { > > if (bar() != &foo2) > > ...; > > } > > > > not sure if we want to do hand-waving saying that we can't possibly have > > points-to sets mentioning those without seeing the function IL. Well, > > might be similarly hand-waving as the reference aliasing issue. > > > > So we could drop the TREE_STATIC restriction if TREE_ADDRESSABLE is reliable > > within the current TU. > > Note that this issue happens only with -fmerge-all-constants. And we have > caveat > in documentation that using the option, pointer comparison can be broken: > > Languages like C or C++ require each variable, > including multiple instances of the same variable in recursive > calls, to have distinct locations, so using this option results in > non-conforming behavior. > > Thus: > > $ cat test.c > const int foo1 = 3; > const int foo2 = 3; > > const int * > __attribute__((noinline)) > bar() > { > return &foo1; > } > > int main () > { > if ((bar() - &foo2) == 0) > __builtin_abort (); > > return 0; > } > > $ gcc test.c -O2 -fno-ipa-icf -fmerge-all-constants && ./a.out > Aborted (core dumped) Sure, the caveat of -fmerge-all-constants is that different constants can be merged. But that doesn't imply that the #c0 failure is fine, the testcase doesn't really care if kTestCases constant arrays from the two functions are merged together or not, if not, they will be separate, if yes, they will be the same, but if it doesn't try to compare them in any way, it should make zero difference on the behavior.