| Issue |
243013
|
| Summary |
[X86] Wrong value of a flag output (`=@ccc`) on the indirect path of asm goto
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
mu-mu-mu
|
On x86-64, the following program prints an unexpected value with clang at -O1 or above. With -O0, it prints the expected value.
```c
#include <stdio.h>
int f(void)
{
int cf = 42;
asm goto("stc\n\tjc %l1" : "=@ccc"(cf) : : : carry);
return 0;
carry:
return cf + 2;
}
int main(void)
{
printf("expected: 3, actual: %d\n", f());
}
```
```console
$ clang -O2 test.c && ./a.out
expected: 3, actual: 2
```
Expected: `stc` sets CF, so `cf` is 1 on the indirect path and `f` returns 3, as with clang -O0 and GCC.
On the indirect target, `xorl` clears CF before `adcl` reads it:
```asm
f:
xorl %eax, %eax
stc
jb .LBB0_1
retq
.LBB0_1:
xorl %eax, %eax
adcl $2, %eax
retq
```
clang (trunk): https://godbolt.org/z/djjj45GKW
gcc (trunk): https://godbolt.org/z/PKh9ejcs1
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs