r328494 - [SemaCXX] _Pragma("clang optimize off") not affecting lambda.

via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 26 06:48:03 PDT 2018


Author: CarlosAlbertoEnciso
Date: Mon Mar 26 06:48:03 2018
New Revision: 328494

URL: http://llvm.org/viewvc/llvm-project?rev=328494&view=rev
Log:
[SemaCXX] _Pragma("clang optimize off") not affecting lambda.

Declaring "_Pragma("clang optimize off")" before the body of a
function with a lambda leads to the lambda functions in the body
not being affected.

Differential Revision: https://reviews.llvm.org/D43821

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

Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=328494&r1=328493&r2=328494&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Mon Mar 26 06:48:03 2018
@@ -904,6 +904,10 @@ void Sema::ActOnStartOfLambdaDefinition(
                             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);

Added: cfe/trunk/test/CodeGenCXX/optnone-pragma-optimize-off.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/optnone-pragma-optimize-off.cpp?rev=328494&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/optnone-pragma-optimize-off.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/optnone-pragma-optimize-off.cpp Mon Mar 26 06:48:03 2018
@@ -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




More information about the cfe-commits mailing list