diff mbox

[Ada] Error in handling of convention of formal parameter

Message ID 20160502092401.GA112785@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet May 2, 2016, 9:24 a.m. UTC
This patch fixes an error in the determination of the convention to be used for
a formal parameter, when the corresponding type carries a convention pragma.

Executing:

gcc -c p.ads -gnatRm

must yield:

Representation information for unit P (spec)

for Rec'Size use 1024;
for Rec'Alignment use 1;
for Rec use record
   I at 0 range  0 .. 1023;
end record;

for Arr'Size use 64;
for Arr'Alignment use 4;
for Arr'Component_Size use 32;

procedure proc1 declared at p.ads:11:13
  convention : Ada
  r : passed by copy
  i : passed by copy

procedure proc2 declared at p.ads:12:13
  convention : Ada
  a : passed by reference
  i : passed by copy

---
package P is

  type Rec is record
    I : String (1 .. 128);
  end record;
  pragma Convention (Ada_Pass_By_Copy, Rec);

  type Arr is array (1 .. 2) of Integer;
  pragma Convention (Ada_Pass_By_Reference, Arr);

  procedure Proc1 (R : Rec; I : Integer) is null;
  procedure Proc2 (A : Arr; I : Integer) is null;

end P;

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

2016-05-02  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch6.adb (Process_Formals): Check properly the type of a
	formal to determine whether a given convention applies to it.
diff mbox

Patch

Index: sem_ch6.adb
===================================================================
--- sem_ch6.adb	(revision 235706)
+++ sem_ch6.adb	(working copy)
@@ -10792,24 +10792,28 @@ 
 
          --  Force call by reference if aliased
 
-         if Is_Aliased (Formal) then
-            Set_Mechanism (Formal, By_Reference);
+         declare
+            Conv : constant Convention_Id := Convention (Etype (Formal));
+         begin
+            if Is_Aliased (Formal) then
+               Set_Mechanism (Formal, By_Reference);
 
-            --  Warn if user asked this to be passed by copy
+               --  Warn if user asked this to be passed by copy
 
-            if Convention (Formal_Type) = Convention_Ada_Pass_By_Copy then
-               Error_Msg_N
-                 ("cannot pass aliased parameter & by copy??", Formal);
-            end if;
+               if Conv = Convention_Ada_Pass_By_Copy then
+                  Error_Msg_N
+                    ("cannot pass aliased parameter & by copy??", Formal);
+               end if;
 
-         --  Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
+            --  Force mechanism if type has Convention Ada_Pass_By_Ref/Copy
 
-         elsif Convention (Formal_Type) = Convention_Ada_Pass_By_Copy then
-            Set_Mechanism (Formal, By_Copy);
+            elsif Conv = Convention_Ada_Pass_By_Copy then
+               Set_Mechanism (Formal, By_Copy);
 
-         elsif Convention (Formal_Type) = Convention_Ada_Pass_By_Reference then
-            Set_Mechanism (Formal, By_Reference);
-         end if;
+            elsif Conv = Convention_Ada_Pass_By_Reference then
+               Set_Mechanism (Formal, By_Reference);
+            end if;
+         end;
 
       <<Next_Parameter>>
          Next (Param_Spec);