svn commit: r272304 - in stable/9/contrib/llvm: patches tools/clang/lib/CodeGen

Ed Maste emaste at FreeBSD.org
Tue Sep 30 15:10:42 UTC 2014


Author: emaste
Date: Tue Sep 30 15:10:40 2014
New Revision: 272304
URL: http://svnweb.freebsd.org/changeset/base/272304

Log:
  MFC Clang debug info crash fix
  
  271282: Merge Clang debug info crash fix rev 200797:
  
      Debug info: fix a crasher when when emitting debug info for
      not-yet-completed templated types. getTypeSize() needs a complete type.
  
      rdar://problem/15931354
  
  271283: Add clang patch for r271282
  
    Note that r271282 contains only the src change from Clang rev 200797.
    This patch file includes two follow-on changes to the test case, which
    do not apply to the copy in the FreeBSD tree.
  
    Upstream Clang revisions:
  
    200797:
  
      Debug info: fix a crasher when when emitting debug info for
      not-yet-completed templated types. getTypeSize() needs a complete type.
  
      rdar://problem/15931354
  
    200798:
  
      Simplify testcase from r200797 some more.
  
    200805:
  
      Further simplify r200797 and add an explanatory comment.
  
  PR:		193347

Added:
  stable/9/contrib/llvm/patches/patch-r271282-clang-r200797-r200798-r200805-debug-info-crash.diff
     - copied unchanged from r271283, head/contrib/llvm/patches/patch-r271282-clang-r200797-r200798-r200805-debug-info-crash.diff
Modified:
  stable/9/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
Directory Properties:
  stable/9/contrib/llvm/   (props changed)
  stable/9/contrib/llvm/tools/clang/   (props changed)

Copied: stable/9/contrib/llvm/patches/patch-r271282-clang-r200797-r200798-r200805-debug-info-crash.diff (from r271283, head/contrib/llvm/patches/patch-r271282-clang-r200797-r200798-r200805-debug-info-crash.diff)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/contrib/llvm/patches/patch-r271282-clang-r200797-r200798-r200805-debug-info-crash.diff	Tue Sep 30 15:10:40 2014	(r272304, copy of r271283, head/contrib/llvm/patches/patch-r271282-clang-r200797-r200798-r200805-debug-info-crash.diff)
@@ -0,0 +1,51 @@
+diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
+index 59ba47c..dddc7e7 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 0000000..b2b7073
+--- /dev/null
++++ b/test/CodeGenCXX/debug-info-template-fwd.cpp
+@@ -0,0 +1,27 @@
++// 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_structure_type ] [Derived<int>] {{.*}} [def]
++// rdar://problem/15931354
++template <class A> class Derived;
++
++template <class A> class Base {
++  static Derived<A> *create();
++};
++
++template <class A> struct Derived : Base<A> {
++};
++
++Base<int> *f;
++
++// During the instantiation of Derived<int>, Base<int> becomes required to be
++// complete - since the declaration has already been emitted (due to 'f',
++// above), we immediately try to build debug info for Base<int> which then
++// requires the (incomplete definition) of Derived<int> which is problematic.
++//
++// (if 'f' is not present, the point at which Base<int> becomes required to be
++// complete during the instantiation of Derived<int> is a no-op because
++// Base<int> was never emitted so we ignore it and carry on until we
++// wire up the base class of Derived<int> in the debug info later on)
++Derived<int> d;

Modified: stable/9/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp
==============================================================================
--- stable/9/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp	Tue Sep 30 15:07:06 2014	(r272303)
+++ stable/9/contrib/llvm/tools/clang/lib/CodeGen/CGDebugInfo.cpp	Tue Sep 30 15:10:40 2014	(r272304)
@@ -2233,9 +2233,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);


More information about the svn-src-stable-9 mailing list