https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109407
Bug ID: 109407
Summary: instruction cmpxchgl run error when using with g++ -O
Product: gcc
Version: 9.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: johgjc at yeah dot net
Target Milestone: ---
Created attachment 54810
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54810&action=edit
a simple test code
the following code,
when using g++ test.cpp, the a.out is a endless loop as expected.
when using g++ -O2 test.cpp, the a.out returns and prints dwOriV=8
#include<cstdint>
#include<cstdio>
int main(){
volatile int dwOriV = 32;
int8_t dwRtnV = 0;
int dwExpV = 16;
int dwDstV = 8;
while(true){
__asm__ __volatile__(
"lock;"
"cmpxchgl %[NEW_VALUE], %[DST];"
"sete %[RET];"
: [RET] "=q"(dwRtnV),[DST] "+m"(dwOriV)
:[NEW_VALUE] "r"(dwDstV), "a"(dwExpV)
: "memory", "cc"
);
if(dwRtnV) {break;}
}
printf("%d",dwOriV);
return 0;
}
my gcc version:
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.