https://github.com/ketjandr updated https://github.com/llvm/llvm-project/pull/217194
>From 9c30c54a8f193c74c848e1934fd1ca1967db098d Mon Sep 17 00:00:00 2001 From: Kenzo <[email protected]> Date: Tue, 18 Aug 2026 22:05:15 -0400 Subject: [PATCH] [Clang][Sema] Fix lambda attribute processing order with clang optimize off --- clang/lib/Sema/SemaLambda.cpp | 8 ++++---- .../CodeGenCXX/optnone-pragma-optimize-off.cpp | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index b97c6d8b95f62..6c9a837cc8a79 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -1513,10 +1513,6 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, CheckCXXDefaultArguments(Method); - // This represents the function body for the lambda function, check if we - // have to apply optnone due to a pragma. - AddRangeBasedOptnone(Method); - // code_seg attribute on lambda apply to the method. if (Attr *A = getImplicitCodeSegOrSectionAttrForFunction( Method, /*IsDefinition=*/true)) @@ -1525,6 +1521,10 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, // Attributes on the lambda apply to the method. ProcessDeclAttributes(CurScope, Method, ParamInfo); + // This represents the function body for the lambda function, check if we + // have to apply optnone due to a pragma. + AddRangeBasedOptnone(Method); + if (Context.getTargetInfo().getTriple().isAArch64()) ARM().CheckSMEFunctionDefAttributes(Method); diff --git a/clang/test/CodeGenCXX/optnone-pragma-optimize-off.cpp b/clang/test/CodeGenCXX/optnone-pragma-optimize-off.cpp index d750c4c2848cb..2819db70fb896 100644 --- a/clang/test/CodeGenCXX/optnone-pragma-optimize-off.cpp +++ b/clang/test/CodeGenCXX/optnone-pragma-optimize-off.cpp @@ -13,4 +13,20 @@ void foo(int p) { _Pragma("clang optimize on") -// CHECK: attributes #[[LAMBDA_ATR]] = { {{.*}} optnone {{.*}} } \ No newline at end of file +// An always_inline lambda should not have noinline and optnone and should +// compile under _Pragma("clang optimize off") +_Pragma("clang optimize off") + +__attribute__((always_inline)) void bar() {} +// CHECK: define {{.*}}void @_Z3barv() #[[ALWAYSINLINE:[0-9]+]] + +auto lambda = []() __attribute__((always_inline)) { return 42; }; +// CHECK: define {{.*}} @"_ZNK3$_1clEv"({{.*}}) #[[ALWAYSINLINE]] + +int caller() { + bar(); + return lambda(); +} + +// CHECK: attributes #[[LAMBDA_ATR]] = { {{.*}} optnone {{.*}} } +// CHECK: attributes #[[ALWAYSINLINE]] = {{{.*}}alwaysinline{{.*}}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
