* [Ada] Spurious errors with complex slice expression
@ 2011-08-02 15:17 Arnaud Charlet
0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2011-08-02 15:17 UTC (permalink / raw)
To: gcc-patches; +Cc: Ed Schonberg
[-- Attachment #1: Type: text/plain, Size: 1588 bytes --]
A tree node must never be analyzed if it is not attached to the tree for the
current compilation, because the parent link is used for numerous semantic
checks and code insertions. This patch fixes a violation of this rule in the
analysis of array aggregates, where expressions in component associations are
copied to be perfom some semantic checks before being fully analyzed.
A common use of the parent field is the determination of the proper point of
insertion for generated code, in Insert_Actions. In this case, Insert_Actions
was being called to create a reference for an itype, for use by the back-end.
Such a reference is not needed if expansion is currently disabled.
The following must compile quietly:
function To_String(Item : in String) return String is
begin
if Item'length <= 1 then
return Item;
end if;
if Item(Item'first) = '<' and then Item(Item'last) = '>' then
if Item'length = 2 then
return "";
end if;
return String'
(1 .. 1 =>
Character'val
(Integer'value
(Item(Item'first + 1 .. Item'last - 1))));
end if;
return String'(1 .. 1 => Character'value(Item));
end To_String;
Tested on x86_64-pc-linux-gnu, committed on trunk
2011-08-02 Ed Schonberg <schonberg@adacore.com>
* sem_aggr.adb (Resolve_Array_Aggregate): when copying the expression
in an association, set parent field of copy before partial analysis.
* sem_res.adb (Resolve_Slice): create reference to itype only when
expansion is enabled.
[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1410 bytes --]
Index: sem_aggr.adb
===================================================================
--- sem_aggr.adb (revision 177175)
+++ sem_aggr.adb (working copy)
@@ -1974,6 +1974,11 @@
begin
Expander_Mode_Save_And_Set (False);
Full_Analysis := False;
+
+ -- Analyze the expression, making sure it is properly
+ -- attached to the tree before we do the analysis.
+
+ Set_Parent (Expr, Parent (Expression (Assoc)));
Analyze (Expr);
-- If the expression is a literal, propagate this info
Index: sem_res.adb
===================================================================
--- sem_res.adb (revision 177177)
+++ sem_res.adb (working copy)
@@ -9817,9 +9817,10 @@
-- so that the itype is frozen at the proper place in the tree (i.e. at
-- the point where actions for the slice are analyzed). Note that this
-- is different from freezing the itype immediately, which might be
- -- premature (e.g. if the slice is within a transient scope).
+ -- premature (e.g. if the slice is within a transient scope). This needs
+ -- to be done only if expansion is enabled.
- else
+ elsif Expander_Active then
Ensure_Defined (Typ => Slice_Subtype, N => N);
end if;
end Set_Slice_Subtype;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-08-02 15:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-02 15:17 [Ada] Spurious errors with complex slice expression Arnaud Charlet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).