From d8e6e77fd65439b70b975972acdc7662689edff0 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 22 Feb 2017 00:13:14 +0000 Subject: [PATCH] Fix assertion failure when generating debug information for a variable declaration declared using class template argument deduction. Patch by Eric Fiselier (who is busy and asked me to commit this on his behalf)! Differential Revision: https://reviews.llvm.org/D30082 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295794 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 5 +++-- .../debug-info-template-deduction-guide.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 test/CodeGenCXX/debug-info-template-deduction-guide.cpp diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 252ee8d71d..acfe0a4d7d 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -2475,8 +2475,9 @@ static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C) { case Type::SubstTemplateTypeParm: T = cast(T)->getReplacementType(); break; - case Type::Auto: { - QualType DT = cast(T)->getDeducedType(); + case Type::Auto: + case Type::DeducedTemplateSpecialization: { + QualType DT = cast(T)->getDeducedType(); assert(!DT.isNull() && "Undeduced types shouldn't reach here."); T = DT; break; diff --git a/test/CodeGenCXX/debug-info-template-deduction-guide.cpp b/test/CodeGenCXX/debug-info-template-deduction-guide.cpp new file mode 100644 index 0000000000..26eb2156e6 --- /dev/null +++ b/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 +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", +S s1(42); +S s2(42); -- 2.40.0