OSDN Git Service

* gcc-interface/decl.c (maybe_pad_type): Do not try to change the form
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 11 Sep 2011 18:56:40 +0000 (18:56 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 11 Sep 2011 18:56:40 +0000 (18:56 +0000)
of an addressable type.
* gcc-interface/trans.c (gnat_gimplify_expr) <VIEW_CONVERT_EXPR>: New.
Deal with those cases for which creating a temporary is mandatory.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@178764 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 781f4b4..d909529 100644 (file)
@@ -1,5 +1,12 @@
 2011-09-11  Eric Botcazou  <ebotcazou@adacore.com>
 
+       * gcc-interface/decl.c (maybe_pad_type): Do not try to change the form
+       of an addressable type.
+       * gcc-interface/trans.c (gnat_gimplify_expr) <VIEW_CONVERT_EXPR>: New.
+       Deal with those cases for which creating a temporary is mandatory.
+
+2011-09-11  Eric Botcazou  <ebotcazou@adacore.com>
+
        * gcc-interface/trans.c (call_to_gnu): Use local variable.  Make sure
        this is a real formal parameter before testing whether it is by ref.
 
index 539c262..0854d5d 100644 (file)
@@ -6521,6 +6521,7 @@ maybe_pad_type (tree type, tree size, unsigned int align,
   if (align != 0
       && TREE_CODE (type) == RECORD_TYPE
       && TYPE_MODE (type) == BLKmode
+      && !TREE_ADDRESSABLE (type)
       && TREE_CODE (orig_size) == INTEGER_CST
       && !TREE_OVERFLOW (orig_size)
       && compare_tree_int (orig_size, MAX_FIXED_MODE_SIZE) <= 0
index fdc8acb..27e2402 100644 (file)
@@ -6446,6 +6446,28 @@ gnat_gimplify_expr (tree *expr_p, gimple_seq *pre_p,
 
       return GS_UNHANDLED;
 
+    case VIEW_CONVERT_EXPR:
+      op = TREE_OPERAND (expr, 0);
+
+      /* If we are view-converting a CONSTRUCTOR or a call from an aggregate
+        type to a scalar one, explicitly create the local temporary.  That's
+        required if the type is passed by reference.  */
+      if ((TREE_CODE (op) == CONSTRUCTOR || TREE_CODE (op) == CALL_EXPR)
+         && AGGREGATE_TYPE_P (TREE_TYPE (op))
+         && !AGGREGATE_TYPE_P (TREE_TYPE (expr)))
+       {
+         tree mod, new_var = create_tmp_var_raw (TREE_TYPE (op), "C");
+         gimple_add_tmp_var (new_var);
+
+         mod = build2 (INIT_EXPR, TREE_TYPE (new_var), new_var, op);
+         gimplify_and_add (mod, pre_p);
+
+         TREE_OPERAND (expr, 0) = new_var;
+         return GS_OK;
+       }
+
+      return GS_UNHANDLED;
+
     case DECL_EXPR:
       op = DECL_EXPR_DECL (expr);
 
index 0329dd0..1a298b1 100644 (file)
@@ -1,3 +1,7 @@
+2011-09-11  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/atomic5.ad[sb]: New test.
+
 2011-09-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        * gcc.dg/sibcall-6.c: Check ia32 instead of ilp32.
diff --git a/gcc/testsuite/gnat.dg/atomic5.adb b/gcc/testsuite/gnat.dg/atomic5.adb
new file mode 100644 (file)
index 0000000..efbed4e
--- /dev/null
@@ -0,0 +1,20 @@
+package body Atomic5 is
+
+  function Create return R is
+  begin
+    return (A => 0, B => 1, C => 2, D => 4);
+  end;
+
+  procedure Proc1 is
+    I : Unsigned_32;
+  begin
+    I := Conv(Create);
+  end;
+
+  procedure Proc2 is
+    I : Unsigned_32;
+  begin
+    I := Conv(R'(A => 0, B => 1, C => 2, D => 4));
+  end;
+
+end Atomic5;
diff --git a/gcc/testsuite/gnat.dg/atomic5.ads b/gcc/testsuite/gnat.dg/atomic5.ads
new file mode 100644 (file)
index 0000000..3f653fa
--- /dev/null
@@ -0,0 +1,25 @@
+-- { dg-do compile }
+
+with Unchecked_Conversion;
+
+package Atomic5 is
+
+  type Byte is mod 2 ** 8;
+  for Byte'Size use 8;
+
+  type Unsigned_32 is mod 2 ** 32;
+  for Unsigned_32'Size use 32;
+
+  type R is record
+    A,B,C,D : Byte;
+  end record;
+  for R'Alignment use 4;
+  pragma Atomic (R);
+
+  function Conv is new Unchecked_Conversion (R, Unsigned_32);
+
+  procedure Proc1;
+
+  procedure Proc2;
+
+end Atomic5;