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

Artem Belevich via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 14 12:09:39 PST 2025


Artem-B wrote:

> why there's a __has_builtin that's different from __can_use_builtin (or whatever we name it), and I don't know that any of us have an answer for that

my $.02
IMO it's a side effect of heterogeneous compilation, where compiler has to parse source code for multiple targets (and thus has to see each target's builtins), but can generate code only for the target we're currently compiling for. `__can_use_builtin` will give us a way to distinguish the two. It's not a perfect tool, because usability of a builtin depends on the context, but it's better than nothing.

For the classic compilation, `__has_builtin` is unambiguous.

On the other hand, AFAICT, there's currently only one known case where we've seen this distinction causing a problem (so far).
We can fix [arm_acle.h](https://github.com/llvm/llvm-project/blob/48c92dda0086d0ec2e8c1032ec53edec743c85f3/clang/lib/Headers/arm_acle.h#L44) and postpone addition of `__can_use_builtin` until it becomes a problem, again.
https://github.com/llvm/llvm-project/blob/48c92dda0086d0ec2e8c1032ec53edec743c85f3/clang/lib/Headers/arm_acle.h#L44-L48

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


More information about the cfe-commits mailing list