#include <signal.h>
#include <unistd.h>
int test;
void handler (int sig)
{
test = 1;
}
int main()
{
signal (SIGALRM, handler);
alarm (1);
while (test == 0)
asm("");
return 0;
}
Results in an infinite loop with -O2. The load of test in main should not
be hoisted out of the loop. A more x86-specific example (but without relying
on unix syscalls might be
int test;
int main()
{
int x = test;
asm("movl $1,test");
if (x + test != 1)
__builtin_trap ();
return 0;
}
It also wouldn't surprise me if the two tests have different culprits...
--
Summary: Old-style asms don't clobber memory
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rth at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24414