Author: erichkeane
Date: Wed Aug 28 13:59:25 2019
New Revision: 370261

URL: http://llvm.org/viewvc/llvm-project?rev=370261&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/test/CodeGenCXX/target-features-error.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=370261&r1=370260&r2=370261&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Wed Aug 28 13:59:25 2019
@@ -2203,7 +2203,7 @@ void CodeGenFunction::checkTargetFeature
 
   // 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;
 

Modified: cfe/trunk/test/CodeGenCXX/target-features-error.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/target-features-error.cpp?rev=370261&r1=370260&r2=370261&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/target-features-error.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/target-features-error.cpp Wed Aug 28 13:59:25 2019
@@ -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


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to