From ce836776664802fa636a579012e4addb02f996af Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Sat, 14 Nov 2015 02:38:37 +0000 Subject: Add support for the always_inline + target feature diagnostic to print out the first missing target feature that's required and reword the diagnostic accordingly. llvm-svn: 253121 --- clang/lib/CodeGen/CodeGenFunction.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index b5812c8d314..a425c3e229a 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1852,7 +1852,8 @@ template void CGBuilderInserter::InsertHelper( #undef PreserveNames static bool hasRequiredFeatures(const SmallVectorImpl &ReqFeatures, - CodeGenModule &CGM, const FunctionDecl *FD) { + CodeGenModule &CGM, const FunctionDecl *FD, + std::string &FirstMissing) { // If there aren't any required features listed then go ahead and return. if (ReqFeatures.empty()) return false; @@ -1870,7 +1871,11 @@ static bool hasRequiredFeatures(const SmallVectorImpl &ReqFeatures, Feature.split(OrFeatures, "|"); return std::any_of(OrFeatures.begin(), OrFeatures.end(), [&](StringRef Feature) { - return CallerFeatureMap.lookup(Feature); + if (!CallerFeatureMap.lookup(Feature)) { + FirstMissing = Feature.str(); + return false; + } + return true; }); }); } @@ -1893,6 +1898,7 @@ void CodeGenFunction::checkTargetFeatures(const CallExpr *E, // the td file with the default cpu, for an always_inline function this is any // listed cpu and any listed features. unsigned BuiltinID = TargetDecl->getBuiltinID(); + std::string MissingFeature; if (BuiltinID) { SmallVector ReqFeatures; const char *FeatureList = @@ -1901,8 +1907,7 @@ void CodeGenFunction::checkTargetFeatures(const CallExpr *E, if (!FeatureList || StringRef(FeatureList) == "") return; StringRef(FeatureList).split(ReqFeatures, ","); - - if (!hasRequiredFeatures(ReqFeatures, CGM, FD)) + if (!hasRequiredFeatures(ReqFeatures, CGM, FD, MissingFeature)) CGM.getDiags().Report(E->getLocStart(), diag::err_builtin_needs_feature) << TargetDecl->getDeclName() << CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID); @@ -1914,8 +1919,8 @@ void CodeGenFunction::checkTargetFeatures(const CallExpr *E, CGM.getFunctionFeatureMap(CalleeFeatureMap, TargetDecl); for (const auto &F : CalleeFeatureMap) ReqFeatures.push_back(F.getKey()); - if (!hasRequiredFeatures(ReqFeatures, CGM, FD)) + if (!hasRequiredFeatures(ReqFeatures, CGM, FD, MissingFeature)) CGM.getDiags().Report(E->getLocStart(), diag::err_function_needs_feature) - << FD->getDeclName() << TargetDecl->getDeclName(); + << FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature; } } -- cgit v1.2.3