r253121 - Add support for the always_inline + target feature diagnostic to print
Eric Christopher via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 13 18:38:38 PST 2015
Author: echristo
Date: Fri Nov 13 20:38:37 2015
New Revision: 253121
URL: http://llvm.org/viewvc/llvm-project?rev=253121&view=rev
Log:
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.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/test/CodeGen/target-features-error-2.c
cfe/trunk/test/CodeGen/target-features-error.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=253121&r1=253120&r2=253121&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Nov 13 20:38:37 2015
@@ -432,8 +432,9 @@ def err_arm_invalid_specialreg : Error<"
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<
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=253121&r1=253120&r2=253121&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Nov 13 20:38:37 2015
@@ -1852,7 +1852,8 @@ template void CGBuilderInserter<Preserve
#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 Sm
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::checkTargetFeature
// 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::checkTargetFeature
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::checkTargetFeature
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;
}
}
Modified: cfe/trunk/test/CodeGen/target-features-error-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/target-features-error-2.c?rev=253121&r1=253120&r2=253121&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/target-features-error-2.c (original)
+++ cfe/trunk/test/CodeGen/target-features-error-2.c Fri Nov 13 20:38:37 2015
@@ -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'}}
}
Modified: cfe/trunk/test/CodeGen/target-features-error.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/target-features-error.c?rev=253121&r1=253120&r2=253121&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/target-features-error.c (original)
+++ cfe/trunk/test/CodeGen/target-features-error.c Fri Nov 13 20:38:37 2015
@@ -3,6 +3,6 @@ int __attribute__((target("avx"), always
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'}}
}
More information about the cfe-commits
mailing list