From patchwork Thu Feb 17 10:01:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chung-Lin Tang X-Patchwork-Id: 83438 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 82DE9B70FF for ; Thu, 17 Feb 2011 21:01:16 +1100 (EST) Received: (qmail 25113 invoked by alias); 17 Feb 2011 10:01:15 -0000 Received: (qmail 25102 invoked by uid 22791); 17 Feb 2011 10:01:14 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 17 Feb 2011 10:01:06 +0000 Received: (qmail 20855 invoked from network); 17 Feb 2011 10:01:05 -0000 Received: from unknown (HELO ?192.168.1.16?) (cltang@127.0.0.2) by mail.codesourcery.com with ESMTPA; 17 Feb 2011 10:01:05 -0000 Message-ID: <4D5CF204.4080306@codesourcery.com> Date: Thu, 17 Feb 2011 18:01:40 +0800 From: Chung-Lin Tang User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches CC: Richard Earnshaw Subject: [PATCH, ARM] Fix PR 43872, incorrectly aligned VLAs 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 Hi, this PR is a case where we have a leaf function with a zero-size frame, that calls alloca() (here through a C99 VLA). The ARM backend recognizes the leaf-and-no-frame opportunity to save an unneeded stack alignment. But when calling alloca(), the allocated block is of BIGGEST_ALIGNMENT, which is 8-bytes under current AAPCS. Thus a stack align may still be needed to place the alloca() returned block properly. This patch adjusts the early return condition with !cfun->calls_alloca. Tested without regressions on ARM-Linux, okay for trunk? Also related, the BIGGEST_ALIGNMENT defined for ARM is currently ABI-based; 64-bits for AAPCS targets, and 32 for old ABI. Should this also consider arch-level as well? i.e. anything >= ARMv5TE (with ldrd) should have this set to 64. Thanks, Chung-Lin 2011-02-17 Chung-Lin Tang PR target/43872 * config/arm/arm.c (arm_get_frame_offsets): Adjust early return condition with !cfun->calls_alloca. Index: config/arm/arm.c =================================================================== --- config/arm/arm.c (revision 170243) +++ config/arm/arm.c (working copy) @@ -15415,7 +15415,10 @@ offsets->soft_frame = offsets->saved_regs + CALLER_INTERWORKING_SLOT_SIZE; /* A leaf function does not need any stack alignment if it has nothing on the stack. */ - if (leaf && frame_size == 0) + if (leaf && frame_size == 0 + /* However if it calls alloca(), we have a dynamically allocated + block of BIGGEST_ALIGNMENT on stack, so still do stack alignment. */ + && ! cfun->calls_alloca) { offsets->outgoing_args = offsets->soft_frame; offsets->locals_base = offsets->soft_frame;