From 906cfe1bf36df2d0efbea663dcc91f9e36e2e097 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Fri, 20 Jul 2018 20:55:00 +0000 Subject: [PATCH] [codeview] Don't emit variable templates as class members MSVC doesn't, so neither should we. Fixes PR38004, which is a crash that happens when we try to emit debug info for a still-dependent partial variable template specialization. As a follow-up, we should review what we're doing for function and class member templates. It looks like we don't filter those out, but I can't seem to get clang to emit any. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337616 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 15 +++++--- .../debug-info-codeview-var-templates.cpp | 35 +++++++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 test/CodeGenCXX/debug-info-codeview-var-templates.cpp diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 08447f895e..10fc22a098 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1298,10 +1298,6 @@ void CGDebugInfo::CollectRecordFields( else { const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record); - // Debug info for nested types is included in the member list only for - // CodeView. - bool IncludeNestedTypes = CGM.getCodeGenOpts().EmitCodeView; - // Field number for non-static fields. unsigned fieldNo = 0; @@ -1311,6 +1307,13 @@ void CGDebugInfo::CollectRecordFields( if (const auto *V = dyn_cast(I)) { if (V->hasAttr()) continue; + + // Skip variable template specializations when emitting CodeView. MSVC + // doesn't emit them. + if (CGM.getCodeGenOpts().EmitCodeView && + isa(V)) + continue; + // Reuse the existing static member declaration if one exists auto MI = StaticDataMemberCache.find(V->getCanonicalDecl()); if (MI != StaticDataMemberCache.end()) { @@ -1327,7 +1330,9 @@ void CGDebugInfo::CollectRecordFields( // Bump field number for next field. ++fieldNo; - } else if (IncludeNestedTypes) { + } else if (CGM.getCodeGenOpts().EmitCodeView) { + // Debug info for nested types is included in the member list only for + // CodeView. if (const auto *nestedType = dyn_cast(I)) if (!nestedType->isImplicit() && nestedType->getDeclContext() == record) diff --git a/test/CodeGenCXX/debug-info-codeview-var-templates.cpp b/test/CodeGenCXX/debug-info-codeview-var-templates.cpp new file mode 100644 index 0000000000..0470c13368 --- /dev/null +++ b/test/CodeGenCXX/debug-info-codeview-var-templates.cpp @@ -0,0 +1,35 @@ +// RUN: %clang_cc1 %s -std=c++14 -triple=i686-pc-windows-msvc -debug-info-kind=limited -gcodeview -emit-llvm -o - | FileCheck %s + +// Don't emit static data member debug info for variable templates. +// PR38004 + +struct TestImplicit { + template + static const __SIZE_TYPE__ size_var = sizeof(T); +}; +int instantiate_test1() { return TestImplicit::size_var + TestImplicit::size_var; } +TestImplicit gv1; + +// CHECK: ![[empty:[0-9]+]] = !{} + +// CHECK: ![[A:[^ ]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TestImplicit", +// CHECK-SAME: elements: ![[empty]] + +template bool vtpl; +struct TestSpecialization { + template static const auto sdm = vtpl; + template <> static const auto sdm = false; +} gv2; + +// CHECK: ![[A:[^ ]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TestSpecialization", +// CHECK-SAME: elements: ![[empty]] + +template bool a; +template struct b; +struct TestPartial { + template static auto d = a; + template static auto d> = d; +} c; + +// CHECK: ![[A:[^ ]*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "TestPartial", +// CHECK-SAME: elements: ![[empty]] -- 2.50.1