From dc9200c2fe44e16d04d44f3a3012a8c921daade4 Mon Sep 17 00:00:00 2001 From: Carlos Alberto Enciso Date: Mon, 26 Mar 2018 13:48:03 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@328494 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaLambda.cpp | 4 ++++ test/CodeGenCXX/optnone-pragma-optimize-off.cpp | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/CodeGenCXX/optnone-pragma-optimize-off.cpp diff --git a/lib/Sema/SemaLambda.cpp b/lib/Sema/SemaLambda.cpp index db8dd1793c..1b9702f79a 100644 --- a/lib/Sema/SemaLambda.cpp +++ b/lib/Sema/SemaLambda.cpp @@ -904,6 +904,10 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, 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); diff --git a/test/CodeGenCXX/optnone-pragma-optimize-off.cpp b/test/CodeGenCXX/optnone-pragma-optimize-off.cpp new file mode 100644 index 0000000000..d750c4c284 --- /dev/null +++ b/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 -- 2.40.0