This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Ada] Spurious warning on call with out parameter in expression function
- From: Pierre-Marie de Rodat <derodat at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Ed Schonberg <schonberg at adacore dot com>
- Date: Thu, 10 Oct 2019 11:29:47 -0400
- Subject: [Ada] Spurious warning on call with out parameter in expression function
If the exprsssion in an expression function includes a function call
with an out-parameter, the corresponding assignment may be flagged as
redundant because it is analyzed twice, once in the expression function
and once in the body constructed for it.
Running this command:
gcc -c -gnatg warn.adb
On the following sources:
package Warn is
function T1 (Y : Integer; X : out Integer) return Boolean
with Import;
function T2 (X : out Integer) return Boolean is (T1 (20, X));
end Warn;
Should execute silently.
Tested on x86_64-pc-linux-gnu, committed on trunk
2019-10-10 Ed Schonberg <schonberg@adacore.com>
gcc/ada/
* sem_warn.adb (Warn_On_Useless_Assignment): Do not warn if the
second assignment is at the same source position as the first.
--- gcc/ada/sem_warn.adb
+++ gcc/ada/sem_warn.adb
@@ -4546,9 +4546,15 @@ package body Sem_Warn is
-- to capture the value. We are not going to capture any value, but
-- the warning message depends on the same kind of conditions.
+ -- If the assignment appears as an out-parameter in a call within an
+ -- expression function it may be detected twice: once when expression
+ -- itself is analyzed, and once when the constructed body is analyzed.
+ -- We don't want to emit a spurious warning in this case.
+
if Is_Assignable (Ent)
and then not Is_Return_Object (Ent)
and then Present (Last_Assignment (Ent))
+ and then Last_Assignment (Ent) /= N
and then not Is_Imported (Ent)
and then not Is_Exported (Ent)
and then Safe_To_Capture_Value (N, Ent)