This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/53886] Seg fault in sh_insn_length_adjustment
- From: "olegendo at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 08 Jul 2012 12:19:09 +0000
- Subject: [Bug target/53886] Seg fault in sh_insn_length_adjustment
- Auto-submitted: auto-generated
- References: <bug-53886-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53886
--- Comment #4 from Oleg Endo <olegendo at gcc dot gnu.org> 2012-07-08 12:19:09 UTC ---
(In reply to comment #3)
> Created attachment 27763 [details]
> preprocessed src
>
> Sorry, I had tried to attach it during the bug creation but I didn't notice it
> didn't take.
Thanks. I could reproduce the problem here. It seems to happen for
-Os and-m{2a|4*}.
The reason is the subexpression
PATTERN (NEXT_INSN (PREV_INSN (insn)))
can return nullptr in some cases like this.
The patch below fixes this particular crash, but I'm not sure whether it is
the right thing to do in this case.
Index: gcc/config/sh/sh.c
===================================================================
--- gcc/config/sh/sh.c (revision 189339)
+++ gcc/config/sh/sh.c (working copy)
@@ -9652,6 +9652,26 @@
#define IS_ASM_LOGICAL_LINE_SEPARATOR(C, STR) ((C) == ';')
#endif
+static bool
+sequence_insn_p (rtx insn)
+{
+ rtx prev,next,pat;
+
+ prev = PREV_INSN (insn);
+ if (prev == NULL)
+ return false;
+
+ next = NEXT_INSN (prev);
+ if (next == NULL)
+ return false;
+
+ pat = PATTERN (next);
+ if (pat == NULL)
+ return false;
+
+ return GET_CODE (pat) == SEQUENCE;
+}
+
int
sh_insn_length_adjustment (rtx insn)
{
@@ -9662,7 +9682,7 @@
&& GET_CODE (PATTERN (insn)) != CLOBBER)
|| CALL_P (insn)
|| (JUMP_P (insn) && !JUMP_TABLE_DATA_P (insn)))
- && GET_CODE (PATTERN (NEXT_INSN (PREV_INSN (insn)))) != SEQUENCE
+ && ! sequence_insn_p (insn)
&& get_attr_needs_delay_slot (insn) == NEEDS_DELAY_SLOT_YES)
return 2;
@@ -9671,7 +9691,7 @@
if (sh_cpu_attr == CPU_SH2E
&& JUMP_P (insn) && !JUMP_TABLE_DATA_P (insn)
&& get_attr_type (insn) == TYPE_CBRANCH
- && GET_CODE (PATTERN (NEXT_INSN (PREV_INSN (insn)))) != SEQUENCE)
+ && ! sequence_insn_p (insn))
return 2;
/* sh-dsp parallel processing insn take four bytes instead of two. */