From e4fc27fce5dfbd10cb3114a3172ae482b27429ce Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 4 Feb 2014 21:29:50 +0000 Subject: [PATCH] Debug info: fix a crasher when when emitting debug info for not-yet-completed templated types. getTypeSize() needs a complete type. rdar://problem/15931354 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200797 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 7 ++-- test/CodeGenCXX/debug-info-template-fwd.cpp | 36 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/CodeGenCXX/debug-info-template-fwd.cpp diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 59ba47c334..dddc7e7569 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2251,9 +2251,10 @@ llvm::DICompositeType CGDebugInfo::CreateLimitedType(const RecordType *Ty) { if (T && (!T.isForwardDecl() || !RD->getDefinition())) return T; - // If this is just a forward declaration, construct an appropriately - // marked node and just return it. - if (!RD->getDefinition()) + // If this is just a forward or incomplete declaration, construct an + // appropriately marked node and just return it. + const RecordDecl *D = RD->getDefinition(); + if (!D || !D->isCompleteDefinition()) return getOrCreateRecordFwdDecl(Ty, RDContext); uint64_t Size = CGM.getContext().getTypeSize(Ty); diff --git a/test/CodeGenCXX/debug-info-template-fwd.cpp b/test/CodeGenCXX/debug-info-template-fwd.cpp new file mode 100644 index 0000000000..5a7d5a9352 --- /dev/null +++ b/test/CodeGenCXX/debug-info-template-fwd.cpp @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -g -emit-llvm -o - | FileCheck %s +// This test is for a crash when emitting debug info for not-yet-completed types. +// Test that we don't actually emit a forward decl for the offending class: +// CHECK: [ DW_TAG_class_type ] [Derived] {{.*}} [def] +// rdar://problem/15931354 +typedef const struct __CFString * CFStringRef; +template class Returner {}; +typedef const __CFString String; + +template class Derived; + +template +class Base +{ + static Derived* create(); +}; + +template +class Derived : public Base { +public: + static void foo(); +}; + +class Foo +{ + Foo(); + static Returner > all(); +}; + +Foo::Foo(){} + +Returner > Foo::all() +{ + Derived::foo(); + return Foo::all(); +} -- 2.40.0