This is an archive of the discontinued LLVM Phabricator instance.

[clang] Fix __has_builtin
ClosedPublic

Authored by yaxunl on May 17 2022, 12:18 PM.

Details

Summary

Fix __has_builtin to return 1 only if the requested target features
of a builtin are enabled by refactoring the code for checking
required target features of a builtin and use it in evaluation
of __has_builtin.

Diff Detail

Event Timeline

yaxunl created this revision.May 17 2022, 12:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 12:18 PM
yaxunl requested review of this revision.May 17 2022, 12:18 PM
tra added a subscriber: echristo.May 17 2022, 2:04 PM

@echristo - FYI, in case you have an opinion on target builtin feature checks.

clang/include/clang/Basic/Builtins.h
264

I think we should boil it down to just evaluateRequiredTargetFeatures(StringRef RequiredFeatures, ... TargetFeatureMap).

clang/lib/Basic/BuiltinTargetFeatures.h
33

I don't think it needs to be part of the public API. Feature check function operates on llvm::StringMap<bool> and does not need to know about this class, and the implementation of this class can be moved into Builtins.cpp where it's actually used.

yaxunl marked 2 inline comments as done.May 18 2022, 9:48 AM
yaxunl added inline comments.
clang/include/clang/Basic/Builtins.h
264

will do

clang/lib/Basic/BuiltinTargetFeatures.h
33

It is not a public API since it is under lib/Basic.

The reason it is made a header file because we have a unit test clang/unittests/CodeGen/CheckTargetFeaturesTest.cpp for class TargetFeatures. This is because TargetFeatures is relatively complicated.

yaxunl updated this revision to Diff 430420.May 18 2022, 9:49 AM
yaxunl marked 2 inline comments as done.

revised by Artem's comments

tra accepted this revision.May 18 2022, 10:39 AM

LGTM with a possible nit.

clang/lib/Basic/BuiltinTargetFeatures.h
33

Got it. I've missed the test.

clang/lib/CodeGen/CodeGenFunction.cpp
2552–2553

Should we move that into the evaluateRequiredTargetFeatures ?

Empty feature list -> true sounds like something that belongs to the evaluation logic. So does the assertion on the no-spaces assumption we make about the input.

This revision is now accepted and ready to land.May 18 2022, 10:39 AM
yaxunl marked an inline comment as done.May 18 2022, 10:43 AM
yaxunl added inline comments.
clang/lib/CodeGen/CodeGenFunction.cpp
2552–2553

will do when committing

This revision was landed with ongoing or failed builds.May 19 2022, 8:35 AM
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2022, 8:35 AM