[PATCH] AST: Mangle templated local classes instead of crashing

David Majnemer david.majnemer at gmail.com
Mon Oct 14 03:19:57 PDT 2013


Hi eli.friedman, rsmith, rjmccall,

On builds of clang compiled with asserts, we would crash during
mangling.
On builds of clang compiler without asserts, we would mangle in an extra
prefix.

i.e. Funtion()::Function::Type<void>[...] rather than Funtion()::Type<void>[...]

http://llvm-reviews.chandlerc.com/D1932

Files:
  lib/AST/ItaniumMangle.cpp
  test/CodeGenCXX/mangle-local-class-names.cpp

Index: lib/AST/ItaniumMangle.cpp
===================================================================
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -1504,18 +1504,16 @@
   if (NoFunction && isLocalContainerContext(DC))
     return;
 
-  assert(!isLocalContainerContext(DC));
-
-  const NamedDecl *ND = cast<NamedDecl>(DC);  
+  const NamedDecl *ND = cast<NamedDecl>(DC);
   if (mangleSubstitution(ND))
     return;
   
   // Check if we have a template.
   const TemplateArgumentList *TemplateArgs = 0;
   if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) {
     mangleTemplatePrefix(TD);
     mangleTemplateArgs(*TemplateArgs);
-  } else {
+  } else if (!isLocalContainerContext(DC)) {
     manglePrefix(getEffectiveDeclContext(ND), NoFunction);
     mangleUnqualifiedName(ND);
   }
Index: test/CodeGenCXX/mangle-local-class-names.cpp
===================================================================
--- test/CodeGenCXX/mangle-local-class-names.cpp
+++ test/CodeGenCXX/mangle-local-class-names.cpp
@@ -95,3 +95,23 @@
   y.g();
 }
 void CallLocalAnonStruct() { LocalAnonStruct(); }
+
+// CHECK: @_ZZ4Fun1vEN5Type15Type2IvE4Fun2Ev
+// CHECK: @_ZZZ4Fun1vEN5Type15Type2IvE4Fun2EvEN5Type35Type4IvE4Fun3Ev
+void Fun1() {
+  struct Type1 {
+    template <typename = void>
+    struct Type2 {
+      static void Fun2() {
+        struct Type3 {
+          template <typename = void>
+          struct Type4 {
+            static void Fun3() {}
+          };
+        };
+        Type3::template Type4<>::Fun3();
+      }
+    };
+  };
+  Type1::Type2<>::Fun2();
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1932.1.patch
Type: text/x-patch
Size: 1586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131014/2bfc3ca3/attachment.bin>


More information about the cfe-commits mailing list