From patchwork Tue Feb 6 09:38:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 869719 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-472645-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ZLPBrwg9"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zbKD13k77z9sR8 for ; Tue, 6 Feb 2018 20:39:10 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=B9n7ezoD6bJlLGjZo4Ie4AouqfhqBTS6UQNbdTA4oQqbGH1KWv isRsXI+4sl6SBykFkyQOwPuxHRqDVCNWPNFgSGrmlHkp1IQedkwYk2qghNTBKfjS hGtv0lcdqTPlNRpwNmNEfecfLL/xtgO337oZchuW9+cgaq3J5td/xmqOw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=90MgEB9U+mlExHZcwGSz17ppF8Y=; b=ZLPBrwg93KDOe2H/s78m jQZtgLpBtFvvWP4wmcb9Lv8n1SP39eJbsh2wAiS5Ho7Q545O0LyDKVNbm4BMMcQW g1o67c4KDjwAAWjvWCVxr/vIupVLqKl2hS7M2dFQW5ncDt73rRfpb74KA6ZB0iXT 9Vfwo+cdYWTC3AoTRLAuGB8= Received: (qmail 74710 invoked by alias); 6 Feb 2018 09:39:03 -0000 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 Received: (qmail 74696 invoked by uid 89); 6 Feb 2018 09:39:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=courtesy, HX-Received:10.80.245.172, responsibility X-HELO: mail-wm0-f42.google.com Received: from mail-wm0-f42.google.com (HELO mail-wm0-f42.google.com) (74.125.82.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 06 Feb 2018 09:39:00 +0000 Received: by mail-wm0-f42.google.com with SMTP id 143so2411780wma.5 for ; Tue, 06 Feb 2018 01:39:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=0s4oB53y9LrkodscZ+JjHAQLfJPXTjEWfJI0kHmaR7w=; b=fYApoeDwO5pL9O34QqN+GJdwPufHp/4AO/Hm+6ASCOuXuUKvOlS6hYInE2j24JcmLG vd6w3xxIQ1AFCcIYPl7zOFbNIksYbWOsltj+s/oxWHaDkxaNs17DSo+UZTpRSpTSZz0X ypq6LA4c/XfqYg9G0XnL7eTC+fIUMXZLD5x1Zp6iczCvp+If4Nv3lt4/RgbGTafKpMnl R/NceqJ1CUXFsHRRHMgcNCJERwVkeSz0mvBOfLUYAXnLwweO4V2zcxw/ikfB1wcRfN3s CJ3yscoXyEz1el6/GQpl1K+/H09qrEVg975b9MZ15Ts5AWFuTxig4vnUDYlXkqXEGUuG 4cUQ== X-Gm-Message-State: APf1xPA9PBGRXb0iieMX5aHTpTlKnHPKWj0+U+xa6t9Uigu3OB3D9B6L vy3C1zB99zCpC5DCIMIlOXMJ3ymWtrU= X-Google-Smtp-Source: AH8x2261t66XewEQKhbi7KG8AqT71Lm1s3Ovk8Fn8qWaJV4jH+DJEEMo4MCVIaqcNc1Qzx6Ize3QPQ== X-Received: by 10.80.245.172 with SMTP id u41mr2946635edm.215.1517909938316; Tue, 06 Feb 2018 01:38:58 -0800 (PST) Received: from abulafia.quesejoda.com (55.red-88-8-76.dynamicip.rima-tde.net. [88.8.76.55]) by smtp.gmail.com with ESMTPSA id l9sm7330873edi.34.2018.02.06.01.38.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Feb 2018 01:38:57 -0800 (PST) To: gcc-patches From: Aldy Hernandez Subject: [PR tree-optimization/84224] do not ICE on malformed allocas Message-ID: Date: Tue, 6 Feb 2018 04:38:56 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 X-IsSubscribed: yes The -Walloca pass can receive a malformed alloca, courtesy of someone providing a faulty prototype.  This was causing an ICE because we assumed alloca calls had at least one argument, which the testcase does not: +void *alloca (); +__typeof__(alloca ()) a () { return alloca (); } I don't believe it should be the responsibility of the -Walloca-larger-than=* pass to warn against such things, so I propose we just ignore this. I also think we should handle this testcase, regardless of the target having an alloca builtin, since the testcase includes its own prototype.  Thus, the missing "{dg-require-effect-target alloca}". OK? gcc/ PR tree-optimization/84224 * gimple-ssa-warn-alloca.c (execute): Do not ICE on malformed allocas. diff --git a/gcc/gimple-ssa-warn-alloca.c b/gcc/gimple-ssa-warn-alloca.c index 941810a997e..7457a16d21f 100644 --- a/gcc/gimple-ssa-warn-alloca.c +++ b/gcc/gimple-ssa-warn-alloca.c @@ -443,9 +443,10 @@ pass_walloca::execute (function *fun) gimple *stmt = gsi_stmt (si); location_t loc = gimple_location (stmt); - if (!gimple_alloca_call_p (stmt)) + if (!gimple_alloca_call_p (stmt) + /* A faulty prototype can yield a malformed alloca() call. */ + || gimple_call_num_args (stmt) < 1) continue; - gcc_assert (gimple_call_num_args (stmt) >= 1); const bool is_vla = gimple_call_alloca_for_var_p (as_a (stmt)); diff --git a/gcc/testsuite/gcc.dg/Walloca-16.c b/gcc/testsuite/gcc.dg/Walloca-16.c new file mode 100644 index 00000000000..3ee96a9570a --- /dev/null +++ b/gcc/testsuite/gcc.dg/Walloca-16.c @@ -0,0 +1,6 @@ +/* PR tree-optimization/84224 */ +/* { dg-do compile } */ +/* { dg-options "-O0 -Walloca" } */ + +void *alloca (); +__typeof__(alloca ()) a () { return alloca (); }