[llvm-bugs] [Bug 44695] New: [DebugInfo] Static variables declared inside functions always have the function scope
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jan 28 06:23:10 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=44695
Bug ID: 44695
Summary: [DebugInfo] Static variables declared inside functions
always have the function scope
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: DebugInfo
Assignee: unassignedbugs at nondot.org
Reporter: ch.bessonova at gmail.com
CC: aprantl at apple.com, jdevlieghere at apple.com,
keith.walker at arm.com, llvm-bugs at lists.llvm.org,
paul_robinson at playstation.sony.com
If a static variable is defined inside of some bracketed block in a function,
clang/llvm will handle it as it has the function scope, not the corresponded
bracketed block scope.
Conside the following example:
1 int foo() { return 42; };
2 int main() {
3 int a = foo();
4 switch(a) {
5 case 1: {
6 static const int a = 1;
7 return a;
8 }
9 case 2: {
10 static const int a = 2;
11 return a;
12 }
13 }
14 }
Here are 3 'a' variables, all of them have function scope according to the
dwarfdump:
0x0000002a: DW_TAG_subprogram
DW_AT_low_pc (0x0000000000401120)
DW_AT_high_pc (0x000000000040117a)
DW_AT_frame_base (DW_OP_reg6 RBP)
DW_AT_name ("main")
DW_AT_decl_file ("temp.cpp")
DW_AT_decl_line (3)
DW_AT_type (0x00000081 "int")
DW_AT_external (true)
0x00000043: DW_TAG_variable
DW_AT_name ("a")
DW_AT_type (0x0000007c "const int")
DW_AT_decl_file ("temp.cpp")
DW_AT_decl_line (7)
DW_AT_location (DW_OP_addr 0x402004)
0x00000058: DW_TAG_variable
DW_AT_name ("a")
DW_AT_type (0x0000007c "const int")
DW_AT_decl_file ("temp.cpp")
DW_AT_decl_line (11)
DW_AT_location (DW_OP_addr 0x402008)
0x0000006d: DW_TAG_variable
DW_AT_location (DW_OP_fbreg -8)
DW_AT_name ("a")
DW_AT_decl_file ("temp.cpp")
DW_AT_decl_line (4)
DW_AT_type (0x00000081 "int")
This confuses debuggers: gdb will print 1 for 'a' even on line 4.
Note: gcc-9.2 generates DW_TAG_lexical_block's for the bracketed blocks and
puts static 'a's there, so gdb prints 42 for 'a' on line 4 as expected.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200128/0d9a99f0/attachment.html>
More information about the llvm-bugs
mailing list