https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98902
Bug ID: 98902
Summary: -fmerge-all-constants leaves dangling reference
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: astrange at ithinksw dot com
Target Milestone: ---
This source:
--
#include <stdio.h>
static const int a1[] = {1};
static const int a2[] = {1};
int main (void)
{
printf("%p %p\n", a1, a2);
return 0;
}
--
produces code where it doesn't emit 'a2' but still references it:
--
.LC0:
.string "%p %p\n"
main:
sub rsp, 8
mov edx, OFFSET FLAT:a2
mov esi, OFFSET FLAT:a1
xor eax, eax
mov edi, OFFSET FLAT:.LC0
call printf
xor eax, eax
add rsp, 8
ret
a1:
.long 1
--
with '-O2 -fmerge-all-constants'. Did not verify this locally, just in compiler
explorer.