From: Eric Christopher Date: Mon, 16 Nov 2015 18:29:59 +0000 (+0000) Subject: When producing error messages for always_inline functions with the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9222288accd7d0b02a371acb1ea68d29463dab1;p=clang When producing error messages for always_inline functions with the target attribute, don't include "negative" subtarget features in the list of required features. Builtins are positive by default so don't need this change, but we pull the default list of features from the command line and so need to make sure that we only include features that are turned on for code generation in our error. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253242 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index a425c3e229..4c1d6af753 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -1917,8 +1917,11 @@ void CodeGenFunction::checkTargetFeatures(const CallExpr *E, SmallVector ReqFeatures; llvm::StringMap CalleeFeatureMap; CGM.getFunctionFeatureMap(CalleeFeatureMap, TargetDecl); - for (const auto &F : CalleeFeatureMap) - ReqFeatures.push_back(F.getKey()); + for (const auto &F : CalleeFeatureMap) { + // Only positive features are "required". + if (F.getValue()) + ReqFeatures.push_back(F.getKey()); + } if (!hasRequiredFeatures(ReqFeatures, CGM, FD, MissingFeature)) CGM.getDiags().Report(E->getLocStart(), diag::err_function_needs_feature) << FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature; diff --git a/test/CodeGen/target-features-no-error.c b/test/CodeGen/target-features-no-error.c new file mode 100644 index 0000000000..b6283b65ec --- /dev/null +++ b/test/CodeGen/target-features-no-error.c @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -emit-llvm -o - -target-feature -sse2 + +// Verify that negative features don't cause additional requirements on the inline function. +int __attribute__((target("sse"), always_inline)) foo(int a) { + return a + 4; +} +int bar() { + return foo(4); // expected-no-diagnostics +}