Patchwork [Ada] Warning on self-assignment to formal

login
register
mail settings
Submitter Arnaud Charlet
Date Sept. 9, 2010, 10:16 a.m.
Message ID <20100909101608.GA20109@adacore.com>
Download mbox | patch
Permalink /patch/64276/
State New
Headers show

Comments

Arnaud Charlet - Sept. 9, 2010, 10:16 a.m.
The compiler failed to warn on a useless self-assignment when the entity was
an in-out parameter. because the predicate Same_Object.ignored formals.

The following must generate the warning:
proc.adb:5:09: warning: useless assignment of "X" to itself

gcc -c -gnatwr proc.adb

---
procedure Proc (X : in out Integer) is
begin
   X := 15;
   if X > 0 then
      X := X;
   end if;
end;

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-09-09  Ed Schonberg  <schonberg@adacore.com>

	* sem_util.adb (Same_Object): include formal parameters.

Patch

Index: sem_util.adb
===================================================================
--- sem_util.adb	(revision 164000)
+++ sem_util.adb	(working copy)
@@ -10538,7 +10538,9 @@  package body Sem_Util is
         and then Present (Entity (N2))
         and then (Ekind (Entity (N1)) = E_Variable
                     or else
-                  Ekind (Entity (N1)) = E_Constant)
+                    Ekind (Entity (N1)) = E_Constant
+                    or else
+                    Ekind (Entity (N1)) in Formal_Kind)
         and then Entity (N1) = Entity (N2)
       then
          return True;