trans.c (Call_to_gnu): Deal with specific conditional expressions for misaligned...
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 13 Aug 2013 17:13:47 +0000 (17:13 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 13 Aug 2013 17:13:47 +0000 (17:13 +0000)
* gcc-interface/trans.c (Call_to_gnu): Deal with specific conditional
expressions for misaligned actual parameters.

From-SVN: r201700

gcc/ada/ChangeLog
gcc/ada/gcc-interface/trans.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/valued_proc.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/valued_proc_pkg.ads [new file with mode: 0644]

index e1f7363..5db69aa 100644 (file)
@@ -1,5 +1,10 @@
 2013-08-13  Eric Botcazou  <ebotcazou@adacore.com>
 
+       * gcc-interface/trans.c (Call_to_gnu): Deal with specific conditional
+       expressions for misaligned actual parameters.
+
+2013-08-13  Eric Botcazou  <ebotcazou@adacore.com>
+
        * gcc-interface/trans.c (can_equal_min_or_max_val_p): Be prepared for
        values outside of the range of the type.
 
index fdd59a8..5c1038a 100644 (file)
@@ -4022,9 +4022,19 @@ Call_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, tree gnu_target,
          /* Set up to move the copy back to the original if needed.  */
          if (!in_param)
            {
-             gnu_stmt = build_binary_op (MODIFY_EXPR, NULL_TREE, gnu_orig,
-                                         gnu_temp);
+             /* If the original is a COND_EXPR whose first arm isn't meant to
+                be further used, just deal with the second arm.  This is very
+                likely the conditional expression built for a check.  */
+             if (TREE_CODE (gnu_orig) == COND_EXPR
+                 && TREE_CODE (TREE_OPERAND (gnu_orig, 1)) == COMPOUND_EXPR
+                 && integer_zerop
+                    (TREE_OPERAND (TREE_OPERAND (gnu_orig, 1), 1)))
+               gnu_orig = TREE_OPERAND (gnu_orig, 2);
+
+             gnu_stmt
+               = build_binary_op (MODIFY_EXPR, NULL_TREE, gnu_orig, gnu_temp);
              set_expr_location_from_node (gnu_stmt, gnat_node);
+
              append_to_statement_list (gnu_stmt, &gnu_after_list);
            }
        }
index f962249..d1079e6 100644 (file)
@@ -1,3 +1,8 @@
+2013-08-13  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/valued_proc.adb: New test.
+       * gnat.dg/valued_proc_pkg.ads: New helper.
+
 2013-08-13  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/57661
diff --git a/gcc/testsuite/gnat.dg/valued_proc.adb b/gcc/testsuite/gnat.dg/valued_proc.adb
new file mode 100644 (file)
index 0000000..7030b43
--- /dev/null
@@ -0,0 +1,12 @@
+-- { dg-do compile }
+-- { dg-options "-gnatdm -gnatws" }
+
+with Valued_Proc_Pkg; use Valued_Proc_Pkg;
+with System; use System;
+
+procedure Valued_Proc is
+   Status : UNSIGNED_LONGWORD;
+   Length : POSITIVE;
+begin
+   GetMsg (Status, UNSIGNED_WORD(Length));
+end;
diff --git a/gcc/testsuite/gnat.dg/valued_proc_pkg.ads b/gcc/testsuite/gnat.dg/valued_proc_pkg.ads
new file mode 100644 (file)
index 0000000..d5197ab
--- /dev/null
@@ -0,0 +1,15 @@
+pragma Extend_System (Aux_DEC);
+with System; use System;
+
+package Valued_Proc_Pkg is
+
+    procedure GETMSG (STATUS : out UNSIGNED_LONGWORD;
+                      MSGLEN : out UNSIGNED_WORD);
+
+    pragma Interface (EXTERNAL, GETMSG);
+
+    pragma IMPORT_VALUED_PROCEDURE (GETMSG, "SYS$GETMSG",
+                                    (UNSIGNED_LONGWORD, UNSIGNED_WORD),
+                                    (VALUE, REFERENCE));
+
+end Valued_Proc_Pkg;