diff options
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 7 | ||||
| -rw-r--r-- | clang/test/CodeGen/target-features-no-error.c | 9 |
2 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index a425c3e229a..4c1d6af7530 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1917,8 +1917,11 @@ void CodeGenFunction::checkTargetFeatures(const CallExpr *E, SmallVector<StringRef, 1> ReqFeatures; llvm::StringMap<bool> 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/clang/test/CodeGen/target-features-no-error.c b/clang/test/CodeGen/target-features-no-error.c new file mode 100644 index 00000000000..b6283b65ec5 --- /dev/null +++ b/clang/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 +} |

