LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 25934 - Incorrect debug info generated for variable size arrays
Summary: Incorrect debug info generated for variable size arrays
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-23 07:49 PST by Tamas Berghammer
Modified: 2018-10-25 20:12 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tamas Berghammer 2015-12-23 07:49:25 PST
Reproducing the issue:
* Compile the followoing code snippet with "clang++ -g var.cpp":
int main() {
    for (int i = 0; i < 10; ++i) {
        int x[i + 1];
        x[0]++;
    }
}
* Inspect the debug info for variable 'x'

The relevant parts of the debug info:
 <4><6b>: Abbrev Number: 5 (DW_TAG_variable)
    <6c>   DW_AT_location    : 0x0      (location list)
    <70>   DW_AT_name        : (indirect string, offset: 0x71): x       
    <74>   DW_AT_decl_file   : 1        
    <75>   DW_AT_decl_line   : 3        
    <76>   DW_AT_type        : <0x84>

<1><84>: Abbrev Number: 7 (DW_TAG_array_type)
    <85>   DW_AT_type        : <0x7d>   
 <2><89>: Abbrev Number: 8 (DW_TAG_subrange_type)
    <8a>   DW_AT_type        : <0x8f>   
 <2><8e>: Abbrev Number: 0
 <1><8f>: Abbrev Number: 9 (DW_TAG_base_type)
    <90>   DW_AT_name        : (indirect string, offset: 0x73): sizetype        
    <94>   DW_AT_byte_size   : 8        
    <95>   DW_AT_encoding    : 7        (unsigned)
 <1><96>: Abbrev Number: 0

The problem is that clang specifies a DW_TAG_subrange_type under DW_TAG_array_type but is fails to fill it in with some information specifying the number of elements in the array (DW_AT_count or DW_AT_upper_bound).

The issue is reproduced with clang 3.5.0 and with 3.8.0 (trunk 256170). Gcc 4.8.4 generates correct debug info with producing a DW_AT_upper_bound containing a dwarf expression to a memory location containing the current array size.