Issue 90047
Summary User defined SIN function is not called with O3 opt level
Labels new issue
Assignees
Reporter ararmine
    When compiling the following example with clang -O3 opt level, the program does not print the expected output, the user defined sin function is not called and the sin library function is called instead. While with -O0 level it works as expected.
Steps to reproduce:
```
cat bug.cpp 
#include <stdio.h>

extern "C" double sin(double x) {
  printf ("Inside the sin function\n");
 return 0.0;
}

int main() {
  printf ("Call 1 %f\n", sin(3.3));
  printf ("Call 2 %f\n", ::sin(3.3));
}
```
With clang 18.1.0
```
clang++ -O0 bug.cpp
./a.out
Inside the sin function
Call 1 0.000000
Inside the sin function
Call 2 0.000000

clang++ -O3 bug.cpp
./a.out
Inside the sin function
Call 1 -0.157746
Inside the sin function
Call 2 -0.157746
```

When compiling the program with GCC 13.2 , the output is expected with both opt. levels.
```
g++ -O0 bug.cpp
./a.out
Inside the sin function
Call 1 0.000000
Inside the sin function
Call 2 0.000000

g++ -O3 bug.cpp
./a.out
Inside the sin function
Call 1 0.000000
Inside the sin function
Call 2 0.000000
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to