This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/39375] New: asm with a "=X" output overwrites the output


The info pages give something like
__asm__ ("xxx" : "=X" (sum));
as an example of adding a hint for gcc that the instruction clobbers "sum". 
However if the variable is an array element, gcc will clobber the variable for
you (in case you forgot) by generating a move from a random register to the
variable.  I don't know if liveness analysis is done on element basis for
arrays, but it doesn't generate warnings either.
Similarly for "=X" but not "=m" or "=r".

For example on x86,
__asm__ ("outl %%eax, (%%dx)" : "=X" (params[1]));
to indicate that the IO causes params[1] to be overwritten, results in:
  400532:       ef                      out    %eax,(%dx)
  400533:       89 45 f4                mov    %eax,-0xc(%rbp)
with all -O levels.

Similarly on ARM a move from r3 is generated that overwrites the array element.


-- 
           Summary: asm with a "=X" output overwrites the output
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: balrogg at gmail dot com
 GCC build triplet: x86_64-linux-gnu, arm-linux-gnueabi
  GCC host triplet: x86_64-linux-gnu, arm-linux-gnueabi


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39375


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]