Add guard to build_reconstructed_reference

Message ID 1613858.L1Fq68rkEG@arcturus.home
State New
Headers show
Series
  • Add guard to build_reconstructed_reference
Related show

Commit Message

Eric Botcazou Aug. 16, 2019, 1:44 p.m.
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

Comments

Jeff Law Aug. 16, 2019, 3:46 p.m. | #1
On 8/16/19 7:44 AM, Eric Botcazou wrote:
> 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.

> 

OK
jeff
Richard Biener Aug. 16, 2019, 6:04 p.m. | #2
On August 16, 2019 3:44:36 PM GMT+02:00, Eric Botcazou <ebotcazou@adacore.com> wrote:
>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?


Ok. 

Richard. 

>

>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.

Patch

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;