]> granicus.if.org Git - clang/commitdiff
Add support for the always_inline + target feature diagnostic to print
authorEric Christopher <echristo@gmail.com>
Sat, 14 Nov 2015 02:38:37 +0000 (02:38 +0000)
committerEric Christopher <echristo@gmail.com>
Sat, 14 Nov 2015 02:38:37 +0000 (02:38 +0000)
out the first missing target feature that's required and reword
the diagnostic accordingly.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253121 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/CodeGen/CodeGenFunction.cpp
test/CodeGen/target-features-error-2.c
test/CodeGen/target-features-error.c

index 76730e6fc7a3234ec73552cdb09eb659e29ffcf7..c3b501a8b53cffce5d462358213792efadc74ea2 100644 (file)
@@ -432,8 +432,9 @@ def err_arm_invalid_specialreg : Error<"invalid special register for builtin">;
 def err_invalid_cpu_supports : Error<"invalid cpu feature string for builtin">;
 def err_builtin_needs_feature : Error<"%0 needs target feature %1">;
 def err_function_needs_feature
-    : Error<"function %0 and always_inline callee function %1 are required to "
-            "have matching target features">;
+    : Error<"always_inline function %1 requires target feature '%2', but would "
+            "be inlined into function %0 that is compiled without support for "
+            "'%2'">;
 def warn_builtin_unknown : Warning<"use of unknown builtin %0">,
   InGroup<ImplicitFunctionDeclare>, DefaultError;
 def warn_dyn_class_memaccess : Warning<
index b5812c8d314279f24092eb79ebf7a452657ad8c1..a425c3e229a5d5aa4612a3fe39cfc6fb9056b1c9 100644 (file)
@@ -1852,7 +1852,8 @@ template void CGBuilderInserter<PreserveNames>::InsertHelper(
 #undef PreserveNames
 
 static bool hasRequiredFeatures(const SmallVectorImpl<StringRef> &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<StringRef> &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<StringRef, 1> 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;
   }
 }
index 66b8a46a4dff043c1c264368dc8524cbd7908da5..c23d152dcfb3c2fddfc309335883fe66d24e41e4 100644 (file)
@@ -3,5 +3,5 @@
 #include <x86intrin.h>
 
 int baz(__m256i a) {
-  return _mm256_extract_epi32(a, 3); // expected-error {{function 'baz' and always_inline callee function '_mm256_extract_epi32' are required to have matching target features}}
+  return _mm256_extract_epi32(a, 3); // expected-error {{always_inline function '_mm256_extract_epi32' requires target feature 'sse4.2', but would be inlined into function 'baz' that is compiled without support for 'sse4.2'}}
 }
index c7abbd0043397224d35e034d1c5ab6a3c3e14935..518f6e6189ed0de55de99f29cac319e62de6fbc1 100644 (file)
@@ -3,6 +3,6 @@ int __attribute__((target("avx"), always_inline)) foo(int a) {
   return a + 4;
 }
 int bar() {
-  return foo(4); // expected-error {{function 'bar' and always_inline callee function 'foo' are required to have matching target features}}
+  return foo(4); // expected-error {{always_inline function 'foo' requires target feature 'sse4.2', but would be inlined into function 'bar' that is compiled without support for 'sse4.2'}}
 }