Issue 135547
Summary Simple function integer return corrupted.
Labels new issue
Assignees
Reporter Manderby
    I stumbled upon a quirky little bug which I can not identify. A simple C program with C11, compiling in XCode. I use the following setup:
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.5.0
Thread model: posi

The following computes twice the same value. Please do not bother about how and why I do this.
```
int testGetSignum32(int i) {
  return (i >> (32 - 1));
}
int testAbsi(int i) {
  int signum = testGetSignum32(i);
  return (signum ^ i) - signum;
}
int main(int argc, const char** argv) {
  int myVar = 0x80000000;
  int signum = testGetSignum32(myVar);
  printf("%x, %x\n", testAbsi(myVar), (signum ^ myVar) - signum);
  return 0;
}
```
When running with optimized code generation, The result is `1c60, ffffffff`. But the two results should be the same.

Funnily, if I add another value to the output, it changes. For example:
```
  printf("%x, %x, %x\n", testAbsi(myVar), (signum ^ myVar) - signum, 0);
```
results in `6fdff2f0, 80000000, 0`

And if I switch places of the two arguments of the original line, I get `80000000, 47a0a0`

MSVC has no problems with that piece of code.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to