]> granicus.if.org Git - clang/commitdiff
When producing error messages for always_inline functions with the
authorEric Christopher <echristo@gmail.com>
Mon, 16 Nov 2015 18:29:59 +0000 (18:29 +0000)
committerEric Christopher <echristo@gmail.com>
Mon, 16 Nov 2015 18:29:59 +0000 (18:29 +0000)
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

lib/CodeGen/CodeGenFunction.cpp
test/CodeGen/target-features-no-error.c [new file with mode: 0644]

index a425c3e229a5d5aa4612a3fe39cfc6fb9056b1c9..4c1d6af75307f1133d8b61b53d21829a08f96995 100644 (file)
@@ -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/test/CodeGen/target-features-no-error.c b/test/CodeGen/target-features-no-error.c
new file mode 100644 (file)
index 0000000..b6283b6
--- /dev/null
@@ -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
+}