From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9020 invoked by alias); 5 Nov 2002 23:26:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 9005 invoked by uid 71); 5 Nov 2002 23:26:01 -0000 Date: Tue, 05 Nov 2002 15:26:00 -0000 Message-ID: <20021105232601.9004.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Franz Sirl Subject: Re: c/8467: Bug in sibling call optimization Reply-To: Franz Sirl X-SW-Source: 2002-11/txt/msg00257.txt.bz2 List-Id: The following reply was made to PR c/8467; it has been noted by GNATS. From: Franz Sirl To: gcc-gnats@gcc.gnu.org Cc: Subject: Re: c/8467: Bug in sibling call optimization Date: Wed, 6 Nov 2002 00:20:46 +0100 On Tuesday 05 November 2002 21:25, Franz.Sirl-kernel@lauterbach.com wrote: > >Number: 8467 > >Category: c > >Synopsis: Bug in sibling call optimization > >Confidential: no > >Severity: serious > >Priority: medium > >Responsible: unassigned > >State: open > >Class: sw-bug > >Submitter-Id: net > >Arrival-Date: Tue Nov 05 12:26:00 PST 2002 > >Closed-Date: > >Last-Modified: > >Originator: Franz.Sirl-kernel@lauterbach.com > >Release: gcc-3.2.1pre, gcc-3.3exp > >Organization: > >Environment: > > powerpc-linux-gnu > > >Description: > > The appended testcase aborts if compiled with -O2, adding > -fno-optimize-sibling-calls makes it pass. > > This is a regression from gcc-2.95.4. > > >How-To-Repeat: > > extern void abort (void); > extern void exit (int); > > int aim_callhandler(int sess, int conn, unsigned short family, unsigned > short type) { > static int i = 0; > > if (!conn) > return 0; > > if (type == 0xffff) > { > return 0; > } > > if (i >= 1) > abort (); > > i++; > return aim_callhandler(sess, conn, family, 0xffff); > } > > int main (void) > { > aim_callhandler (0, 1, 0, 0); > exit (0); > } The 4th arg is incorrectly sign-extended during tail recursion. the .rtl dump with debug_call_placeholder_verbose set to 1 in the debugger: (call_insn 94 68 96 (call_placeholder 84 0 69 79 (cond [ (const_string "normal") (sequence [ (insn 84 0 86 (set (reg:SI 3 r3) (reg/v:SI 116)) -1 (nil) (nil)) (insn 86 84 88 (set (reg:SI 4 r4) (reg/v:SI 117)) -1 (nil) (nil)) (insn 88 86 90 (set (reg:SI 5 r5) (reg/v:SI 118)) -1 (nil) (nil)) (insn 90 88 91 (set (reg:SI 6 r6) (const_int 65535 [0xffff])) -1 (nil) (nil)) (call_insn 91 90 93 (parallel[ (set (reg:SI 3 r3) (call (mem:SI (symbol_ref:SI ("aim_callhandler")) [0 S4 A8]) (const_int 0 [0x0]))) (use (const_int 0 [0x0])) (clobber (scratch:SI)) ] ) -1 (nil) (nil) (expr_list (use (reg:SI 6 r6)) (expr_list (use (reg:SI 5 r5)) (expr_list (use (reg:SI 4 r4)) (expr_list (use (reg:SI 3 r3)) (nil)))))) (insn 93 91 0 (set (reg:SI 137) (reg:SI 3 r3)) -1 (nil) (nil)) ]) (const_string "tail_recursion") (sequence [ (note 69 0 70 NOTE_INSN_DELETED) (note 70 69 72 NOTE_INSN_DELETED) (insn 72 70 74 (set (reg/v:SI 116) (reg/v:SI 116)) -1 (nil) (nil)) (insn 74 72 76 (set (reg/v:SI 117) (reg/v:SI 117)) -1 (nil) (nil)) (insn 76 74 78 (set (reg/v:SI 118) (reg/v:SI 118)) -1 (nil) (nil)) (insn 78 76 80 (set (reg/v:SI 119) (const_int -1 [0xffffffffffffffff])) -1 (nil) (nil)) (jump_insn 80 78 81 (set (pc) (label_ref 79)) -1 (nil) (nil)) (barrier 81 80 82) (barrier 82 81 0) ]) ])) -1 (nil) (nil) (nil)) Note the difference between insn 90 in the "normal" sequence and insn 78 in the "tail_recursion" sequence! The 0xffff CONST_INT got signed extended, so the compiler took the "short" type of the 4th arg into account, but ignored the "unsigned" one. Franz.