[clang] [Clang] Add __has_target_builtin macro (PR #126324)

Nick Sarnie via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 13 09:07:19 PST 2025


sarnex wrote:

> GCC has __has_builtin, so how do they handle offloading targets? Do they have the same odd behavior where __has_builtin returns true for builtins it cannot actually emit code for?

Setting up offloading for GCC was a nightmare, but it looks like the behavior is the same as clang (available builtins are the union of host + offload).

I tried this example:
```
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;
}
```

with flags:
```
g++-14 -fopenmp -foffload=amdgcn-amdhsa="-march=gfx1103" foo.cpp -fcf-protection=none 
```

and i got
```
lto1: fatal error: target specific builtin not available
```

https://github.com/llvm/llvm-project/pull/126324


More information about the cfe-commits mailing list