https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100781
Bug ID: 100781
Summary: Emitted binary code changes when -g is enabled at -O2
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: tlwang at uwaterloo dot ca
Target Milestone: ---
The .text section for the following program (transformed_program0.c) changes
after toggling the -g flag.
$ cat transformed_program0.c
struct a {
int b;
};
long c(short d, long e, struct a f) {
g:;
int h = f.b <= e, i = d, n = h >= d;
if (!n)
goto j;
goto k;
j:;
long l = 5;
if (l)
goto m;
d = 0;
m:
if (d)
return f.b;
k:
goto g;
}
int main() {}
$
$ 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/12.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/tmp.tVhv2eaPzV-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 12.0.0 20210526 (experimental) [master revision
:21638bbbf:1fd76b24306ed4df4cf9e797d900699ed59ce7f7] (GCC)
$
$ gcc-trunk transformed_program0.c -O2 -w ; objdump --disassemble a.out >
"no-g.txt"
$ gcc-trunk transformed_program0.c -O2 -w -g; objdump --disassemble a.out >
"g.txt"
$ diff no-g.txt g.txt
108,111c108,111
< 401125: 89 f9 mov %edi,%ecx
< 401127: 0f bf ff movswl %di,%edi
< 40112a: 49 39 f0 cmp %rsi,%r8
< 40112d: 0f 9e c0 setle %al
---
> 401125: 0f bf ff movswl %di,%edi
> 401128: 4c 39 c6 cmp %r8,%rsi
> 40112b: 0f 9d c0 setge %al
> 40112e: 66 90 xchg %ax,%ax
114,118c114,117
< 401134: 66 85 c9 test %cx,%cx
< 401137: 74 f7 je 401130 <c+0x10>
< 401139: 4c 89 c0 mov %r8,%rax
< 40113c: c3 retq
< 40113d: 0f 1f 00 nopl (%rax)
---
> 401134: 4c 89 c0 mov %r8,%rax
> 401137: c3 retq
> 401138: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
> 40113f: 00