public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fix internal error on packed array In/Out actual parameter
@ 2019-07-05  7:08 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-07-05  7:08 UTC (permalink / raw)
  To: gcc-patches; +Cc: Eric Botcazou

[-- Attachment #1: Type: text/plain, Size: 671 bytes --]

This fixes an issue introduced in Ada 2012 for calls to functions taking
an In/Out parameter and for which the actual is the component of a
packed array.  In this case, the front-end needs to create a temporary
for the actual, initialize it before the call and assign it back after
it, because operations on bit-packed arrays are converted into
mask-and-shift sequences.

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

2019-07-05  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* exp_ch4.adb (Expand_N_Indexed_Component): Do not expand actual
	parameters of function calls here either.

gcc/testsuite/

	* gnat.dg/pack23.adb, gnat.dg/pack23_pkg.ads: New testcase.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1701 bytes --]

--- gcc/ada/exp_ch4.adb
+++ gcc/ada/exp_ch4.adb
@@ -6762,7 +6762,7 @@ package body Exp_Ch4 is
       --    Renaming objects in renaming associations
       --      This case is handled when a use of the renamed variable occurs
 
-      --    Actual parameters for a procedure call
+      --    Actual parameters for a subprogram call
       --      This case is handled in Exp_Ch6.Expand_Actuals
 
       --    The second expression in a 'Read attribute reference
@@ -6783,11 +6783,12 @@ package body Exp_Ch4 is
             if Nkind (Parnt) = N_Unchecked_Expression then
                null;
 
-            elsif Nkind_In (Parnt, N_Object_Renaming_Declaration,
-                                   N_Procedure_Call_Statement)
+            elsif Nkind (Parnt) = N_Object_Renaming_Declaration then
+               return;
+
+            elsif Nkind (Parnt) in N_Subprogram_Call
               or else (Nkind (Parnt) = N_Parameter_Association
-                        and then
-                          Nkind (Parent (Parnt)) = N_Procedure_Call_Statement)
+                        and then Nkind (Parent (Parnt)) in N_Subprogram_Call)
             then
                return;
 

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/pack23.adb
@@ -0,0 +1,14 @@
+--  { dg-do compile }
+--  { dg-options "-gnatws" }
+
+with Pack23_Pkg;
+
+function Pack23 return Integer is
+
+  type Arr is array (1 .. 32) of Boolean with Size => 32, Pack;
+
+  A : Arr;
+
+begin
+  return Pack23_Pkg.Func (A (1));
+end;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/pack23_pkg.ads
@@ -0,0 +1,5 @@
+package Pack23_Pkg is
+
+  function Func (B : in out Boolean) return Integer;
+
+end Pack23_Pkg;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-05  7:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-05  7:08 [Ada] Fix internal error on packed array In/Out actual parameter Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).