https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128668

            Bug ID: 128668
           Summary: Should the inline asm %= number change when only -g is
                    added?
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yqtian668 at gmail dot com
  Target Milestone: ---

I would like to ask whether the numeric value produced by the inline
asm %= template escape is expected to change when the same C source is
compiled with -g instead of -g0.

Reproducer (source.c, no headers):

int f(int x) { int ghost = x + 1; asm volatile ("movl $%=, %0" : "=r" (x));
return x; }

Commands on x86_64-pc-linux-gnu:

gcc -O2 -frandom-seed=1 -g0 -S source.c -o w.s
cp w.s no-debug.s
gcc -O2 -frandom-seed=1 -g -S source.c -o w.s
cp w.s with-debug.s

With GCC 17.0.0 20261015 (experimental), revision
84348add236100e5f69a3e9ec4f7b1038bf2b83d, the function
contains `movl $5, %eax` with -g0 and `movl $9, %eax` with -g.  I reproduced
the same pair of values with an existing GCC 17.0.0 20261021 native build.
Because this example uses %= as an immediate, f returns a different value.

The GCC manual (https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html)
describes %= as a number unique to each instance of an asm statement
within a compilation, and gives local labels as its use case.  I
do not see a promise that its numeric value is stable between compilations.
Is the difference above expected under this contract? 

If the value is intended to stay the same when only debug information is
enabled, a possible cause is that final_scan_insn_1 in gcc/final.cc
increments insn_counter before it filters NOTE insns.  With -g, additional
debug notes precede the asm. 

Any suggestions would be appreciated.

Reply via email to