[clang] f9eaa69 - Ensure aux-target specific builtins get validated.
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Thu May 7 13:23:16 PDT 2020
Author: Erich Keane
Date: 2020-05-07T13:22:10-07:00
New Revision: f9eaa6934e4fdd92e09ddff89b6805a8b583e53e
URL: https://github.com/llvm/llvm-project/commit/f9eaa6934e4fdd92e09ddff89b6805a8b583e53e
DIFF: https://github.com/llvm/llvm-project/commit/f9eaa6934e4fdd92e09ddff89b6805a8b583e53e.diff
LOG: Ensure aux-target specific builtins get validated.
I discovered that when using an aux-target builtin, it was recognized as
a builtin but never checked. This patch checks for an aux-target builtin
and instead validates it against the correct target.
It does this by extracting the checking code for Target-specific
builtins into its own function, then calls with either targetInfo or
AuxTargetInfo.
Added:
clang/test/Sema/check-aux-builtins.c
Modified:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4d6e94df0b4d..66294c34a608 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -12003,6 +12003,10 @@ class Sema final {
ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl,
unsigned BuiltinID, CallExpr *TheCall);
+
+ bool CheckTSBuiltinFunctionCall(llvm::Triple::ArchType Arch,
+ unsigned BuiltinID, CallExpr *TheCall);
+
void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall);
bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall,
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 478a534ab71c..b4cb76d0b1ad 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1379,6 +1379,46 @@ CheckBuiltinTargetSupport(Sema &S, unsigned BuiltinID, CallExpr *TheCall,
static void CheckNonNullArgument(Sema &S, const Expr *ArgExpr,
SourceLocation CallSiteLoc);
+bool Sema::CheckTSBuiltinFunctionCall(llvm::Triple::ArchType Arch,
+ unsigned BuiltinID, CallExpr *TheCall) {
+ switch (Arch) {
+ default:
+ // Some builtins don't require additional checking, so just consider these
+ // acceptable.
+ return false;
+ case llvm::Triple::arm:
+ case llvm::Triple::armeb:
+ case llvm::Triple::thumb:
+ case llvm::Triple::thumbeb:
+ return CheckARMBuiltinFunctionCall(BuiltinID, TheCall);
+ case llvm::Triple::aarch64:
+ case llvm::Triple::aarch64_32:
+ case llvm::Triple::aarch64_be:
+ return CheckAArch64BuiltinFunctionCall(BuiltinID, TheCall);
+ case llvm::Triple::bpfeb:
+ case llvm::Triple::bpfel:
+ return CheckBPFBuiltinFunctionCall(BuiltinID, TheCall);
+ case llvm::Triple::hexagon:
+ return CheckHexagonBuiltinFunctionCall(BuiltinID, TheCall);
+ case llvm::Triple::mips:
+ case llvm::Triple::mipsel:
+ case llvm::Triple::mips64:
+ case llvm::Triple::mips64el:
+ return CheckMipsBuiltinFunctionCall(BuiltinID, TheCall);
+ case llvm::Triple::systemz:
+ return CheckSystemZBuiltinFunctionCall(BuiltinID, TheCall);
+ case llvm::Triple::x86:
+ case llvm::Triple::x86_64:
+ return CheckX86BuiltinFunctionCall(BuiltinID, TheCall);
+ case llvm::Triple::ppc:
+ case llvm::Triple::ppc64:
+ case llvm::Triple::ppc64le:
+ return CheckPPCBuiltinFunctionCall(BuiltinID, TheCall);
+ case llvm::Triple::amdgcn:
+ return CheckAMDGCNBuiltinFunctionCall(BuiltinID, TheCall);
+ }
+}
+
ExprResult
Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
CallExpr *TheCall) {
@@ -1875,57 +1915,19 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
// Since the target specific builtins for each arch overlap, only check those
// of the arch we are compiling for.
if (Context.BuiltinInfo.isTSBuiltin(BuiltinID)) {
- switch (Context.getTargetInfo().getTriple().getArch()) {
- case llvm::Triple::arm:
- case llvm::Triple::armeb:
- case llvm::Triple::thumb:
- case llvm::Triple::thumbeb:
- if (CheckARMBuiltinFunctionCall(BuiltinID, TheCall))
- return ExprError();
- break;
- case llvm::Triple::aarch64:
- case llvm::Triple::aarch64_32:
- case llvm::Triple::aarch64_be:
- if (CheckAArch64BuiltinFunctionCall(BuiltinID, TheCall))
- return ExprError();
- break;
- case llvm::Triple::bpfeb:
- case llvm::Triple::bpfel:
- if (CheckBPFBuiltinFunctionCall(BuiltinID, TheCall))
- return ExprError();
- break;
- case llvm::Triple::hexagon:
- if (CheckHexagonBuiltinFunctionCall(BuiltinID, TheCall))
- return ExprError();
- break;
- case llvm::Triple::mips:
- case llvm::Triple::mipsel:
- case llvm::Triple::mips64:
- case llvm::Triple::mips64el:
- if (CheckMipsBuiltinFunctionCall(BuiltinID, TheCall))
- return ExprError();
- break;
- case llvm::Triple::systemz:
- if (CheckSystemZBuiltinFunctionCall(BuiltinID, TheCall))
- return ExprError();
- break;
- case llvm::Triple::x86:
- case llvm::Triple::x86_64:
- if (CheckX86BuiltinFunctionCall(BuiltinID, TheCall))
- return ExprError();
- break;
- case llvm::Triple::ppc:
- case llvm::Triple::ppc64:
- case llvm::Triple::ppc64le:
- if (CheckPPCBuiltinFunctionCall(BuiltinID, TheCall))
- return ExprError();
- break;
- case llvm::Triple::amdgcn:
- if (CheckAMDGCNBuiltinFunctionCall(BuiltinID, TheCall))
- return ExprError();
- break;
- default:
- break;
+ if (Context.BuiltinInfo.isAuxBuiltinID(BuiltinID)) {
+ assert(Context.getAuxTargetInfo() &&
+ "Aux Target Builtin, but not an aux target?");
+
+ if (CheckTSBuiltinFunctionCall(
+ Context.getAuxTargetInfo()->getTriple().getArch(),
+ Context.BuiltinInfo.getAuxBuiltinID(BuiltinID), TheCall))
+ return ExprError();
+ } else {
+ if (CheckTSBuiltinFunctionCall(
+ Context.getTargetInfo().getTriple().getArch(), BuiltinID,
+ TheCall))
+ return ExprError();
}
}
diff --git a/clang/test/Sema/check-aux-builtins.c b/clang/test/Sema/check-aux-builtins.c
new file mode 100644
index 000000000000..a9a836cdcbb7
--- /dev/null
+++ b/clang/test/Sema/check-aux-builtins.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fopenmp -fopenmp-is-device -triple aarch64 -aux-triple x86_64-linux-pc -fsyntax-only -verify %s
+
+void func(void) {
+ __builtin_cpu_is("INVALID"); // expected-error{{invalid cpu name for builtin}}
+}
More information about the cfe-commits
mailing list