c/9242: GCC sometimes removes important asm statements

adam@os.inf.tu-dresden.de adam@os.inf.tu-dresden.de
Thu Jan 9 13:06:00 GMT 2003


>Number:         9242
>Category:       c
>Synopsis:       GCC sometimes removes important asm statements
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 09 05:06:01 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Adam Lackorzynski
>Release:        gcc version 3.2.2 20030108 (prerelease)
>Organization:
>Environment:
Debian woody/stable 3.0r1, x86, Linux 2.4.20
>Description:
Compiling the provided code the asm statements may not appear in the binary.

When compiling with -O2 or -O3 the resulting binary doesn't conain a "sti" statement.
When removing the "int a = 2 + a;" line from nothing() and compiling with -O2, there's as well no "sti" statement.
But compiling with -O3 it's there! And the code looks reasonable.
In the wrong cases there's a "hlt" in the code but on a rather suspicious place (i.e. not where one would expect it).
>How-To-Repeat:
void nothing(void) {
  int a = 2 + a;
}
int main(void) {
  int r = 1;
  while (r) {
    asm volatile ("sti");
    asm volatile ("hlt");

    while (r)
      nothing();
  }
  return 0;
}

Compiled with
   $ gcc -O2 -Wall -o z z.c
or $ gcc -O3 -Wall -o z z.c
and then:
   objdump -d z 
to see the resulting code
>Fix:
Add "cc" or "memory" to the clobber list of one asm statement.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-prs mailing list