Issue |
119849
|
Summary |
[x86][CF]Unable to obtain the correct CF flag bit
|
Labels |
new issue
|
Assignees |
|
Reporter |
zhaojiangkun-1
|
Retrieve the CF register flag bit through __readeflags() and verify if the parameters are equal.
Clang generates the 'and' instruction after compilation, and clears the CF flag after executing the 'and' instruction. Is this a bug or is it for some purpose? Resulting in the inability to obtain correct results through __readeflags().
https://godbolt.org/z/4oaWeKxY1
**How did I do it**
1)`clang -g test.c -o -test`
2)`cgdb test`
3) run to ` flags = readeflags_test (100, 101)` and debug in assembly
**the debug result**

**test script:**
```#include <x86intrin.h>
extern void abort (void);
#ifdef __x86_64__
#define EFLAGS_TYPE unsigned long long int
#else
#define EFLAGS_TYPE unsigned int
#endif
EFLAGS_TYPE
readeflags_test (unsigned int a, unsigned int b)
{
volatile char x = (a == b);
return __readeflags ();
}
int
main ()
{
EFLAGS_TYPE flags;
flags = readeflags_test (100, 100);
if ((flags & 1) != 0) /* Read CF */
abort ();
flags = readeflags_test (100, 101);
flags = readeflags_test(101, 100);//新增测试用例,用于验证比较对CF的影响
if ((flags & 1) == 0) /* Read CF */
abort ();
#ifdef DEBUG
printf ("PASSED\n");
#endif
return 0;
}
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs