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] Fix segfault in param_change_prob


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.

-- 
Eric Botcazou
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). 
-- { dg-do compile }
-- { dg-options "-O" }

with Unchecked_Conversion;
with System; use System;
with Opt58_Pkg; use Opt58_Pkg;

procedure Opt58 is

   function Convert is new Unchecked_Conversion (Integer, Rec);

   Dword : Integer := 0;
   I : Small_Int := F1 (Convert (Dword));

begin
   if F2 (Null_Address, I = 0) then
      null;
   end if;
end Opt58;
with System; use System;

package Opt58_Pkg is

   pragma Pure (Opt58_Pkg);

   type Small_Int is range 0 .. 255;

   type Rec is record
     D1, D2, D3, D4 : Small_Int;
   end record;
   pragma Pack (Rec);
   for Rec'Size use 32;

   function F1 (R : Rec) return Small_Int;

   function F2 (A : Address; B : Boolean) return Boolean;

end Opt58_Pkg;

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