]> granicus.if.org Git - clang/commitdiff
Don't crash when mangling types defined in ObjC class extensions.
authorJohn McCall <rjmccall@apple.com>
Wed, 10 Apr 2013 06:08:21 +0000 (06:08 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 10 Apr 2013 06:08:21 +0000 (06:08 +0000)
The original test case here was mangling a type name for TBAA,
but we can provoke this in C++11 easily enough.

rdar://13434937

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179153 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ItaniumMangle.cpp
test/CodeGenObjCXX/mangle.mm

index 21c499317f5eb773986521ec73ec9221acb0b697..0f4881e24eac22522a26a635c63fc54bc16a475c 100644 (file)
@@ -1095,6 +1095,15 @@ void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
       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);
index 2521c6076a8c17c6e7479d73e297937e216d60a0..45a93a196dcbd04658eb200b598c975d1c627ca6 100644 (file)
@@ -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
   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.
+@interface Test2 @end
+@interface Test2 ()
+@property (assign) enum { T2x, T2y, T2z } axis;
+@end
+@interface Test2 (a)
+@property (assign) enum { T2i, T2j, T2k } dimension;
+@end
+@implementation Test2 {
+@public
+  enum { T2a, T2b, T2c } alt_axis;
+}
+@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;
+}