r364109 - Ensure Target Features always_inline error happens in C++ cases.
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 21 15:29:32 PDT 2019
Author: erichkeane
Date: Fri Jun 21 15:29:32 2019
New Revision: 364109
URL: http://llvm.org/viewvc/llvm-project?rev=364109&view=rev
Log:
Ensure Target Features always_inline error happens in C++ cases.
A handful of C++ cases as reported in PR42352 didn't actually give an
error when always_inlining with a different target feature list. This
resulted in broken IR.
Added:
cfe/trunk/test/CodeGenCXX/target-builtin-error.o (with props)
cfe/trunk/test/CodeGenCXX/target-features-error.cpp (with props)
Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=364109&r1=364108&r2=364109&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Jun 21 15:29:32 2019
@@ -3791,6 +3791,16 @@ RValue CodeGenFunction::EmitCall(const C
llvm::FunctionType *IRFuncTy = getTypes().GetFunctionType(CallInfo);
const Decl *TargetDecl = Callee.getAbstractInfo().getCalleeDecl().getDecl();
+ if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl))
+ // We can only guarantee that a function is called from the correct
+ // context/function based on the appropriate target attributes,
+ // so only check in the case where we have both always_inline and target
+ // since otherwise we could be making a conditional call after a check for
+ // the proper cpu features (and it won't cause code generation issues due to
+ // function based code generation).
+ if (TargetDecl->hasAttr<AlwaysInlineAttr>() &&
+ TargetDecl->hasAttr<TargetAttr>())
+ checkTargetFeatures(Loc, FD);
#ifndef NDEBUG
if (!(CallInfo.isVariadic() && CallInfo.getArgStruct())) {
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=364109&r1=364108&r2=364109&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Jun 21 15:29:32 2019
@@ -4697,17 +4697,6 @@ RValue CodeGenFunction::EmitCall(QualTyp
const Decl *TargetDecl =
OrigCallee.getAbstractInfo().getCalleeDecl().getDecl();
- if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(TargetDecl))
- // We can only guarantee that a function is called from the correct
- // context/function based on the appropriate target attributes,
- // so only check in the case where we have both always_inline and target
- // since otherwise we could be making a conditional call after a check for
- // the proper cpu features (and it won't cause code generation issues due to
- // function based code generation).
- if (TargetDecl->hasAttr<AlwaysInlineAttr>() &&
- TargetDecl->hasAttr<TargetAttr>())
- checkTargetFeatures(E, FD);
-
CalleeType = getContext().getCanonicalType(CalleeType);
auto PointeeType = cast<PointerType>(CalleeType)->getPointeeType();
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=364109&r1=364108&r2=364109&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Fri Jun 21 15:29:32 2019
@@ -2179,6 +2179,13 @@ static bool hasRequiredFeatures(const Sm
// called function.
void CodeGenFunction::checkTargetFeatures(const CallExpr *E,
const FunctionDecl *TargetDecl) {
+ return checkTargetFeatures(E->getBeginLoc(), TargetDecl);
+}
+
+// Emits an error if we don't have a valid set of target features for the
+// called function.
+void CodeGenFunction::checkTargetFeatures(SourceLocation Loc,
+ const FunctionDecl *TargetDecl) {
// Early exit if this is an indirect call.
if (!TargetDecl)
return;
@@ -2203,7 +2210,7 @@ void CodeGenFunction::checkTargetFeature
return;
StringRef(FeatureList).split(ReqFeatures, ',');
if (!hasRequiredFeatures(ReqFeatures, CGM, FD, MissingFeature))
- CGM.getDiags().Report(E->getBeginLoc(), diag::err_builtin_needs_feature)
+ CGM.getDiags().Report(Loc, diag::err_builtin_needs_feature)
<< TargetDecl->getDeclName()
<< CGM.getContext().BuiltinInfo.getRequiredFeatures(BuiltinID);
@@ -2229,7 +2236,7 @@ void CodeGenFunction::checkTargetFeature
ReqFeatures.push_back(F.getKey());
}
if (!hasRequiredFeatures(ReqFeatures, CGM, FD, MissingFeature))
- CGM.getDiags().Report(E->getBeginLoc(), diag::err_function_needs_feature)
+ CGM.getDiags().Report(Loc, diag::err_function_needs_feature)
<< FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature;
}
}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=364109&r1=364108&r2=364109&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Jun 21 15:29:32 2019
@@ -3605,6 +3605,7 @@ public:
CGCallee EmitCallee(const Expr *E);
void checkTargetFeatures(const CallExpr *E, const FunctionDecl *TargetDecl);
+ void checkTargetFeatures(SourceLocation Loc, const FunctionDecl *TargetDecl);
llvm::CallInst *EmitRuntimeCall(llvm::FunctionCallee callee,
const Twine &name = "");
Added: cfe/trunk/test/CodeGenCXX/target-builtin-error.o
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/target-builtin-error.o?rev=364109&view=auto
==============================================================================
Binary file - no diff available.
Propchange: cfe/trunk/test/CodeGenCXX/target-builtin-error.o
------------------------------------------------------------------------------
svn:mime-type = application/x-object
Added: cfe/trunk/test/CodeGenCXX/target-features-error.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/target-features-error.cpp?rev=364109&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/target-features-error.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/target-features-error.cpp Fri Jun 21 15:29:32 2019
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o -
+
+struct S {
+ __attribute__((always_inline, target("avx512f")))
+ void foo(){}
+ __attribute__((always_inline, target("avx512f")))
+ operator int(){ return 0; }
+ __attribute__((always_inline, target("avx512f")))
+ void operator()(){ }
+
+};
+
+void usage(S & s) {
+ s.foo(); // expected-error {{'foo' requires target feature 'avx512f'}}
+ (void)(int)s; // expected-error {{'operator int' requires target feature 'avx512f'}}
+ s(); // expected-error {{'operator()' requires target feature 'avx512f'}}
+}
Propchange: cfe/trunk/test/CodeGenCXX/target-features-error.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/CodeGenCXX/target-features-error.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Rev URL
Propchange: cfe/trunk/test/CodeGenCXX/target-features-error.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list