krisb created this revision. krisb added reviewers: dblaikie, aprantl, probinson. Herald added a project: All. krisb requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This is a part from D113743 <https://reviews.llvm.org/D113743> split to make it easier to test and review. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D125694 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGenCXX/debug-info-static-locals.cpp Index: clang/test/CodeGenCXX/debug-info-static-locals.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/debug-info-static-locals.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s + +// Test that static local variables emitted in correct scopes. + +void test() { + static int bar = 2; + { + static int bar = 1; + { + static int bar = 0; + } + } +} + +// CHECK: [[FS_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: [[FS_GV:![0-9]+]] +// CHECK: [[FS_GV]] = distinct !DIGlobalVariable(name: "bar", scope: [[FSCOPE:![0-9]+]] +// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "test" +// CHECK-SAME: localDecls: [[FS_DECLS:![0-9]+]] +// CHECK: [[FS_DECLS]] = !{[[FS_GVE]]} +// CHECK: [[LB1_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: [[LB1_GV:![0-9]+]] +// CHECK: [[LB1_GV]] = distinct !DIGlobalVariable(name: "bar", scope: [[LB1SCOPE:![0-9]+]] +// CHECK: [[LB1SCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]] +// CHECK-SAME: localDecls: [[LB1_DECLS:![0-9]+]] +// CHECK: [[LB1_DECLS]] = !{[[LB1_GVE]]} +// CHECK: [[LB2_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: [[LB2_GV:![0-9]+]] +// CHECK: [[LB2_GV]] = distinct !DIGlobalVariable(name: "bar", scope: [[LB2SCOPE:![0-9]+]] +// CHECK: [[LB2SCOPE]] = distinct !DILexicalBlock(scope: [[LB1SCOPE]] +// CHECK-SAME: localDecls: [[LB2_DECLS:![0-9]+]] +// CHECK: [[LB2_DECLS]] = !{[[LB2_GVE]]} Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -3746,6 +3746,14 @@ TemplateParameters = nullptr; } + // Get context for static locals (that are technically globals) the same way + // we do for "local" locals -- by using current lexical block. + if (VD->isStaticLocal()) { + assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); + VDContext = LexicalBlockStack.back(); + return; + } + // Since we emit declarations (DW_AT_members) for static members, place the // definition of those static members in the namespace they were declared in // in the source code (the lexical decl context).
Index: clang/test/CodeGenCXX/debug-info-static-locals.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/debug-info-static-locals.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s + +// Test that static local variables emitted in correct scopes. + +void test() { + static int bar = 2; + { + static int bar = 1; + { + static int bar = 0; + } + } +} + +// CHECK: [[FS_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: [[FS_GV:![0-9]+]] +// CHECK: [[FS_GV]] = distinct !DIGlobalVariable(name: "bar", scope: [[FSCOPE:![0-9]+]] +// CHECK: [[FSCOPE]] = distinct !DISubprogram(name: "test" +// CHECK-SAME: localDecls: [[FS_DECLS:![0-9]+]] +// CHECK: [[FS_DECLS]] = !{[[FS_GVE]]} +// CHECK: [[LB1_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: [[LB1_GV:![0-9]+]] +// CHECK: [[LB1_GV]] = distinct !DIGlobalVariable(name: "bar", scope: [[LB1SCOPE:![0-9]+]] +// CHECK: [[LB1SCOPE]] = distinct !DILexicalBlock(scope: [[FSCOPE]] +// CHECK-SAME: localDecls: [[LB1_DECLS:![0-9]+]] +// CHECK: [[LB1_DECLS]] = !{[[LB1_GVE]]} +// CHECK: [[LB2_GVE:![0-9]+]] = !DIGlobalVariableExpression(var: [[LB2_GV:![0-9]+]] +// CHECK: [[LB2_GV]] = distinct !DIGlobalVariable(name: "bar", scope: [[LB2SCOPE:![0-9]+]] +// CHECK: [[LB2SCOPE]] = distinct !DILexicalBlock(scope: [[LB1SCOPE]] +// CHECK-SAME: localDecls: [[LB2_DECLS:![0-9]+]] +// CHECK: [[LB2_DECLS]] = !{[[LB2_GVE]]} Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -3746,6 +3746,14 @@ TemplateParameters = nullptr; } + // Get context for static locals (that are technically globals) the same way + // we do for "local" locals -- by using current lexical block. + if (VD->isStaticLocal()) { + assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!"); + VDContext = LexicalBlockStack.back(); + return; + } + // Since we emit declarations (DW_AT_members) for static members, place the // definition of those static members in the namespace they were declared in // in the source code (the lexical decl context).
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits