Author: Corentin Jabot
Date: 2023-03-23T16:11:58+01:00
New Revision: 82c83d7e41053b72fc0dc84de9b8bee71986ffc3

URL: 
https://github.com/llvm/llvm-project/commit/82c83d7e41053b72fc0dc84de9b8bee71986ffc3
DIFF: 
https://github.com/llvm/llvm-project/commit/82c83d7e41053b72fc0dc84de9b8bee71986ffc3.diff

LOG: [Clang] Fix evaluation of parameters of lambda call operator attributes

Fix a regresion introduced by D124351.
Attributes of lambda call operator were evaluated in the
context of the closure object type rather than its operator,
causing an assertion failure.

This was because we temporarily switch to the class lambda to
produce the mangling of the lambda, but we stayed in that
context too long.

Reviewed By: eandrews, aaron.ballman

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaLambda.cpp
    clang/test/SemaCXX/lambda-expressions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 3a82c7b3e8285..64db9d065f9c6 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -390,6 +390,9 @@ buildTypeForLambdaCallOperator(Sema &S, 
clang::CXXRecordDecl *Class,
 void Sema::handleLambdaNumbering(
     CXXRecordDecl *Class, CXXMethodDecl *Method,
     std::optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling) {
+
+  ContextRAII ManglingContext(*this, Class->getDeclContext());
+
   if (Mangling) {
     bool HasKnownInternalLinkage;
     unsigned ManglingNumber, DeviceManglingNumber;
@@ -1324,8 +1327,6 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
       ParamInfo.getDeclSpec().getConstexprSpecifier(),
       IsLambdaStatic ? SC_Static : SC_None, Params, ExplicitResultType);
 
-  ContextRAII ManglingContext(*this, Class->getDeclContext());
-
   CheckCXXDefaultArguments(Method);
 
   // This represents the function body for the lambda function, check if we
@@ -1350,8 +1351,6 @@ void Sema::ActOnStartOfLambdaDefinition(LambdaIntroducer 
&Intro,
 
   handleLambdaNumbering(Class, Method);
 
-  ManglingContext.pop();
-
   for (auto &&C : LSI->Captures) {
     if (!C.isVariableCapture())
       continue;

diff  --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 84d224fdc835e..67853c991ce53 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -std=c++14 -Wno-unused-value -fsyntax-only -verify 
-verify=expected-cxx14 -fblocks %s
-// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify -fblocks 
%s
+// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -verify -ast-dump -fblocks %s 
| FileCheck %s
 
 namespace std { class type_info; };
 
@@ -704,3 +704,13 @@ static_assert([]() constexpr {
 }());
 } // namespace GH60936
 #endif
+
+// Call operator attributes refering to a variable should
+// be properly handled after D124351
+constexpr int i = 2;
+void foo() {
+  (void)[=][[gnu::aligned(i)]] () {}; // expected-warning{{C++2b extension}}
+  // CHECK: AlignedAttr
+  // CHECK-NEXT: ConstantExpr
+  // CHECK-NEXT: value: Int 2
+}


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

Reply via email to