This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Add guard to build_reconstructed_reference


Hi,

this adds a small guard to the new function build_reconstructed_reference for 
broken VIEW_CONVERT_EXPRs.  Users can easily generate these in Ada through the 
generic function Ada.Unchecked_Conversion and they need to be accepted...

Tested on x86_64-suse-linux, OK for the mainline?


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  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt81.ad[sb]: New test.

-- 
Eric Botcazou
Index: tree-sra.c
===================================================================
--- tree-sra.c	(revision 274487)
+++ tree-sra.c	(working copy)
@@ -1812,11 +1812,15 @@ build_reconstructed_reference (location_t, tree ba
   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;
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;
-- { 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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]