[debug] Fix handling of vlas in lto
Atm, when running vla-1.c with -O0 -flto, we have:
...
FAIL: gcc.dg/guality/vla-1.c -O0 -flto -fuse-linker-plugin \
-fno-fat-lto-objects line 17 sizeof (a) == 6
...
The vla a[i + 1] in f1 is gimplified into:
...
f1 (int i)
{
char a[0:D.1922] [value-expr: *a.0];
char[0:D.1922] * a.0;
D.1921 = i + 1;
D.1926 = (sizetype) D.1921;
a.0 = __builtin_alloca_with_align (D.1926, 8);
...
The early debug info for the upper bound of the type of vla a that we stream
out is:
...
DIE 0: DW_TAG_subrange_type (0x7f85029a90f0)
DW_AT_upper_bound: location descriptor:
(0x7f85029a9230) DW_OP_GNU_variable_value die -> 0 (0x7f85029a94b0), 0
DIE 0: DW_TAG_variable (0x7f85029a94b0)
DW_AT_name: "D.1922"
DW_AT_type: die -> 0 (0x7f85029a3d70)
DW_AT_artificial: 1
...
and in ltrans we have for that same upper bound:
...
DIE 0: DW_TAG_subrange_type (0x7f5183b57d70)
DW_AT_upper_bound: die -> 0 (0x7f5183b576e0)
DIE 0: DW_TAG_variable (0x7f5183b576e0)
DW_AT_name: "D.4278"
DW_AT_abstract_origin: die -> label: vla_1.c.
6719312a + 193 (0x7f5183b57730)
...
where D.4278 has abstract origin D.1922.
The D.4278 die has no DW_AT_location, so when evaluting "sizeof (a)" in the
debugger, we can't find the information to get the value of D.4278, and the
debugger prints "<optimized out>".
This patch fixes that by either:
- adding DW_AT_location to the referenced variable die, or
- instead of using a ref for the upper bound, using an exprloc.
When changing gcc.dg/guality/guality.exp to run the usual flto flavours
"-fno-use-linker-plugin -flto-partition=none" and "-fuse-linker-plugin
-fno-fat-lto-objects" in combination with O0, Og, O1, O2, O3 and Os, this patch
fixes all (20) failures in vla-1.c, leaving only:
...
No symbol "i" in current context.
UNSUPPORTED: gcc.dg/guality/vla-1.c -O3 -flto -fno-use-linker-plugin \
-flto-partition=none line 17 i == 5
'a' has unknown type; cast it to its declared type
UNSUPPORTED: gcc.dg/guality/vla-1.c -O3 -flto -fno-use-linker-plugin \
-flto-partition=none line 17 sizeof (a) == 6
...
Bootstrapped and reg-tested on x86_64.
2018-08-20 Tom de Vries <tdevries@suse.de>
* dwarf2out.c (add_scalar_info): Don't add reference to existing die
unless the referenced die describes the added property using
DW_AT_location or DW_AT_const_value. Fall back to exprloc case.
Otherwise, add a DW_AT_location to the referenced die.
From-SVN: r263660