On 01/18/2016 12:18 PM, Richard Biener wrote:
Looking for TYPE_DECL_IS_STUB uses I come along dwarf2out_ignore_block
which you'd need to change as well I think.
That is true, thank you!
First, I’ll answer your last point:
Btw, not sure how you get at the "wrong" debug info gen order, I
can't seem to get at it with a C testcase.
As with the other patch this misses a testcase.
That’s true, sorry for that. I could not yield a C reproducer neither,
so here’s my original Ada testcase: I will include it in the next patch
under gnat.dg.
So the problem I’m trying to address is the following: Record_Type is
declared in Debug5, and it is referenced by the R parameter in
Debug5.Process (so far, so good). Now, because debug info for
Debug5.Process is emitted before the one for Debug5, Record_Type is
emitted in the global scope and is not relocated under Debug5 afterwards.
- else if (TREE_CODE (decl_or_origin) == TYPE_DECL
- && TYPE_DECL_IS_STUB (decl_or_origin))
+ else if (TREE_CODE (decl_or_origin) == TYPE_DECL)
die = lookup_type_die (TREE_TYPE (decl_or_origin));
But ... I think this change is wrong. It is supposed to use the _type_ DIE
in case the FE didn't create a proper TYPE_DECL. So I think what is
maybe missing is
else if (TREE_CODE (decl_or_origin) == TYPE_DECL)
die = lookup_decl_die (decl_or_origin);
? That is, why should we lookup the type if the type-decl isn't a stub?
While I agree that for non-stub TYPE_DECL, it is sound to look for the
decl itself rather than the type, this does not fix the bug I intended
to fix. Indeed, when we reach this point for the TYPE_DECL corresponding
to Record_Type, add_type_attribute just creates a DW_TAG_typedef for it,
and the call it does to modified_type just returns the existing
DW_TAG_record_type (still in the global scope).
So assuming your proposal of the change is correct, should we then use
TYPE_CONTEXT in order to (potentially) relocate TREE_TYPE (decl) in
add_type_attribute?
--
Pierre-Marie de Rodat
-- The aim of this test is to check that Ada types appear in the proper
-- context in the debug info.
--
-- Checking this directly would be really tedious just scanning for assembly
-- lines, so instead we rely on DWARFv4's .debug_types sections, which must be
-- created only for global-scope types. Checking the number of .debug_types is
-- some hackish way to check that types are output in the proper context (i.e.
-- at global or local scope).
--
-- { dg-options "-g -gdwarf-4 -cargs -fdebug-types-section -dA" }
-- { dg-final { scan-assembler-times "\\(DIE \\(0x\[a-f0-9\]*\\) DW_TAG_type_unit\\)" 0 } }
procedure Debug5 is
type Array_Type is array (Natural range <>) of Integer;
type Record_Type (L1, L2 : Natural) is record
I1 : Integer;
A1 : Array_Type (1 .. L1);
I2 : Integer;
A2 : Array_Type (1 .. L2);
I3 : Integer;
end record;
function Get (L1, L2 : Natural) return Record_Type is
Result : Record_Type (L1, L2);
begin
Result.I1 := 1;
for I in Result.A1'Range loop
Result.A1 (I) := I;
end loop;
Result.I2 := 2;
for I in Result.A2'Range loop
Result.A2 (I) := I;
end loop;
Result.I3 := 3;
return Result;
end Get;
R1 : Record_Type := Get (0, 0);
R2 : Record_Type := Get (1, 0);
R3 : Record_Type := Get (0, 1);
R4 : Record_Type := Get (2, 2);
procedure Process (R : Record_Type) is
begin
null;
end Process;
begin
Process (R1);
Process (R2);
Process (R3);
Process (R4);
end Debug5;