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

            Bug ID: 122980
           Summary: asm() 'c' operand modifier not working consistently
           Product: gcc
           Version: 15.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jbeulich at suse dot com
  Target Milestone: ---

I've collected the following, likely still incomplete, list of issues with this
modifier (including observations on x86 with the 'p' and 'P' modifiers as
well):

extern const unsigned char garr[];

void test(void) {
        // None of these work for RISC-V.
        // All of these work for Arm32, Arm64, and PPC.
        asm volatile(".long %c0" :: "i" (0x12345678U));
        asm volatile(".long %c0" :: "i" (0x87654321U));         // bogus
(negative in .s)
        asm volatile(".quad %c0" :: "i" (0x87654321U));         // wrong
        // These don't work for x86.
        asm volatile(".quad %c0" :: "i" (0x87654321UL));        // wrong for
32-bit targets
        asm volatile(".quad %c0" :: "i" (&garr[0x12345678U]));
        asm volatile(".quad %c0" :: "i" (&garr[0x87654321U]));  // bogus
warning for 32-bit targets

#if defined(__i386__) || defined(__x86_64__)
        asm("/*** SEPARATOR ***/");

        asm volatile(".long %p0" :: "i" (0x12345678U));
        asm volatile(".long %p0" :: "i" (0x87654321U));         // bogus
(negative in .s)
        asm volatile(".quad %p0" :: "i" (0x87654321U));         // wrong
        asm volatile(".quad %p0" :: "i" (0x87654321UL));        // wrong for
ix86
        asm volatile(".quad %p0" :: "i" (&garr[0x12345678U]));
        asm volatile(".quad %p0" :: "i" (&garr[0x87654321U]));  // bogus
warning for ix86

        asm("/*** SEPARATOR ***/");

        asm volatile(".long %P0" :: "i" (0x12345678U));
        asm volatile(".long %P0" :: "i" (0x87654321U));         // bogus
(negative in .s)
        asm volatile(".quad %P0" :: "i" (0x87654321U));         // wrong
        asm volatile(".quad %P0" :: "i" (0x87654321UL));        // wrong for
ix86
        asm volatile(".quad %P0" :: "i" (&garr[0x12345678U]));
        asm volatile(".quad %P0" :: "i" (&garr[0x87654321U]));  // bogus
warning for ix86
#endif
}

Patches to address at least part of these were sent over a year ago:
https://gcc.gnu.org/pipermail/gcc-patches/2024-November/669681.html

Despite pinging twice, there was no response. Maybe what I'm doing it entirely
wrong, and fixing the issue needs going a completely different route.

Not sure whether bug 116540 is possibly related.

Reply via email to