r179153 - Don't crash when mangling types defined in ObjC class extensions.

John McCall rjmccall at apple.com
Tue Apr 9 23:08:21 PDT 2013


Author: rjmccall
Date: Wed Apr 10 01:08:21 2013
New Revision: 179153

URL: http://llvm.org/viewvc/llvm-project?rev=179153&view=rev
Log:
Don't crash when mangling types defined in ObjC class extensions.

The original test case here was mangling a type name for TBAA,
but we can provoke this in C++11 easily enough.

rdar://13434937

Modified:
    cfe/trunk/lib/AST/ItaniumMangle.cpp
    cfe/trunk/test/CodeGenObjCXX/mangle.mm

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=179153&r1=179152&r2=179153&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Wed Apr 10 01:08:21 2013
@@ -1095,6 +1095,15 @@ void CXXNameMangler::mangleUnqualifiedNa
       mangleSourceName(FD->getIdentifier());
       break;
     }
+
+    // Class extensions have no name as a category, and it's possible
+    // for them to be the semantic parent of certain declarations
+    // (primarily, tag decls defined within declarations).  Such
+    // declarations will always have internal linkage, so the name
+    // doesn't really matter, but we shouldn't crash on them.  For
+    // safety, just handle all ObjC containers here.
+    if (isa<ObjCContainerDecl>(ND))
+      break;
     
     // We must have an anonymous struct.
     const TagDecl *TD = cast<TagDecl>(ND);

Modified: cfe/trunk/test/CodeGenObjCXX/mangle.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/mangle.mm?rev=179153&r1=179152&r2=179153&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjCXX/mangle.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/mangle.mm Wed Apr 10 01:08:21 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - | FileCheck %s
 
 // CHECK: @"_ZZ11+[A shared]E1a" = internal global
 // CHECK: @"_ZZ11-[A(Foo) f]E1a" = internal global
@@ -54,3 +54,27 @@
   uiIsVisible();
 }
 @end
+
+// rdar://13434937
+//
+// Don't crash when mangling an enum whose semantic context
+// is a class extension (which looks anonymous in the AST).
+// The other tests here are just for coverage.
+ at interface Test2 @end
+ at interface Test2 ()
+ at property (assign) enum { T2x, T2y, T2z } axis;
+ at end
+ at interface Test2 (a)
+ at property (assign) enum { T2i, T2j, T2k } dimension;
+ at end
+ at implementation Test2 {
+ at public
+  enum { T2a, T2b, T2c } alt_axis;
+}
+ at end
+template <class T> struct Test2Template { Test2Template() {} }; // must have a member that we'll instantiate and mangle
+void test2(Test2 *t) {
+  Test2Template<decltype(t.axis)> t0;
+  Test2Template<decltype(t.dimension)> t1;
+  Test2Template<decltype(t->alt_axis)> t2;
+}





More information about the cfe-commits mailing list