From patchwork Fri Oct 29 17:08:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 69612 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B98B9B6ED0 for ; Sat, 30 Oct 2010 04:08:30 +1100 (EST) Received: (qmail 30239 invoked by alias); 29 Oct 2010 17:08:24 -0000 Received: (qmail 30225 invoked by uid 22791); 29 Oct 2010 17:08:23 -0000 X-SWARE-Spam-Status: No, hits=-5.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 29 Oct 2010 17:08:16 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9TH8FwH026795 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 29 Oct 2010 13:08:15 -0400 Received: from anchor.twiddle.home (ovpn-113-23.phx2.redhat.com [10.3.113.23]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o9TH8Efe006579 for ; Fri, 29 Oct 2010 13:08:14 -0400 Message-ID: <4CCAFF7E.5080807@redhat.com> Date: Fri, 29 Oct 2010 10:08:14 -0700 From: Richard Henderson User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100921 Fedora/3.1.4-1.fc13 Thunderbird/3.1.4 MIME-Version: 1.0 To: GCC Patches Subject: [PR 46226] asm goto may leave stack pointer invalid X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org An asm goto is a jump instruction, therefore we must ensure a consistent stack wrt pending adjustments beforehand. Tested on i486 and x86_64-linux, committed to 4.5 and head. r~ PR rtl-opt/46226 * stmt.c (expand_asm_operands): Call do_pending_stack_adjust for asm goto. diff --git a/gcc/stmt.c b/gcc/stmt.c index 9096d83..c8f56f5 100644 --- a/gcc/stmt.c +++ b/gcc/stmt.c @@ -776,6 +776,10 @@ expand_asm_operands (tree string, tree outputs, tree inputs, /* Second pass evaluates arguments. */ + /* Make sure stack is consistent for asm goto. */ + if (nlabels > 0) + do_pending_stack_adjust (); + ninout = 0; for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++) { diff --git a/gcc/testsuite/gcc.dg/pr46226.c b/gcc/testsuite/gcc.dg/pr46226.c new file mode 100644 index 0000000..9934a4f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr46226.c @@ -0,0 +1,36 @@ +/* { dg-do run } */ +/* { dg-options "-Os -fomit-frame-pointer" } */ +/* { dg-options "-Os -fomit-frame-pointer -mno-accumulate-outgoing-args -fno-asynchronous-unwind-tables" { target { i?86-*-* x86_64-*-* } } } */ + +extern void abort(void); + +static void *p[2]; + +void __attribute__((noinline)) +g(int x, ...) +{ + asm volatile ("" : : "g"(x)); +} + +void __attribute__((noinline)) +f(int x) +{ + p[0] = __builtin_return_address (0); + if (x == 0) + g(0); + g(1, 2, 3, 4, 5, 6, 7); + + asm goto ("jmp %l0" : : : : label); + abort (); + + label: + p[1] = __builtin_return_address (0); +} + +int main() +{ + f(1); + if (p[0] != p[1]) + abort (); + return 0; +}