[PATCH] D43821: [SemaCXX] _Pragma("clang optimize off") not affecting lambda.

Carlos Alberto Enciso via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 26 06:51:10 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL328494: [SemaCXX] _Pragma("clang optimize off") not affecting lambda. (authored by CarlosAlbertoEnciso, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D43821?vs=137550&id=139783#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43821

Files:
  cfe/trunk/lib/Sema/SemaLambda.cpp
  cfe/trunk/test/CodeGenCXX/optnone-pragma-optimize-off.cpp


Index: cfe/trunk/test/CodeGenCXX/optnone-pragma-optimize-off.cpp
===================================================================
--- cfe/trunk/test/CodeGenCXX/optnone-pragma-optimize-off.cpp
+++ cfe/trunk/test/CodeGenCXX/optnone-pragma-optimize-off.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 %s -triple %itanium_abi_triple -O1 -disable-llvm-passes -emit-llvm -o - | FileCheck %s
+
+// Test the attributes for the lambda function contains 'optnone' as result of
+// the _Pragma("clang optimize off").
+
+_Pragma("clang optimize off")
+
+void foo(int p) {
+  auto lambda = [&p]() { ++p; };
+  lambda();
+  // CHECK: define {{.*}} @"_ZZ3fooiENK3$_0clEv"({{.*}}) #[[LAMBDA_ATR:[0-9]+]]
+}
+
+_Pragma("clang optimize on")
+
+// CHECK: attributes #[[LAMBDA_ATR]] = { {{.*}} optnone {{.*}} }
\ No newline at end of file
Index: cfe/trunk/lib/Sema/SemaLambda.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp
+++ cfe/trunk/lib/Sema/SemaLambda.cpp
@@ -904,6 +904,10 @@
                             ParamInfo.getDeclSpec().isConstexprSpecified());
   if (ExplicitParams)
     CheckCXXDefaultArguments(Method);
+
+  // This represents the function body for the lambda function, check if we
+  // have to apply optnone due to a pragma.
+  AddRangeBasedOptnone(Method);
   
   // Attributes on the lambda apply to the method.  
   ProcessDeclAttributes(CurScope, Method, ParamInfo);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43821.139783.patch
Type: text/x-patch
Size: 1431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180326/952cde54/attachment.bin>


More information about the cfe-commits mailing list