From: Amy Huang Date: Wed, 29 May 2019 21:45:34 +0000 (+0000) Subject: CodeView - add static data members to global variable debug info. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e7fac8a0763b4595c1e8db743697857a93d2bf7d;p=clang CodeView - add static data members to global variable debug info. Summary: Add static data members to IR debug info's list of global variables so that they are emitted as S_CONSTANT records. Related to https://bugs.llvm.org/show_bug.cgi?id=41615. Reviewers: rnk Subscribers: aprantl, cfe-commits, llvm-commits, thakis Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D62167 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@362038 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 89c053f4b2..b79169f0a0 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -4361,9 +4361,13 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) { return; } - // Do not emit separate definitions for function local const/statics. + llvm::DIScope *DContext = nullptr; + + // Do not emit separate definitions for function local consts. if (isa(VD->getDeclContext())) return; + + // Emit definition for static members in CodeView. VD = cast(VD->getCanonicalDecl()); auto *VarD = cast(VD); if (VarD->isStaticDataMember()) { @@ -4375,10 +4379,16 @@ void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) { // through its scope. RetainedTypes.push_back( CGM.getContext().getRecordType(RD).getAsOpaquePtr()); - return; - } - llvm::DIScope *DContext = getDeclContextDescriptor(VD); + if (!CGM.getCodeGenOpts().EmitCodeView) + return; + + // Use the global scope for static members. + DContext = getContextDescriptor( + cast(CGM.getContext().getTranslationUnitDecl()), TheCU); + } else { + DContext = getDeclContextDescriptor(VD); + } auto &GV = DeclCache[VD]; if (GV) diff --git a/test/CodeGenCXX/debug-info-static-member.cpp b/test/CodeGenCXX/debug-info-static-member.cpp index 702d1f87e7..8ad86843f4 100644 --- a/test/CodeGenCXX/debug-info-static-member.cpp +++ b/test/CodeGenCXX/debug-info-static-member.cpp @@ -1,6 +1,7 @@ // RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | FileCheck %s // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S -o - | FileCheck %s // RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S -o - | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-windows-msvc -gcodeview -debug-info-kind=limited %s -emit-llvm -o - | FileCheck --check-prefix MSVC %s // PR14471 // CHECK: @_ZN1C1aE = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]] @@ -35,6 +36,7 @@ public: // CHECK: [[A]] = !DIGlobalVariableExpression(var: [[AV:.*]], expr: !DIExpression()) // CHECK: [[AV]] = distinct !DIGlobalVariable(name: "a", // CHECK-SAME: declaration: ![[DECL_A:[0-9]+]]) +// MSVC: distinct !DIGlobalVariable(name: "a" // // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}}, identifier: "_ZTS1X") // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "anon_static_decl_struct" @@ -48,6 +50,7 @@ int C::a = 4; // CHECK: [[B]] = !DIGlobalVariableExpression(var: [[BV:.*]], expr: !DIExpression()) // CHECK: [[BV]] = distinct !DIGlobalVariable(name: "b", // CHECK-SAME: declaration: ![[DECL_B:[0-9]+]]) +// MSVC: distinct !DIGlobalVariable(name: "b" // CHECK: ![[DECL_B]] = !DIDerivedType(tag: DW_TAG_member, name: "b" // CHECK-NOT: size: // CHECK-NOT: align: @@ -95,6 +98,7 @@ int C::a = 4; int C::b = 2; // CHECK: [[C]] = !DIGlobalVariableExpression(var: [[CV:.*]], expr: !DIExpression()) // CHECK: [[CV]] = distinct !DIGlobalVariable(name: "c", {{.*}} declaration: ![[DECL_C]]) +// MSVC: distinct !DIGlobalVariable(name: "c" int C::c = 1; int main() @@ -114,11 +118,18 @@ struct anon_static_decl_struct { }; } - int ref() { return anon_static_decl_struct::anon_static_decl_var; } +// In MSVC, static data members should be emitted as global variables when used. +// MSVC: !DIGlobalVariableExpression(var: [[ANON_STATIC_DECL:![0-9]+]], +// MSVC-SAME: !DIExpression(DW_OP_constu, 117, DW_OP_stack_value) +// MSVC: [[ANON_STATIC_DECL]] = distinct !DIGlobalVariable(name: "anon_static_decl_var" +// MSVC: !DIGlobalVariableExpression(var: [[STATIC_DECL_TEMPL:![0-9]+]] +// MSVC-SAME: !DIExpression(DW_OP_constu, 7, DW_OP_stack_value) +// MSVC: [[STATIC_DECL_TEMPL]] = distinct !DIGlobalVariable(name: "static_decl_templ_var" + template struct static_decl_templ { static const int static_decl_templ_var = 7;