aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Dewar <dewar@adacore.com>2014-02-18 11:52:58 +0000
committerArnaud Charlet <charlet@gcc.gnu.org>2014-02-18 12:52:58 +0100
commit365c849669a60a5b940ff12df8dcb7ac2868d921 (patch)
treea937c244223d54363a5eb3caa31abe41c55442f9
parent20afe6403b216d1f0a2cc9e119efbac514acb533 (diff)
downloadgcc-365c849669a60a5b940ff12df8dcb7ac2868d921.zip
gcc-365c849669a60a5b940ff12df8dcb7ac2868d921.tar.gz
gcc-365c849669a60a5b940ff12df8dcb7ac2868d921.tar.bz2
exp_attr.adb: Minor reformatting.
2014-02-18 Robert Dewar <dewar@adacore.com> * exp_attr.adb: Minor reformatting. * exp_ch4.ads, exp_ch4.adb (Expand_N_Reference): New procedure. * exp_util.adb (Remove_Side_Effects): Add conditional expressions as another case where we don't generate N_Reference nodes for primitive types. * expander.adb (Expand): Add call to Expand_N_Reference. From-SVN: r207841
-rw-r--r--gcc/ada/ChangeLog9
-rw-r--r--gcc/ada/exp_attr.adb16
-rw-r--r--gcc/ada/exp_ch4.adb59
-rw-r--r--gcc/ada/exp_ch4.ads3
-rw-r--r--gcc/ada/exp_util.adb26
-rw-r--r--gcc/ada/expander.adb3
6 files changed, 100 insertions, 16 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index d9ca753..4f710514 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,12 @@
+2014-02-18 Robert Dewar <dewar@adacore.com>
+
+ * exp_attr.adb: Minor reformatting.
+ * exp_ch4.ads, exp_ch4.adb (Expand_N_Reference): New procedure.
+ * exp_util.adb (Remove_Side_Effects): Add conditional expressions
+ as another case where we don't generate N_Reference nodes for
+ primitive types.
+ * expander.adb (Expand): Add call to Expand_N_Reference.
+
2014-02-06 Hristian Kirtchev <kirtchev@adacore.com>
* sem_prag.adb (Analyze_Refined_Pragma): Remove
diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb
index c54fb78..7a55d8b 100644
--- a/gcc/ada/exp_attr.adb
+++ b/gcc/ada/exp_attr.adb
@@ -1132,20 +1132,20 @@ package body Exp_Attr is
-- copies from being created when the unchecked conversion
-- is expanded (which would happen in Remove_Side_Effects
-- if Expand_N_Unchecked_Conversion were allowed to call
- -- Force_Evaluation). The copy could violate Ada semantics
- -- in cases such as an actual that is an out parameter.
- -- Note that this approach is also used in exp_ch7 for calls
- -- to controlled type operations to prevent problems with
- -- actuals wrapped in unchecked conversions.
+ -- Force_Evaluation). The copy could violate Ada semantics in
+ -- cases such as an actual that is an out parameter. Note that
+ -- this approach is also used in exp_ch7 for calls to controlled
+ -- type operations to prevent problems with actuals wrapped in
+ -- unchecked conversions.
if Is_Untagged_Derivation (Etype (Expression (Item))) then
Set_Assignment_OK (Item);
end if;
end if;
- -- The stream operation to call maybe a renaming created by
- -- an attribute definition clause, and may not be frozen yet.
- -- Ensure that it has the necessary extra formals.
+ -- The stream operation to call may be a renaming created by an
+ -- attribute definition clause, and may not be frozen yet. Ensure
+ -- that it has the necessary extra formals.
if not Is_Frozen (Pname) then
Create_Extra_Formals (Pname);
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index ec9febf..30951ed 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -9225,6 +9225,65 @@ package body Exp_Ch4 is
Analyze_And_Resolve (N, Standard_Boolean);
end Expand_N_Quantified_Expression;
+ ------------------------
+ -- Expand_N_Reference --
+ ------------------------
+
+ -- It is a little unclear why we generate references to expression values,
+ -- but we definitely do! At the very least in Modify_Tree_For_C, we need to
+ -- get rid of such constructs. We do this by expanding:
+
+ -- expression'Reference
+
+ -- into
+
+ -- Tnn : constant typ := expression;
+ -- ...
+ -- Tnn'Reference
+
+ procedure Expand_N_Reference (N : Node_Id) is
+ begin
+ -- No problem if Modify_Tree_For_C not set, the existing back ends will
+ -- correctly handle P'Reference where P is a general expression.
+
+ if not Modify_Tree_For_C then
+ return;
+
+ -- No problem if we have an entity name since we can take its address
+
+ elsif Is_Entity_Name (Prefix (N)) then
+ return;
+
+ -- Can't go copying limited types
+
+ elsif Is_Limited_Record (Etype (Prefix (N)))
+ or else Is_Limited_Composite (Etype (Prefix (N)))
+ then
+ return;
+
+ -- Here is the case where we do the transformation discussed above
+
+ else
+ declare
+ Loc : constant Source_Ptr := Sloc (N);
+ Expr : constant Node_Id := Prefix (N);
+ Typ : constant Entity_Id := Etype (N);
+ Tnn : constant Entity_Id := Make_Temporary (Loc, 'T', Expr);
+ begin
+ Insert_Action (N,
+ Make_Object_Declaration (Loc,
+ Defining_Identifier => Tnn,
+ Constant_Present => True,
+ Object_Definition => New_Occurrence_Of (Etype (Expr), Loc),
+ Expression => Expr));
+ Rewrite (N,
+ Make_Reference (Loc,
+ Prefix => New_Occurrence_Of (Tnn, Loc)));
+ Analyze_And_Resolve (N, Typ);
+ end;
+ end if;
+ end Expand_N_Reference;
+
---------------------------------
-- Expand_N_Selected_Component --
---------------------------------
diff --git a/gcc/ada/exp_ch4.ads b/gcc/ada/exp_ch4.ads
index 277a755..99ed861 100644
--- a/gcc/ada/exp_ch4.ads
+++ b/gcc/ada/exp_ch4.ads
@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
--- Copyright (C) 1992-2012, Free Software Foundation, Inc. --
+-- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
@@ -68,6 +68,7 @@ package Exp_Ch4 is
procedure Expand_N_Or_Else (N : Node_Id);
procedure Expand_N_Qualified_Expression (N : Node_Id);
procedure Expand_N_Quantified_Expression (N : Node_Id);
+ procedure Expand_N_Reference (N : Node_Id);
procedure Expand_N_Selected_Component (N : Node_Id);
procedure Expand_N_Slice (N : Node_Id);
procedure Expand_N_Type_Conversion (N : Node_Id);
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index dd5766b..cea3dab 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -6972,17 +6972,28 @@ package body Exp_Util is
Scope_Suppress.Suppress := (others => True);
-- If it is a scalar type and we need to capture the value, just make
- -- a copy. Likewise for a function call, an attribute reference, an
- -- allocator, or an operator. And if we have a volatile reference and
- -- Name_Req is not set (see comments above for Side_Effect_Free).
+ -- a copy. Likewise for a function call, an attribute reference, a
+ -- conditional expression, an allocator, or an operator. And if we have
+ -- a volatile reference and Name_Req is not set (see comments above for
+ -- Side_Effect_Free).
if Is_Elementary_Type (Exp_Type)
+
+ -- Note: this test is rather mysterious??? Why can't we just test ONLY
+ -- Is_Elementary_Type and be done with it. If we try that approach, we
+ -- get some failures (infinite recursions) from the Duplicate_Subexpr
+ -- call at the end of Checks.Apply_Predicate_Check. To be
+ -- investigated ???
+
and then (Variable_Ref
- or else Nkind_In (Exp, N_Function_Call,
- N_Attribute_Reference,
- N_Allocator)
+ or else Nkind_In (Exp, N_Attribute_Reference,
+ N_Allocator,
+ N_Case_Expression,
+ N_If_Expression,
+ N_Function_Call)
or else Nkind (Exp) in N_Op
- or else (not Name_Req and then Is_Volatile_Reference (Exp)))
+ or else (not Name_Req
+ and then Is_Volatile_Reference (Exp)))
then
Def_Id := Make_Temporary (Loc, 'R', Exp);
Set_Etype (Def_Id, Exp_Type);
@@ -7230,6 +7241,7 @@ package body Exp_Util is
E := Exp;
if Nkind (E) = N_Explicit_Dereference then
New_Exp := Relocate_Node (Prefix (E));
+
else
E := Relocate_Node (E);
diff --git a/gcc/ada/expander.adb b/gcc/ada/expander.adb
index 9f57cda..2afa4b5 100644
--- a/gcc/ada/expander.adb
+++ b/gcc/ada/expander.adb
@@ -411,6 +411,9 @@ package body Expander is
when N_Record_Representation_Clause =>
Expand_N_Record_Representation_Clause (N);
+ when N_Reference =>
+ Expand_N_Reference (N);
+
when N_Requeue_Statement =>
Expand_N_Requeue_Statement (N);