Skip to content

Commit 255eb17

Browse files
[Clang]Throw frontend error for target feature mismatch when using flatten attribute
Fixes #149866
1 parent bce9b6d commit 255eb17

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5261,9 +5261,11 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
52615261
// since otherwise we could be making a conditional call after a check for
52625262
// the proper cpu features (and it won't cause code generation issues due to
52635263
// function based code generation).
5264-
if (TargetDecl->hasAttr<AlwaysInlineAttr>() &&
5265-
(TargetDecl->hasAttr<TargetAttr>() ||
5266-
(CurFuncDecl && CurFuncDecl->hasAttr<TargetAttr>())))
5264+
if ((TargetDecl->hasAttr<AlwaysInlineAttr>() &&
5265+
(TargetDecl->hasAttr<TargetAttr>() ||
5266+
(CurFuncDecl && CurFuncDecl->hasAttr<TargetAttr>()))) ||
5267+
(CurFuncDecl && CurFuncDecl->hasAttr<FlattenAttr>() &&
5268+
TargetDecl->hasAttr<TargetAttr>()))
52675269
checkTargetFeatures(Loc, FD);
52685270
}
52695271

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__((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'}}
12+
}

0 commit comments

Comments
 (0)