[Ada] Crash on an aspect specification with parameter associations
Pierre-Marie de Rodat
derodat@adacore.com
Mon Sep 25 10:08:00 GMT 2017
This patch fixes a compiler abort in ASIS mode on an aspect specification
whose expression is a function call with parameter associations.
The following must compile quietly:
gcc -c -gnatct p.adb
---
with System;
procedure P is
type T is new Integer;
package Obj is
Buf : T := 1234;
end Obj;
function Unchecked_Data_Address (Stream : T;
Current_Read_Position : Boolean := False) return System.Address;
function Unchecked_Data_Address (Stream : T;
Current_Read_Position : Boolean := False) return System.Address is
begin
return Stream'Address;
end;
Result : constant String (1 .. 10)
with Address =>
Unchecked_Data_Address (Obj.Buf, Current_Read_Position => True),
Import, Convention => Ada;
begin
null;
end;
Tested on x86_64-pc-linux-gnu, committed on trunk
2017-09-25 Ed Schonberg <schonberg@adacore.com>
* sem_ch13.adb (Analyze_One_Aspect): In ASIS mode make a full copy of
the expression to be used in the generated attribute specification
(rather than relocating it) to avoid resolving a potentially malformed
tree when the expression is resolved through an ASIS-specific call to
Resolve_Aspect_Expressions. This manifests itself as a crash on a
function with parameter associations.
-------------- next part --------------
Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb (revision 253141)
+++ sem_ch13.adb (working copy)
@@ -2264,13 +2264,29 @@
end if;
end if;
- -- Construct the attribute definition clause
+ -- Construct the attribute_definition_clause. The expression
+ -- in the aspect specification is simply shared with the
+ -- constructed attribute, because it will be fully analyzed
+ -- when the attribute is processed. However, in ASIS mode
+ -- the aspect expression itself is preanalyzed and resolved
+ -- to catch visibility errors that are otherwise caught
+ -- later, and we create a separate copy of the expression
+ -- to prevent analysis of a malformed tree (e.g. a function
+ -- call with parameter associations).
- Aitem :=
- Make_Attribute_Definition_Clause (Loc,
- Name => Ent,
- Chars => Chars (Id),
- Expression => Relocate_Node (Expr));
+ if ASIS_Mode then
+ Aitem :=
+ Make_Attribute_Definition_Clause (Loc,
+ Name => Ent,
+ Chars => Chars (Id),
+ Expression => New_Copy_Tree (Expr));
+ else
+ Aitem :=
+ Make_Attribute_Definition_Clause (Loc,
+ Name => Ent,
+ Chars => Chars (Id),
+ Expression => Relocate_Node (Expr));
+ end if;
-- If the address is specified, then we treat the entity as
-- referenced, to avoid spurious warnings. This is analogous
More information about the Gcc-patches
mailing list