On Mon, Mar 14, 2016 at 01:41:38PM -0500, Segher Boessenkool wrote:
> On Mon, Mar 14, 2016 at 06:39:12PM +0100, Bernd Schmidt wrote:
> > On 03/14/2016 04:38 PM, Segher Boessenkool wrote:
> > >If your machine description refers to a non-existent predicate genrecog
> > >crashes.  This fixes it.
> > 
> > Might be better to fix the caller?
> 
> Yeah maybe.  The next function that takes a pred also tests for !pred,
> but let me see what the caller of the failing case is.

There is just the single caller, and pred is set right before the call
there.  How about this patch, then?


Segher


Subject: [PATCH] genrecog: Fix crash on invalid input

If your machine description refers to a non-existent predicate genrecog
crashes.  This fixes it.


2016-03-14  Segher Boeesenkool  <segher#kernel.crashing.org>

        * genrecog.c (match_pattern_2): If pred is NULL don't call
        safe_predicate_mode on it.

---
 gcc/genrecog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/genrecog.c b/gcc/genrecog.c
index f8b8ef4..47e4266 100644
--- a/gcc/genrecog.c
+++ b/gcc/genrecog.c
@@ -4037,7 +4037,7 @@ match_pattern_2 (state *s, md_rtx_info *info, position 
*pos, rtx pattern)
                /* Check the mode first, to distinguish things like SImode
                   and DImode register_operands, as described above.  */
                machine_mode mode = GET_MODE (e->pattern);
-               if (safe_predicate_mode (pred, mode))
+               if (pred && safe_predicate_mode (pred, mode))
                  s = add_decision (s, rtx_test::mode (e->pos), mode, true);
 
                /* Assign to operands[] first, so that the rtx usually doesn't
-- 
1.9.3

Reply via email to