https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118882
Bug ID: 118882
Summary: __has_builtin is confusing with `#pragma omp target`
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
With offloading __has_builtin makes things confusing.
clang has proposed to deprecating __has_builtin and adding a new method which
is dependent on the context of at least host vs target offloading.
See https://github.com/llvm/llvm-project/pull/126324 for the full back story.
For GCC an example is:
```
int main() {
int x = 0;
#pragma omp target
{
for(int i = 0; i < 100; i++) {
#if __has_builtin(__builtin_ia32_pause)
__builtin_ia32_pause();
#endif
x+= i;
}
}
return x;
}
```
And compile/link with:
```
g++-14 -fopenmp -foffload=amdgcn-amdhsa="-march=gfx1103" foo.cpp
-fcf-protection=none
```
Gives:
```
lto1: fatal error: target specific builtin not available
compilation terminated.
gcn mkoffload: fatal error: x86_64-linux-gnu-accel-amdgcn-amdhsa-gcc-14
returned 1 exit status
compilation terminated.
lto-wrapper: fatal error:
/usr/libexec/gcc/x86_64-linux-gnu/14//accel/amdgcn-amdhsa/mkoffload returned 1
exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
```