diff mbox

Fix segfault in param_change_prob

Message ID 8613782.AEIKBo5lNX@arcturus.home
State New
Headers show

Commit Message

Eric Botcazou Aug. 31, 2016, 6:46 p.m. UTC
Hi,

the attached Ada testcase triggers a segfault in param_change_prob because the 
parameter is VIEW_CONVERT_EXPR<INTEGER_CST> (or <SSA_NAME) for a variant) so 
it fools the logic and walk_aliased_vdefs is called on a NULL second argument 
as the call is to a pure function.  The proposed fix is just to strip the VCE.

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


2016-08-31  Eric Botcazou  <ebotcazou@adacore.com>

	* ipa-inline-analysis.c (param_change_prob): Strip VIEW_CONVERT_EXPR.


2016-08-31  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt58.adb: New test.
	* gnat.dg/opt58_pkg.ads: New helper.

Comments

Richard Biener Sept. 1, 2016, 11:50 a.m. UTC | #1
On Wed, Aug 31, 2016 at 8:46 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> the attached Ada testcase triggers a segfault in param_change_prob because the
> parameter is VIEW_CONVERT_EXPR<INTEGER_CST> (or <SSA_NAME) for a variant) so
> it fools the logic and walk_aliased_vdefs is called on a NULL second argument
> as the call is to a pure function.  The proposed fix is just to strip the VCE.
>
> Tested on x86_64-suse-linux, OK for the mainline?

I think the fix is not enough if op is for example MEM[&"foo"] (no
V_C_E) then get_base_address
returns a STRING_CST and you run into exactly the same issue.

So I think it's better to apply get_base_address here rather than only
stripping VIEW_CONVERT_EXRPs.
(beware of it returning NULL_TREE for WITH_SIZE_EXPRs, thus maybe
strip those first as well)

You could after all have COMPONENT_REF<VIEW_CONVERT_EXPR
<INTEGER_CST>> as well ...

Richard.

>
> 2016-08-31  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * ipa-inline-analysis.c (param_change_prob): Strip VIEW_CONVERT_EXPR.
>
>
> 2016-08-31  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * gnat.dg/opt58.adb: New test.
>         * gnat.dg/opt58_pkg.ads: New helper.
>
> --
> Eric Botcazou
diff mbox

Patch

Index: ipa-inline-analysis.c
===================================================================
--- ipa-inline-analysis.c	(revision 239842)
+++ ipa-inline-analysis.c	(working copy)
@@ -2185,9 +2185,13 @@  param_change_prob (gimple *stmt, int i)
   basic_block bb = gimple_bb (stmt);
   tree base;
 
-  /* Global invariants neve change.  */
+  if (TREE_CODE (op) == VIEW_CONVERT_EXPR)
+    op = TREE_OPERAND (op, 0);
+
+  /* Global invariants never change.  */
   if (is_gimple_min_invariant (op))
     return 0;
+
   /* We would have to do non-trivial analysis to really work out what
      is the probability of value to change (i.e. when init statement
      is in a sibling loop of the call).