llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.69k stars 11.87k forks source link

vla var with typedef'd type has incomplete debug info #47591

Open vries opened 3 years ago

vries commented 3 years ago
Bugzilla Link 48247
Version 10.0
OS Linux
CC @dwblaikie,@JDevlieghere,@walkerkd,@pogo59

Extended Description

Consider test.c: ... int n = 5; int a = 1;

int main (void) {

if V == 1

int vla[n];

elif V == 2

typedef int vla_t[n]; vla_t vla;

endif

for (int i = 0; i < n; i++) vla[i] = i;

return vla[a]; } ...

With gcc, we print the correct type of vla in both V=1 and V=2 cases: ... $ gcc test.c -g -DV=1 $ gdb -batch a.out -ex "b 17" -ex run -ex "ptype vla" Breakpoint 1 at 0x400533: file test.c, line 17.

Breakpoint 1, main () at test.c:17 17 return vla[a]; type = int [5] $ gcc test.c -g -DV=2 $ gdb -batch a.out -ex "b 17" -ex run -ex "ptype vla" Breakpoint 1 at 0x400533: file test.c, line 17.

Breakpoint 1, main () at test.c:17 17 return vla[a]; type = int [5] ...

With clang-10, that's only for V=1: ... $ clang test.c -g -DV=1 $ gdb -batch a.out -ex "b 17" -ex run -ex "ptype vla" Breakpoint 1 at 0x40050e: file test.c, line 17.

Breakpoint 1, main () at test.c:17 17 return vla[a]; type = int [5] $ clang test.c -g -DV=2 $ gdb -batch a.out -ex "b 17" -ex run -ex "ptype vla" Breakpoint 1 at 0x40050e: file test.c, line 17.

Breakpoint 1, main () at test.c:17 17 return vla[a]; type = int [] ...

With clang and V=2, the variable vla: ...

<2><147>: Abbrev Number: 6 (DW_TAG_variable) <14c> DW_AT_name : (indirect string, offset: 0x21d): vla <152> DW_AT_type : <0x172> ... has type: ... <2><172>: Abbrev Number: 9 (DW_TAG_typedef) <173> DW_AT_type : <0x185> <177> DW_AT_name : (indirect string, offset: 0x235): vla_t ... which refers to type: ... <1><185>: Abbrev Number: 10 (DW_TAG_array_type) <186> DW_AT_type : <0x106> <2><18a>: Abbrev Number: 11 (DW_TAG_subrange_type) <18b> DW_AT_type : <0x190> ... There's no DW_AT_count for the DW_TAG_subrange_type.
pogo59 commented 3 years ago

Moved to DebugInfo for better visibility.