r200797 - Debug info: fix a crasher when when emitting debug info for

Adrian Prantl aprantl at apple.com
Tue Feb 4 13:29:51 PST 2014


Author: adrian
Date: Tue Feb  4 15:29:50 2014
New Revision: 200797

URL: http://llvm.org/viewvc/llvm-project?rev=200797&view=rev
Log:
Debug info: fix a crasher when when emitting debug info for
not-yet-completed templated types. getTypeSize() needs a complete type.

rdar://problem/15931354

Added:
    cfe/trunk/test/CodeGenCXX/debug-info-template-fwd.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=200797&r1=200796&r2=200797&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Feb  4 15:29:50 2014
@@ -2251,9 +2251,10 @@ llvm::DICompositeType CGDebugInfo::Creat
   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);

Added: cfe/trunk/test/CodeGenCXX/debug-info-template-fwd.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-template-fwd.cpp?rev=200797&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/debug-info-template-fwd.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-info-template-fwd.cpp Tue Feb  4 15:29:50 2014
@@ -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<const __CFString, Foo>] {{.*}} [def]
+// rdar://problem/15931354
+typedef const struct __CFString * CFStringRef;
+template <class R> class Returner {};
+typedef const __CFString String;
+
+template <class A, class B> class Derived;
+
+template <class A, class B>
+class Base
+{
+  static Derived<A, B>* create();
+};
+
+template <class A, class B>
+class Derived : public Base<A, B> {
+public:
+  static void foo();
+};
+
+class Foo
+{
+  Foo();
+  static Returner<Base<String,Foo> > all();
+};
+
+Foo::Foo(){}
+
+Returner<Base<String,Foo> > Foo::all()
+{
+  Derived<String,Foo>::foo();
+  return Foo::all();
+}





More information about the cfe-commits mailing list