akhuang updated this revision to Diff 319348.
akhuang marked an inline comment as done.
akhuang added a comment.

change to function returning a number, fill in ItaniumMangle function


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95187/new/

https://reviews.llvm.org/D95187

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
  clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp

Index: clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
===================================================================
--- clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
+++ clang/test/CodeGenCXX/debug-info-gline-tables-only-codeview.cpp
@@ -6,10 +6,15 @@
 namespace NS {
 struct C {
   void m() {}
+  // Test externally visible lambda.
+  void lambda2() { []() {}(); }
 };
 void f() {}
 }
 
+// Test non- externally visible lambda.
+auto lambda1 = []() { return 1; };
+
 NS::C c;
 
 void test() {
@@ -27,4 +32,16 @@
   // CHECK-NOT: identifier
   // CHECK: ![[MTYPE]] = !DISubroutineType(types: !{{.*}})
   c.m();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA1:[0-9]+]]
+  // CHECK: ![[LAMBDA1]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:                            name: "<lambda_0>"
+  // CHECK-SAME:                            flags: DIFlagFwdDecl
+  lambda1();
+
+  // CHECK: !DISubprogram(name: "operator()", scope: ![[LAMBDA2:[0-9]+]]
+  // CHECK: ![[LAMBDA2]] = !DICompositeType(tag: DW_TAG_class_type,
+  // CHECK-SAME:                            name: "<lambda_1>"
+  // CHECK-SAME:                            flags: DIFlagFwdDecl
+  c.lambda2();
 }
Index: clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
===================================================================
--- clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
+++ clang/test/CodeGenCXX/debug-info-codeview-unnamed.cpp
@@ -100,7 +100,7 @@
   // MSVC-SAME:      )
   // MSVC:       [[TYPE_OF_FOUR]] = distinct !DICompositeType
   // MSVC-SAME:      tag: DW_TAG_class_type
-  // MSVC-NOT:       name:
+  // MSVC-SAME:      name: "<lambda_0>"
   // MSVC-SAME:      identifier: ".?AV<lambda_0>@?0??main@@9@"
   // MSVC-SAME:      )
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -317,8 +317,9 @@
   if (const IdentifierInfo *II = RD->getIdentifier())
     return II->getName();
 
-  // The CodeView printer in LLVM wants to see the names of unnamed types: it is
-  // used to reconstruct the fully qualified type names.
+  // The CodeView printer in LLVM wants to see the names of unnamed types
+  // because they need to have a unique identifier.
+  // These names are used to reconstruct the fully qualified type names.
   if (CGM.getCodeGenOpts().EmitCodeView) {
     if (const TypedefNameDecl *D = RD->getTypedefNameForAnonDecl()) {
       assert(RD->getDeclContext() == D->getDeclContext() &&
@@ -342,6 +343,18 @@
         // associate typedef mangled in if they have one.
         Name = TND->getName();
 
+      // Give lambdas a display name based on their name mangling.
+      if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
+        if (CXXRD->isLambda()) {
+          unsigned LambdaNumber =
+              CGM.getCXXABI().getMangleContext().getLambdaNumber(CXXRD);
+
+          SmallString<256> LambdaName("<lambda_");
+          LambdaName += std::to_string(LambdaNumber);
+          LambdaName += '>';
+          return internString(LambdaName);
+        }
+
       if (!Name.empty()) {
         SmallString<256> UnnamedType("<unnamed-type-");
         UnnamedType += Name;
Index: clang/lib/AST/MicrosoftMangle.cpp
===================================================================
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -228,6 +228,14 @@
     return true;
   }
 
+  unsigned getLambdaNumber(const CXXRecordDecl *Lambda) override {
+    unsigned LambdaManglingNumber = Lambda->getLambdaManglingNumber();
+    if (LambdaManglingNumber)
+      return LambdaManglingNumber;
+    else
+      return getLambdaId(Lambda);
+  }
+
   unsigned getLambdaId(const CXXRecordDecl *RD) {
     assert(RD->isLambda() && "RD must be a lambda!");
     assert(!RD->isExternallyVisible() && "RD must not be visible!");
Index: clang/lib/AST/ItaniumMangle.cpp
===================================================================
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -203,6 +203,14 @@
     disc = discriminator-2;
     return true;
   }
+
+  unsigned getLambdaNumber(const CXXRecordDecl *Lambda) override {
+    unsigned Number = Lambda->getLambdaManglingNumber();
+    if (Number == 0)
+      return getAnonymousStructId(Lambda);
+    return Number;
+  }
+
   /// @}
 };
 
Index: clang/include/clang/AST/Mangle.h
===================================================================
--- clang/include/clang/AST/Mangle.h
+++ clang/include/clang/AST/Mangle.h
@@ -89,6 +89,8 @@
     return Result.first->second;
   }
 
+  virtual unsigned getLambdaNumber(const CXXRecordDecl *Lambda) = 0;
+
   /// @name Mangler Entry Points
   /// @{
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to