Skip to content

Commit 9638206

Browse files
Add new diagnostic error for flatten
1 parent 255eb17 commit 9638206

File tree

6 files changed

+62
-16
lines changed

6 files changed

+62
-16
lines changed

clang/include/clang/Basic/DiagnosticFrontendKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ def err_function_needs_feature : Error<
287287
"always_inline function %1 requires target feature '%2', but would "
288288
"be inlined into function %0 that is compiled without support for '%2'">;
289289

290+
def err_flatten_function_needs_feature
291+
: Error<"flatten function %0 calls %1 which requires target feature '%2', "
292+
"but the caller is compiled without support for '%2'">;
293+
290294
let CategoryName = "Codegen ABI Check" in {
291295
def err_function_always_inline_attribute_mismatch : Error<
292296
"always_inline function %1 and its caller %0 have mismatching %2 attributes">;

clang/lib/CodeGen/CGCall.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5265,7 +5265,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
52655265
(TargetDecl->hasAttr<TargetAttr>() ||
52665266
(CurFuncDecl && CurFuncDecl->hasAttr<TargetAttr>()))) ||
52675267
(CurFuncDecl && CurFuncDecl->hasAttr<FlattenAttr>() &&
5268-
TargetDecl->hasAttr<TargetAttr>()))
5268+
(CurFuncDecl->hasAttr<TargetAttr>() ||
5269+
TargetDecl->hasAttr<TargetAttr>())))
52695270
checkTargetFeatures(Loc, FD);
52705271
}
52715272

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,9 @@ void CodeGenFunction::checkTargetFeatures(SourceLocation Loc,
28272827
if (!FD)
28282828
return;
28292829

2830+
bool IsAlwaysInline = TargetDecl->hasAttr<AlwaysInlineAttr>();
2831+
bool IsFlatten = FD && FD->hasAttr<FlattenAttr>();
2832+
28302833
// Grab the required features for the call. For a builtin this is listed in
28312834
// the td file with the default cpu, for an always_inline function this is any
28322835
// listed cpu and any listed features.
@@ -2869,25 +2872,39 @@ void CodeGenFunction::checkTargetFeatures(SourceLocation Loc,
28692872
if (F.getValue())
28702873
ReqFeatures.push_back(F.getKey());
28712874
}
2872-
if (!llvm::all_of(ReqFeatures, [&](StringRef Feature) {
2873-
if (!CallerFeatureMap.lookup(Feature)) {
2874-
MissingFeature = Feature.str();
2875-
return false;
2876-
}
2877-
return true;
2878-
}) && !IsHipStdPar)
2879-
CGM.getDiags().Report(Loc, diag::err_function_needs_feature)
2880-
<< FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature;
2875+
if (!llvm::all_of(ReqFeatures,
2876+
[&](StringRef Feature) {
2877+
if (!CallerFeatureMap.lookup(Feature)) {
2878+
MissingFeature = Feature.str();
2879+
return false;
2880+
}
2881+
return true;
2882+
}) &&
2883+
!IsHipStdPar) {
2884+
if (IsAlwaysInline)
2885+
CGM.getDiags().Report(Loc, diag::err_function_needs_feature)
2886+
<< FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature;
2887+
else if (IsFlatten)
2888+
CGM.getDiags().Report(Loc, diag::err_flatten_function_needs_feature)
2889+
<< FD->getDeclName() << TargetDecl->getDeclName() << MissingFeature;
2890+
}
2891+
28812892
} else if (!FD->isMultiVersion() && FD->hasAttr<TargetAttr>()) {
28822893
llvm::StringMap<bool> CalleeFeatureMap;
28832894
CGM.getContext().getFunctionFeatureMap(CalleeFeatureMap, TargetDecl);
28842895

28852896
for (const auto &F : CalleeFeatureMap) {
2886-
if (F.getValue() && (!CallerFeatureMap.lookup(F.getKey()) ||
2887-
!CallerFeatureMap.find(F.getKey())->getValue()) &&
2888-
!IsHipStdPar)
2889-
CGM.getDiags().Report(Loc, diag::err_function_needs_feature)
2890-
<< FD->getDeclName() << TargetDecl->getDeclName() << F.getKey();
2897+
if (F.getValue() &&
2898+
(!CallerFeatureMap.lookup(F.getKey()) ||
2899+
!CallerFeatureMap.find(F.getKey())->getValue()) &&
2900+
!IsHipStdPar) {
2901+
if (IsAlwaysInline)
2902+
CGM.getDiags().Report(Loc, diag::err_function_needs_feature)
2903+
<< FD->getDeclName() << TargetDecl->getDeclName() << F.getKey();
2904+
else if (IsFlatten)
2905+
CGM.getDiags().Report(Loc, diag::err_flatten_function_needs_feature)
2906+
<< FD->getDeclName() << TargetDecl->getDeclName() << F.getKey();
2907+
}
28912908
}
28922909
}
28932910
}

clang/test/CodeGen/target-features-error-3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ __v2df __attribute__((target("sse4.1"))) foo() {
88
}
99

1010
__v2df __attribute__((flatten)) bar() {
11-
return foo(); // expected-error {{always_inline function 'foo' requires target feature 'sse4.1', but would be inlined into function 'bar' that is compiled without support for 'sse4.1'}}
11+
return foo(); // expected-error {{flatten function 'bar' calls 'foo' which requires target feature 'sse4.1', but the caller is compiled without support for 'sse4.1'}}
1212
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o -
2+
3+
typedef double __v2df __attribute__((__vector_size__(16)));
4+
5+
__v2df __attribute__((target("sse4.1"))) foo() {
6+
__v2df v = {0.0, 0.0};
7+
return __builtin_ia32_roundpd(v, 2);
8+
}
9+
10+
__v2df __attribute__((target("no-sse4.1"), flatten)) bar() {
11+
return foo(); // expected-error {{flatten function 'bar' calls 'foo' which requires target feature 'sse4.1', but the caller is compiled without support for 'sse4.1'}}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +sse4.1 -S -verify -o -
2+
3+
typedef double __v2df __attribute__((__vector_size__(16)));
4+
5+
__v2df foo() {
6+
__v2df v = {0.0, 0.0};
7+
return __builtin_ia32_roundpd(v, 2);
8+
}
9+
10+
__v2df __attribute__((target("no-sse4.1"), flatten)) bar() {
11+
return foo(); // expected-error {{flatten function 'bar' calls 'foo' which requires target feature 'sse4.1', but the caller is compiled without support for 'sse4.1'}}
12+
}

0 commit comments

Comments
 (0)