patch-r271282-clang-r200797-r200798-r200805-debug-info-crash.diff revision 271414
1diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp 2index 59ba47c..dddc7e7 100644 3--- a/lib/CodeGen/CGDebugInfo.cpp 4+++ b/lib/CodeGen/CGDebugInfo.cpp 5@@ -2251,9 +2251,10 @@ llvm::DICompositeType CGDebugInfo::CreateLimitedType(const RecordType *Ty) { 6 if (T && (!T.isForwardDecl() || !RD->getDefinition())) 7 return T; 8 9- // If this is just a forward declaration, construct an appropriately 10- // marked node and just return it. 11- if (!RD->getDefinition()) 12+ // If this is just a forward or incomplete declaration, construct an 13+ // appropriately marked node and just return it. 14+ const RecordDecl *D = RD->getDefinition(); 15+ if (!D || !D->isCompleteDefinition()) 16 return getOrCreateRecordFwdDecl(Ty, RDContext); 17 18 uint64_t Size = CGM.getContext().getTypeSize(Ty); 19diff --git a/test/CodeGenCXX/debug-info-template-fwd.cpp b/test/CodeGenCXX/debug-info-template-fwd.cpp 20new file mode 100644 21index 0000000..b2b7073 22--- /dev/null 23+++ b/test/CodeGenCXX/debug-info-template-fwd.cpp 24@@ -0,0 +1,27 @@ 25+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -g -emit-llvm -o - | FileCheck %s 26+// This test is for a crash when emitting debug info for not-yet-completed 27+// types. 28+// Test that we don't actually emit a forward decl for the offending class: 29+// CHECK: [ DW_TAG_structure_type ] [Derived<int>] {{.*}} [def] 30+// rdar://problem/15931354 31+template <class A> class Derived; 32+ 33+template <class A> class Base { 34+ static Derived<A> *create(); 35+}; 36+ 37+template <class A> struct Derived : Base<A> { 38+}; 39+ 40+Base<int> *f; 41+ 42+// During the instantiation of Derived<int>, Base<int> becomes required to be 43+// complete - since the declaration has already been emitted (due to 'f', 44+// above), we immediately try to build debug info for Base<int> which then 45+// requires the (incomplete definition) of Derived<int> which is problematic. 46+// 47+// (if 'f' is not present, the point at which Base<int> becomes required to be 48+// complete during the instantiation of Derived<int> is a no-op because 49+// Base<int> was never emitted so we ignore it and carry on until we 50+// wire up the base class of Derived<int> in the debug info later on) 51+Derived<int> d; 52