aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2019-07-22 13:56:31 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2019-07-22 13:56:31 +0000
commit0af66bdce078d022e19dae1c83dfa06f7f622648 (patch)
tree8ecf8d102e9fc5189e3062f60afbb9a751826811
parentc961d8205b749d6df462202efd09efa6bf01442d (diff)
downloadgcc-0af66bdce078d022e19dae1c83dfa06f7f622648.zip
gcc-0af66bdce078d022e19dae1c83dfa06f7f622648.tar.gz
gcc-0af66bdce078d022e19dae1c83dfa06f7f622648.tar.bz2
[Ada] Spurious warning about a useless assignment
This patch removes a spurious warning about a useless assignment, when a composite object is the target of an assignment and is an actual for an out parameter in a subsewuent call, and there is an intervening use of the object as the prefix of a selected component in an intervening operation. 2019-07-22 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * sem_res.adb (Resolve_Selected_Component): If the prefix has a deferred reference, generate the correct reference now, to indicate that the previous assignment is used. This prevents spurious warnings on useless assignments when compiling with all warnings enabled. when there is a subsequent call in the same stqtement list, in which the prefix of the selected component is the actual for an out parameter. gcc/testsuite/ * gnat.dg/warn22.adb: New testcase. From-SVN: r273669
-rw-r--r--gcc/ada/ChangeLog10
-rw-r--r--gcc/ada/sem_res.adb17
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gnat.dg/warn22.adb34
4 files changed, 65 insertions, 0 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 38cc4b8..c42164b 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,13 @@
+2019-07-22 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_res.adb (Resolve_Selected_Component): If the prefix has a
+ deferred reference, generate the correct reference now, to
+ indicate that the previous assignment is used. This prevents
+ spurious warnings on useless assignments when compiling with all
+ warnings enabled. when there is a subsequent call in the same
+ stqtement list, in which the prefix of the selected component is
+ the actual for an out parameter.
+
2019-07-22 Eric Botcazou <ebotcazou@adacore.com>
* exp_attr.adb (Expand_Loop_Entry_Attribute): Copy the condition
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 4ca74f8..fd4fedc 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -10625,8 +10625,25 @@ package body Sem_Res is
if Is_Access_Type (Etype (P)) then
T := Designated_Type (Etype (P));
Check_Fully_Declared_Prefix (T, P);
+
else
T := Etype (P);
+
+ -- If the prefix is an entity it may have a deferred reference set
+ -- during analysis of the selected component. After resolution we
+ -- can transform it into a proper reference. This prevents spurious
+ -- warnings on useless assignments when the same selected component
+ -- is the actual for an out parameter in a subsequent call.
+
+ if Is_Entity_Name (P)
+ and then Has_Deferred_Reference (Entity (P))
+ then
+ if May_Be_Lvalue (N) then
+ Generate_Reference (Entity (P), P, 'm');
+ else
+ Generate_Reference (Entity (P), P, 'r');
+ end if;
+ end if;
end if;
-- Set flag for expander if discriminant check required on a component
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e9c2b5e3..f8372ba 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2019-07-22 Ed Schonberg <schonberg@adacore.com>
+
+ * gnat.dg/warn22.adb: New testcase.
+
2019-07-22 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/loop_invariant1.adb, gnat.dg/loop_invariant1.ads: New
diff --git a/gcc/testsuite/gnat.dg/warn22.adb b/gcc/testsuite/gnat.dg/warn22.adb
new file mode 100644
index 0000000..0a1692f
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/warn22.adb
@@ -0,0 +1,34 @@
+-- { dg-do compile }
+-- { dg-options "-gnatwa" }
+
+with Ada.Text_IO;
+
+procedure Warn22
+is
+ type X is
+ record
+ Str : String (1 .. 3);
+ end record;
+
+ type T is
+ record
+ Value : X;
+ end record;
+
+ procedure Consume_Data (Item : out T) is
+ begin
+ Item := (Value => (Str => "Bar"));
+ end Consume_Data;
+
+ Baz : T;
+begin
+
+ Baz := (Value => (Str => "Foo"));
+
+ Ada.Text_IO.Put_Line (Baz.Value.Str);
+
+ Consume_Data (Baz);
+
+ Ada.Text_IO.Put_Line (Baz.Value.Str);
+
+end Warn22;