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

            Bug ID: 100921
           Summary: Inline assembly use of struct not counted as use for
                    store elision
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ethereal at ethv dot net
  Target Milestone: ---

The following functions do not compile to the same result: (example is for
x86_64)

    extern "C" void consumer(int *);
    void example1() {
        int v;
        // this store will be elided as `v` is somehow never considered "read"
        v = 0x12345; // some special constant
        __asm__ __volatile__("call consumer" : : "D"(&v));
        // random value has now been used
    }
    void example2() {
        int v;
        // this store is _not_ elided, it's kept around
        // even though the behaviour should be identical to example1
        v = 0x12345;
        consumer(&v);
    }

The use of `call` is not special, this appears to happen with any inline
assembly, including e.g. `mov`, `lgdt`, and `fld`. However, in both cases the
variable is "used" in the same way (taking the address of an initialized
variable), but are treated differently.

Various GCC versions tested (11.1, 9.3, 7.5, 6.4) all produce the same output.
clang outputs differently, and with the expected result for various versions
(3.3, 5.0, 12.0). Here's a godbolt link: https://godbolt.org/z/dWhx3zfse

Reply via email to