1 diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
2 index 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()))
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);
18 uint64_t Size = CGM.getContext().getTypeSize(Ty);
19 diff --git a/test/CodeGenCXX/debug-info-template-fwd.cpp b/test/CodeGenCXX/debug-info-template-fwd.cpp
21 index 0000000..b2b7073
23 +++ b/test/CodeGenCXX/debug-info-template-fwd.cpp
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
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;
33 +template <class A> class Base {
34 + static Derived<A> *create();
37 +template <class A> struct Derived : Base<A> {
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.
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)