From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3521 invoked by alias); 8 Jul 2012 12:19:29 -0000 Received: (qmail 3509 invoked by uid 22791); 8 Jul 2012 12:19:27 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 08 Jul 2012 12:19:10 +0000 From: "olegendo at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/53886] Seg fault in sh_insn_length_adjustment Date: Sun, 08 Jul 2012 12:19:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: olegendo at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-07/txt/msg00701.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53886 --- Comment #4 from Oleg Endo 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. */