public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] genrecog: Fix crash on invalid input
@ 2016-03-14 15:39 Segher Boessenkool
  2016-03-14 17:39 ` Bernd Schmidt
  0 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2016-03-14 15:39 UTC (permalink / raw)
  To: gcc-patches; +Cc: rdsandiford, Segher Boessenkool

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

Is this okay for trunk?


Segher


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

	* genrecog.c (safe_predicate_mode): If PRED is NULL, return false.

---
 gcc/genrecog.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/gcc/genrecog.c b/gcc/genrecog.c
index f8b8ef4..65882f4 100644
--- a/gcc/genrecog.c
+++ b/gcc/genrecog.c
@@ -3378,6 +3378,9 @@ find_subroutines (routine_type type, state *s, vec <state *> &procs)
 static bool
 safe_predicate_mode (const struct pred_data *pred, machine_mode mode)
 {
+  if (!pred)
+    return false;
+
   /* Scalar integer constants have VOIDmode.  */
   if (GET_MODE_CLASS (mode) == MODE_INT
       && (pred->codes[CONST_INT]
-- 
1.9.3

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] genrecog: Fix crash on invalid input
  2016-03-14 15:39 [PATCH] genrecog: Fix crash on invalid input Segher Boessenkool
@ 2016-03-14 17:39 ` Bernd Schmidt
  2016-03-14 18:41   ` Segher Boessenkool
  0 siblings, 1 reply; 5+ messages in thread
From: Bernd Schmidt @ 2016-03-14 17:39 UTC (permalink / raw)
  To: Segher Boessenkool, gcc-patches; +Cc: rdsandiford

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?


Bernd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] genrecog: Fix crash on invalid input
  2016-03-14 17:39 ` Bernd Schmidt
@ 2016-03-14 18:41   ` Segher Boessenkool
  2016-03-14 20:00     ` Segher Boessenkool
  0 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2016-03-14 18:41 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: gcc-patches, rdsandiford

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.


Segher

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] genrecog: Fix crash on invalid input
  2016-03-14 18:41   ` Segher Boessenkool
@ 2016-03-14 20:00     ` Segher Boessenkool
  2016-03-15  0:25       ` Bernd Schmidt
  0 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2016-03-14 20:00 UTC (permalink / raw)
  To: Bernd Schmidt; +Cc: gcc-patches, rdsandiford

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] genrecog: Fix crash on invalid input
  2016-03-14 20:00     ` Segher Boessenkool
@ 2016-03-15  0:25       ` Bernd Schmidt
  0 siblings, 0 replies; 5+ messages in thread
From: Bernd Schmidt @ 2016-03-15  0:25 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: gcc-patches, rdsandiford

On 03/14/2016 09:00 PM, Segher Boessenkool wrote:
> There is just the single caller, and pred is set right before the call
> there.  How about this patch, then?

Looks alright.


Bernd

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-03-15  0:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-14 15:39 [PATCH] genrecog: Fix crash on invalid input Segher Boessenkool
2016-03-14 17:39 ` Bernd Schmidt
2016-03-14 18:41   ` Segher Boessenkool
2016-03-14 20:00     ` Segher Boessenkool
2016-03-15  0:25       ` Bernd Schmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).