tree-sra.c (build_reconstructed_reference): Return NULL_TREE instead of NULL.
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 16 Aug 2019 16:00:25 +0000 (16:00 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 16 Aug 2019 16:00:25 +0000 (16:00 +0000)
* tree-sra.c (build_reconstructed_reference): Return NULL_TREE instead
of NULL.  Add guard for broken VIEW_CONVERT_EXPRs.

From-SVN: r274576

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/opt81.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/opt81.ads [new file with mode: 0644]
gcc/tree-sra.c

index b5badf3ff1e5952c4446f5377f38104a0dcdc609..e14ab3d7c912f47a90bcb2e62aa5de54bc7f4814 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-16  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * tree-sra.c (build_reconstructed_reference): Return NULL_TREE instead
+       of NULL.  Add guard for broken VIEW_CONVERT_EXPRs.
+
 2019-08-16  Martin Sebor  <msebor@redhat.com>
 
        * tree.def (TYPE_SIZE): Clarify.
index 9f00d1ceab72a655c1fc9e827b921ad2519642f8..9b7eff988119ed5d1d703f0cd91e1605ced176c3 100644 (file)
@@ -1,3 +1,7 @@
+2019-08-16  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/opt81.ad[sb]: New test.
+
 2019-08-16  Martin Sebor  <msebor@redhat.com>
 
        PR testsuite/91458
diff --git a/gcc/testsuite/gnat.dg/opt81.adb b/gcc/testsuite/gnat.dg/opt81.adb
new file mode 100644 (file)
index 0000000..057d846
--- /dev/null
@@ -0,0 +1,20 @@
+-- { dg-do compile }
+-- { dg-options "-O -gnatws" }
+
+with Unchecked_Conversion;
+
+package body Opt81 is
+
+  procedure Copy (From, To : Rec) is
+    Len : constant Natural := From.A.all'Length;
+    subtype Fixed_String is String (1 .. Len);
+    type Fixed_String_Access is access Fixed_String;
+    function To_Fixed is new
+      Unchecked_Conversion (Source => String_Access,
+                            Target => Fixed_String_Access);
+    S : Fixed_String_Access := To_Fixed (To.A);
+  begin
+    S (1 .. Len) := From.A.all;
+  end;
+
+end Opt81;
diff --git a/gcc/testsuite/gnat.dg/opt81.ads b/gcc/testsuite/gnat.dg/opt81.ads
new file mode 100644 (file)
index 0000000..743dcc2
--- /dev/null
@@ -0,0 +1,15 @@
+package Opt81 is
+
+  type String_Access is access String;
+
+  type Rec is record
+    A : String_Access;
+  end record;
+
+  for Rec use record
+    A at 0 range 0 .. (Standard'Word_Size - 1);
+  end record;
+
+  procedure Copy(From, To : Rec);
+
+end Opt81;
index 03c1a2ae9e91669bea57233597c374f8e8ff55af..1505ce57d309c5d9aa7f8826db157ef2c66a83e0 100644 (file)
@@ -1812,11 +1812,15 @@ build_reconstructed_reference (location_t, tree base, struct access *model)
   while (!types_compatible_p (TREE_TYPE (expr), TREE_TYPE (base)))
     {
       if (!handled_component_p (expr))
-       return NULL;
+       return NULL_TREE;
       prev_expr = expr;
       expr = TREE_OPERAND (expr, 0);
     }
 
+  /* Guard against broken VIEW_CONVERT_EXPRs...  */
+  if (!prev_expr)
+    return NULL_TREE;
+
   TREE_OPERAND (prev_expr, 0) = base;
   tree ref = unshare_expr (model->expr);
   TREE_OPERAND (prev_expr, 0) = expr;