https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115332
Bug ID: 115332 Summary: Using label-as-value in asm statement removes label Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: mr.bossman075 at gmail dot com Target Milestone: --- $ riscv64-unknown-elf-gcc -v Using built-in specs. COLLECT_GCC=riscv64-unknown-elf-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/riscv64-unknown-elf/13.2.0/lto-wrapper Target: riscv64-unknown-elf Configured with: ../gcc-13.2.0/configure --build=x86_64-linux-gnu --prefix=/usr --includedir='/usr/lib/include' --mandir='/usr/lib/share/man' --infodir='/usr/lib/share/info' --sysconfdir=/etc --localstatedir=/var --disable-option-checking --disable-silent-rules --libdir='/usr/lib/lib/x86_64-linux-gnu' --libexecdir='/usr/lib/lib/x86_64-linux-gnu' --disable-maintainer-mode --disable-dependency-tracking --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/doc/gcc-riscv64-unknown-elf/info --mandir=/usr/share/man --htmldir=/usr/share/doc/gcc-riscv64-unknown-elf/html --pdfdir=/usr/share/doc/gcc-riscv64-unknown-elf/pdf --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --with-system-zlib --enable-multilib --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-libstdc++-v3 --disable-nls --disable-shared --disable-threads --with-arch=rv64imafdc --enable-tls --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=riscv64-unknown-elf --with-gnu-as --with-gnu-ld --with-headers=no --without-newlib --with-pkgversion=13.2.0-10+12 --without-included-gettext SED=/bin/sed SHELL=/bin/sh BASH=/bin/bash CONFIG_SHELL=/bin/bash AR_FOR_TARGET=riscv64-unknown-elf-ar AS_FOR_TARGET=riscv64-unknown-elf-as LD_FOR_TARGET=riscv64-unknown-elf-ld NM_FOR_TARGET=riscv64-unknown-elf-nm OBJDUMP_FOR_TARGET=riscv64-unknown-elf-objdump RANLIB_FOR_TARGET=riscv64-unknown-elf-ranlib READELF_FOR_TARGET=riscv64-unknown-elf-readelf STRIP_FOR_TARGET=riscv64-unknown-elf-strip ASFLAGS= ASFLAGS_FOR_BUILD= CFLAGS='-g -O2 -ffile-prefix-map=/build/reproducible-path/gcc-riscv64-unknown-elf-12=. -fstack-protector-strong -fstack-clash-protection -fcf-protection' 'CFLAGS_FOR_BUILD=-g -O2' CPPFLAGS='-Wdate-time -D_FORTIFY_SOURCE=2' CPPFLAGS_FOR_BUILD= CXXFLAGS='-g -O2 -ffile-prefix-map=/build/reproducible-path/gcc-riscv64-unknown-elf-12=. -fstack-protector-strong -fstack-clash-protection -fcf-protection' 'CXXFLAGS_FOR_BUILD=-g -O2' DFLAGS=-frelease DFLAGS_FOR_BUILD=-frelease FCFLAGS='-g -O2 -ffile-prefix-map=/build/reproducible-path/gcc-riscv64-unknown-elf-12=. -fstack-protector-strong -fstack-clash-protection -fcf-protection' 'FCFLAGS_FOR_BUILD=-g -O2' FFLAGS='-g -O2 -ffile-prefix-map=/build/reproducible-path/gcc-riscv64-unknown-elf-12=. -fstack-protector-strong -fstack-clash-protection -fcf-protection' 'FFLAGS_FOR_BUILD=-g -O2' LDFLAGS='-Wl,-z,relro -Wl,-z,now' LDFLAGS_FOR_BUILD= OBJCFLAGS='-g -O2 -ffile-prefix-map=/build/reproducible-path/gcc-riscv64-unknown-elf-12=. -fstack-protector-strong -fstack-clash-protection -fcf-protection' 'OBJCFLAGS_FOR_BUILD=-g -O2' OBJCXXFLAGS='-g -O2 -ffile-prefix-map=/build/reproducible-path/gcc-riscv64-unknown-elf-12=. -fstack-protector-strong -fstack-clash-protection -fcf-protection' 'OBJCXXFLAGS_FOR_BUILD=-g -O2' INHIBIT_LIBC_CFLAGS=-DUSE_TM_CLONE_REGISTRY=0 'CFLAGS_FOR_TARGET=-Os -mcmodel=medany' 'CXXFLAGS_FOR_TARGET=-Os -mcmodel=medany' Thread model: single Supported LTO compression algorithms: zlib gcc version 13.2.0 (13.2.0-10+12) int test_labels() { void *label = &&l; long val; asm volatile("mv %0, %1" : "=r" (val) : "r" (label) : "memory"); return 1; l: return 0; } int test_labels2() { void *label = &&l; long val; asm volatile goto("mv %0, %1" : "=r" (val) : "r" (label) : "memory": l); return 1; l: return 0; } In the above code in `test_labels` the label `l` will be removed even though we are using the "label as value" in the asm statement. The second test uses asm goto to tell the compiler that the label is used. The compilation output is what would be expected of the first. The above code was compiled with the command below. This doesn't appear to be architecture-dependent, but was originally found on riscv. riscv64-unknown-elf-gcc -S -c -O1 -Wall -Wextra -fno-strict-aliasing -fwrapv test.c -o- The output of the above command is: .file "test.c" .option nopic .attribute arch, "rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0" .attribute unaligned_access, 0 .attribute stack_align, 16 .text .align 1 .globl test_labels .type test_labels, @function test_labels: .L2: lui a5,%hi(.L2) addi a5,a5,%lo(.L2) ### Note here that .L2 is the same as test_labels #APP # 6 "test.c" 1 mov a5, a5 # 0 "" 2 #NO_APP li a0,1 ret .size test_labels, .-test_labels .align 1 .globl test_labels2 .type test_labels2, @function test_labels2: lui a5,%hi(.L4) addi a5,a5,%lo(.L4) #APP # 20 "test.c" 1 mov a5, a5 # 0 "" 2 #NO_APP li a0,1 ret .L5: li a0,0 .L4: ret .size test_labels2, .-test_labels2 .ident "GCC: (13.2.0-10+12) 13.2.0" Here is another example using arm: https://godbolt.org/z/cqEzPvrGx I'm not entirely sure if this is a duplicate of Bug 44298, but the premise is slightly different so I'll ask anyway. Even if this isn't a bug, which is understandable, why doesn't it generate a warning that the label was moved?