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

            Bug ID: 125344
           Summary: returned struct and inline asm with multiple
                    alternative constraints compiles incorrectly on x86_64
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chris+gcc at lulabs dot net
  Target Milestone: ---

The following C code compiles incorrectly on x86-64. bad() "loses" the value of
x and returns uninitialized memory on the stack:

struct S {
    float x;
    float y;
};

static struct S f() {
    struct S x = {42.0f, 1337.0f};
    return x;
}

float bad() {
    float x = f().x;
    asm volatile ("" : "+m,r"(x));
    return x;
}

Compile with GCC 16.1, -O1:

"bad":
        movss   xmm0, DWORD PTR [rsp-4]
        ret

(https://godbolt.org/z/485e5rjMK)

>From what I can tell, the "+m,r" constraint should be equivalent to "+mr" in
this case, which produces a correct result.

The bug appears to reproduce in all GCC versions since 4.8.1. 4.7.4 does not
have the issue.

Reply via email to