https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89145
Bug ID: 89145
Summary: GCC does not assume that two different external
variables have different addresses
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
The module:
**
extern int p;
extern int q;
int foo (void)
{
return &p == &q;
}
**
is compiled by `gcc -O3' to:
**
foo:
movl $p, %eax
cmpq $q, %rax
sete %al
movzbl %al, %eax
ret
**
When at least one of the variables is declared static, gcc's optimizer kicks in
and yields:
**
foo:
xorl %eax, %eax
ret
**
Either, `gcc' is missing an optimization in the case of external variables, or
the addresses of different external variables can be the same, which sounds
strange to me.
A test with clang showed that it always produces the latter, optimized version.