[PATCH] D30082: Fix assertion when generating debug information for deduced template specialization types.

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 16 22:36:38 PST 2017


EricWF created this revision.
Herald added a subscriber: aprantl.

Currently the following code hits an `llvm_unreachable` in `CGDebugInfo::CreateTypeNode`  because `DeducedTemplateSpecialization` isn't handled.

  // clang++ -std=c++1z -g test.cpp
  template <class T> struct S { S(T) {} };
  S s(42);

This patch attempts to fix the handling of `DeducedTemplateSpecialization` as to correctly emit debug information. I've also attempted to write a test checking the emission of the debug information, but IDK if it's testing for the right output.


https://reviews.llvm.org/D30082

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGenCXX/debug-info-template-deduction-guide.cpp


Index: test/CodeGenCXX/debug-info-template-deduction-guide.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/debug-info-template-deduction-guide.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang -S -emit-llvm -target x86_64-unknown_unknown -g %s -o - -std=c++1z | FileCheck %s
+
+// Verify that we don't crash when emitting debug information for objects
+// created from a deduced template specialization.
+
+template <class T>
+struct S {
+  S(T) {}
+};
+
+// CHECK: !DIGlobalVariable(name: "s1"
+// CHECK-SAME: type: [[TYPE_NUM:![0-9]+]]
+// CHECK: !DIGlobalVariable(name: "s2"
+// CHECK-SAME: type: [[TYPE_NUM]]
+// CHECK: [[TYPE_NUM]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S<int>",
+S s1(42);
+S<int> s2(42);
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -2475,6 +2475,12 @@
     case Type::SubstTemplateTypeParm:
       T = cast<SubstTemplateTypeParmType>(T)->getReplacementType();
       break;
+    case Type::DeducedTemplateSpecialization: {
+      QualType DT = dyn_cast<DeducedType>(T)->getDeducedType();
+      assert(!DT.isNull() && "Undeduced types shouldn't reach here.");
+      T = DT;
+      break;
+    }
     case Type::Auto: {
       QualType DT = cast<AutoType>(T)->getDeducedType();
       assert(!DT.isNull() && "Undeduced types shouldn't reach here.");
@@ -2638,11 +2644,12 @@
   case Type::TemplateSpecialization:
     return CreateType(cast<TemplateSpecializationType>(Ty), Unit);
 
+  case Type::DeducedTemplateSpecialization:
+    assert(isa<DeducedTemplateSpecializationType>(Ty));
   case Type::Auto:
   case Type::Attributed:
   case Type::Adjusted:
   case Type::Decayed:
-  case Type::DeducedTemplateSpecialization:
   case Type::Elaborated:
   case Type::Paren:
   case Type::SubstTemplateTypeParm:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30082.88858.patch
Type: text/x-patch
Size: 1925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170217/936c5f45/attachment.bin>


More information about the cfe-commits mailing list