[cfe-dev] '__has_builtin' and '-mcpu'

Renato Golin via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 28 06:54:21 PDT 2016


On 28 July 2016 at 14:24, Martin J. O'Riordan via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> But I was thinking that it might be useful for the programmer to test for
> the existence of the builtin using ‘__has_builtin’, but while this returns
> true when give the name of any of our builtins, it does so regardless of
> which CPU variant was selected.

Hi Martin,

A similar problem was reported by Android:

https://llvm.org/bugs/show_bug.cgi?id=28629

and it seems my interpretation of "has_builtin" was wrong, and yours
is right (so was Stephen's).

I'll update that bug to reflect this, but this opens a larger Clang
question as to what does it mean to "have a builtin".

In that example, __has_builtin returns true, but it's implemented as a
library call and only implemented in Compiler-RT, which is an odd
combination. That is why I assumed that it meant that Clang "knew
about it and how to lower" instead of "knew how to custom lower
without library calls".

Given that this is a CPU specific (at least TargetFeature-specific)
feature, getting the target's description is sine qua non to get this
working, which means call backs into LLVM. But once you got the
Subtarget object, "has<FeatureX>" is a simple call. :)

cheers,
--renato



More information about the cfe-dev mailing list