From patchwork Fri Sep 17 23:26:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 65115 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 7BADEB70AE for ; Sat, 18 Sep 2010 09:26:33 +1000 (EST) Received: (qmail 28465 invoked by alias); 17 Sep 2010 23:26:32 -0000 Received: (qmail 28457 invoked by uid 22791); 17 Sep 2010 23:26:31 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 17 Sep 2010 23:26:27 +0000 Received: from hpaq14.eem.corp.google.com (hpaq14.eem.corp.google.com [172.25.149.14]) by smtp-out.google.com with ESMTP id o8HNQO8u021188 for ; Fri, 17 Sep 2010 16:26:24 -0700 Received: from iwn39 (iwn39.prod.google.com [10.241.68.103]) by hpaq14.eem.corp.google.com with ESMTP id o8HNQNNf006719 for ; Fri, 17 Sep 2010 16:26:23 -0700 Received: by iwn39 with SMTP id 39so2966995iwn.40 for ; Fri, 17 Sep 2010 16:26:23 -0700 (PDT) Received: by 10.231.182.204 with SMTP id cd12mr6151188ibb.101.1284765982565; Fri, 17 Sep 2010 16:26:22 -0700 (PDT) Received: from coign.google.com (dhcp-172-22-123-203.mtv.corp.google.com [172.22.123.203]) by mx.google.com with ESMTPS id i6sm4191701iba.20.2010.09.17.16.26.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 17 Sep 2010 16:26:21 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org Subject: [gccgo] Test for -fsplit-stack and alloca Date: Fri, 17 Sep 2010 16:26:20 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true 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 I forgot to commit this with the last patch. This is a test case for -fsplit-stack with alloca. Committed to gccgo branch. Ian Index: gcc/testsuite/gcc.dg/split-4.c =================================================================== --- gcc/testsuite/gcc.dg/split-4.c (revision 0) +++ gcc/testsuite/gcc.dg/split-4.c (revision 0) @@ -0,0 +1,65 @@ +/* This test needs to use setrlimit to set the stack size, so it can + only run on Unix. */ +/* { dg-do run { target *-*-linux* *-*-solaris* *-*-darwin* } } */ +/* { dg-require-effective-target split_stack } */ +/* { dg-options "-fsplit-stack" } */ + +#include +#include +#include +#include + +/* Use a noinline function to ensure that the buffer is not removed + from the stack. */ +static void use_buffer (char *buf, size_t) __attribute__ ((noinline)); +static void +use_buffer (char *buf, size_t c) +{ + memset (buf, '\0', c); +} + +/* Each recursive call uses 10 * i bytes. We call it 1000 times, + using a total of 5,000,000 bytes. If -fsplit-stack is not working, + that will overflow our stack limit. */ + +static void +down1 (int i) +{ + char buf[10 * i]; + + if (i > 0) + { + use_buffer (buf, 10 * i); + down1 (i - 1); + } +} + +/* Same thing, using alloca. */ + +static void +down2 (int i) +{ + char *buf = alloca (10 * i); + + if (i > 0) + { + use_buffer (buf, 10 * i); + down2 (i - 1); + } +} + +int +main (void) +{ + struct rlimit r; + + /* We set a stack limit because we are usually invoked via make, and + make sets the stack limit to be as large as possible. */ + r.rlim_cur = 8192 * 1024; + r.rlim_max = 8192 * 1024; + if (setrlimit (RLIMIT_STACK, &r) != 0) + abort (); + down1 (1000); + down2 (1000); + return 0; +}