Fix always_inline 'target' compatibility check code for Lambdas

The previous version of this used CurFuncDecl in CodeGenFunction,
however this doesn't include lambdas.  However, CurCodeDecl DOES. Switch
the check to use CurCodeDecl so that the actual function being emitted
gets checked, preventing an error in ISEL.

llvm-svn: 370261
This commit is contained in:
Erich Keane 2019-08-28 20:59:25 +00:00
parent a1178b862a
commit 856f3fe5bb
2 changed files with 46 additions and 2 deletions

View File

@ -2203,7 +2203,7 @@ void CodeGenFunction::checkTargetFeatures(SourceLocation Loc,
// Get the current enclosing function if it exists. If it doesn't
// we can't check the target features anyhow.
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl);
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurCodeDecl);
if (!FD)
return;

View File

@ -1,4 +1,6 @@
// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o -
// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -DTEST1
// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -DTEST2
// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -DTEST3
struct S {
__attribute__((always_inline, target("avx512f")))
@ -9,9 +11,51 @@ struct S {
void operator()(){ }
};
__attribute__((always_inline, target("avx512f")))
void free_func(){}
#ifdef TEST1
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'}}
free_func(); // expected-error{{'free_func' requires target feature 'avx512f'}}
}
#endif
#ifdef TEST2
__attribute__((target("avx512f")))
void usage(S & s) {
s.foo();
(void)(int)s;
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'}}
free_func(); // expected-error{{'free_func' requires target feature 'avx512f'}}
}();
}
#endif
#ifdef TEST3
void usage(S & s) {
[&s] () __attribute__((target("avx512f"))) {
s.foo();
(void)(int) s;
s();
free_func();
}();
[&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'}}
free_func(); // expected-error{{'free_func' requires target feature 'avx512f'}}
}();
}
#endif