https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107036
Bug ID: 107036
Summary: Emitted binary code changes when -g is enabled at -O1
-flto and optimize attribute
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: lto
Assignee: unassigned at gcc dot gnu.org
Reporter: tlwang at uwaterloo dot ca
CC: marxin at gcc dot gnu.org
Target Milestone: ---
This occurs when compiling attributes_program0_preprocessed.c as shown below:
$ cat attributes_program0_preprocessed.c
struct {
volatile short a;
int b;
} c = {1};
void d() { short e = c.b; }
void f() {}
void g() { c.a; }
__attribute__((optimize(0))) int main() {
f(g);
d();
}
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/scratch/software/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/tmp.KbBz3lKFoo-gcc-builder/gcc/configure
--enable-languages=c,c++,lto --enable-checking-yes --enable-multiarch
--prefix=/scratch/software/gcc-trunk --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20220925 (experimental) [master -g28a61ecdc] (GCC)
tlwang@cartesian:~/inline_asm_bugs/3966721184$ gcc-trunk -w -flto -O1
attributes_program0_preprocessed.c -o a.out ; objdump --disassemble
--section=.text a.out > no_dbg.txt
$ gcc-trunk -w -flto -O1 attributes_program0_preprocessed.c -g -o a.out ;
objdump --disassemble --section=.text a.out > dbg.txt
$ diff no_dbg.txt dbg.txt
98,100c98,101
< 401113: 0f b7 05 ee 0e 00 00 movzwl 0xeee(%rip),%eax # 402008
<c>
< 40111a: c3 retq
< 40111b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
---
> 401113: c3 retq
> 401114: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
> 40111b: 00 00 00
> 40111e: 66 90 xchg %ax,%ax