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

            Bug ID: 65402
           Summary: global register variables miscompiled when unit
                    contains sse4.2 functions
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mattiase at acm dot org

The mere presence of a function with the attribute target("sse4.2") is enough
for gcc to miscompile other functions with respect to global register
variables:

---------------- code below! -----------------
__attribute__((target("sse4.2"))) void F(void) {}

register long gr1 asm("r12");
register long gr2 asm("r13");

long G(void);

int H(void) {
  gr1 = G();   /* Any code at all, really. */
  return 1;
}
----------------- code above! ----------------

The existence of F causes H to save/restore all global register variables in
its prologue/epilogue, which of course makes these variables impossible to use
inside H. Comment out the definition of F, and the problem disappears.

This occurs in GCC 4.9.2 on x86-64 (Linux), with -O0 or -O2.

Possible workaround: move the register declarations to above F. This is not
always easy (in our case, F is really the stuff in ia32intrin.h that happened
to be included from header files that we need for the types in the register
variable declarations).

Although it's good practice to put the global register declarations at the top
of the unit, not doing so shouldn't cause functions below to be miscompiled.

This appears to be a regression; the bug is not present in GCC 4.8.1.

Reply via email to