From 9f8cbc24cb5bcc150c45cf229c37013c06aa3bb5 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Thu, 12 Nov 2015 00:44:04 +0000 Subject: [PATCH] In preparation to use it in more places rename checkBuiltinTargetFeatures to checkTargetFeatures and sink the error handling into the function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@252832 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGBuiltin.cpp | 22 +++++++++++----------- lib/CodeGen/CodeGenFunction.h | 4 +--- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index f82302bd74..9e5a075d52 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -344,24 +344,24 @@ Value *CodeGenFunction::EmitVAStartEnd(Value *ArgValue, bool IsStart) { } // Returns true if we have a valid set of target features. -bool CodeGenFunction::checkBuiltinTargetFeatures( - const FunctionDecl *TargetDecl) { +void CodeGenFunction::checkTargetFeatures(const CallExpr *E, + const FunctionDecl *TargetDecl) { // Early exit if this is an indirect call. if (!TargetDecl) - return true; + return; // Get the current enclosing function if it exists. If it doesn't // we can't check the target features anyhow. const FunctionDecl *FD = dyn_cast_or_null(CurFuncDecl); if (!FD) - return true; + return; unsigned BuiltinID = TargetDecl->getBuiltinID(); const char *FeatureList = CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID); if (!FeatureList || StringRef(FeatureList) == "") - return true; + return; llvm::StringMap FeatureMap; CGM.getFunctionFeatureMap(FeatureMap, FD); @@ -370,7 +370,7 @@ bool CodeGenFunction::checkBuiltinTargetFeatures( // true, otherwise return false. SmallVector AttrFeatures; StringRef(FeatureList).split(AttrFeatures, ","); - return std::all_of(AttrFeatures.begin(), AttrFeatures.end(), + if (!std::all_of(AttrFeatures.begin(), AttrFeatures.end(), [&](StringRef &Feature) { SmallVector OrFeatures; Feature.split(OrFeatures, "|"); @@ -378,7 +378,10 @@ bool CodeGenFunction::checkBuiltinTargetFeatures( [&](StringRef &Feature) { return FeatureMap[Feature]; }); - }); + })) + CGM.getDiags().Report(E->getLocStart(), diag::err_builtin_needs_feature) + << TargetDecl->getDeclName() + << CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID); } RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, @@ -1969,10 +1972,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, // This is down here to avoid non-target specific builtins, however, if // generic builtins start to require generic target features then we // can move this up to the beginning of the function. - if (!checkBuiltinTargetFeatures(FD)) - CGM.getDiags().Report(E->getLocStart(), diag::err_builtin_needs_feature) - << FD->getDeclName() - << CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID); + checkTargetFeatures(E, FD); // See if we have a target specific intrinsic. const char *Name = getContext().BuiltinInfo.getName(BuiltinID); diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 1aab00e10d..d0f37e6fa4 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -2638,9 +2638,7 @@ public: RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue = ReturnValueSlot()); - void getFunctionFeatureMap(llvm::StringMap &FeatureMap, - const FunctionDecl *FD); - bool checkBuiltinTargetFeatures(const FunctionDecl *TargetDecl); + void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl); llvm::CallInst *EmitRuntimeCall(llvm::Value *callee, const Twine &name = ""); -- 2.40.0