summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/patches/patch-r271282-clang-r200797-r200798-r200805-debug-info-crash.diff
blob: 4088dbb6dc7d99295b70621114d5342b9150ccca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Pull in r200797 from upstream clang trunk (by Adrian Prantl):

  Debug info: fix a crasher when when emitting debug info for
  not-yet-completed templated types. getTypeSize() needs a complete type.

  rdar://problem/15931354

Introduced here: http://svnweb.freebsd.org/changeset/base/271282

Index: tools/clang/lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- tools/clang/lib/CodeGen/CGDebugInfo.cpp
+++ tools/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2251,9 +2251,10 @@ llvm::DICompositeType CGDebugInfo::CreateLimitedTy
   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);
Index: tools/clang/test/CodeGenCXX/debug-info-template-fwd.cpp
===================================================================
--- tools/clang/test/CodeGenCXX/debug-info-template-fwd.cpp
+++ tools/clang/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<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();
+}
OpenPOWER on IntegriCloud