patch-r271282-clang-r200797-r200798-r200805-debug-info-crash.diff revision 278716
1Pull in r200797 from upstream clang trunk (by Adrian Prantl): 2 3 Debug info: fix a crasher when when emitting debug info for 4 not-yet-completed templated types. getTypeSize() needs a complete type. 5 6 rdar://problem/15931354 7 8Introduced here: http://svnweb.freebsd.org/changeset/base/271282 9 10Index: tools/clang/lib/CodeGen/CGDebugInfo.cpp 11=================================================================== 12--- tools/clang/lib/CodeGen/CGDebugInfo.cpp 13+++ tools/clang/lib/CodeGen/CGDebugInfo.cpp 14@@ -2251,9 +2251,10 @@ llvm::DICompositeType CGDebugInfo::CreateLimitedTy 15 if (T && (!T.isForwardDecl() || !RD->getDefinition())) 16 return T; 17 18- // If this is just a forward declaration, construct an appropriately 19- // marked node and just return it. 20- if (!RD->getDefinition()) 21+ // If this is just a forward or incomplete declaration, construct an 22+ // appropriately marked node and just return it. 23+ const RecordDecl *D = RD->getDefinition(); 24+ if (!D || !D->isCompleteDefinition()) 25 return getOrCreateRecordFwdDecl(Ty, RDContext); 26 27 uint64_t Size = CGM.getContext().getTypeSize(Ty); 28Index: tools/clang/test/CodeGenCXX/debug-info-template-fwd.cpp 29=================================================================== 30--- tools/clang/test/CodeGenCXX/debug-info-template-fwd.cpp 31+++ tools/clang/test/CodeGenCXX/debug-info-template-fwd.cpp 32@@ -0,0 +1,36 @@ 33+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -g -emit-llvm -o - | FileCheck %s 34+// This test is for a crash when emitting debug info for not-yet-completed types. 35+// Test that we don't actually emit a forward decl for the offending class: 36+// CHECK: [ DW_TAG_class_type ] [Derived<const __CFString, Foo>] {{.*}} [def] 37+// rdar://problem/15931354 38+typedef const struct __CFString * CFStringRef; 39+template <class R> class Returner {}; 40+typedef const __CFString String; 41+ 42+template <class A, class B> class Derived; 43+ 44+template <class A, class B> 45+class Base 46+{ 47+ static Derived<A, B>* create(); 48+}; 49+ 50+template <class A, class B> 51+class Derived : public Base<A, B> { 52+public: 53+ static void foo(); 54+}; 55+ 56+class Foo 57+{ 58+ Foo(); 59+ static Returner<Base<String,Foo> > all(); 60+}; 61+ 62+Foo::Foo(){} 63+ 64+Returner<Base<String,Foo> > Foo::all() 65+{ 66+ Derived<String,Foo>::foo(); 67+ return Foo::all(); 68+} 69