From patchwork Sat Mar 12 19:40:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1604686 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=DaHuECSE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KGCnj55lwz9sG3 for ; Sun, 13 Mar 2022 06:40:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 850E9385DC35 for ; Sat, 12 Mar 2022 19:40:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 9904F3858C78 for ; Sat, 12 Mar 2022 19:40:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9904F3858C78 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=gs+JWzzuMGsUdPyJhu0Al4pbDhO7kHgLpqRz2KUz0Uw=; b=DaHuECSEz8qL7wZfukG06gf0Yr kY0y16NhNEdDxsMkQgWeW517C41p820JWQ/pSu1IAHmGP9wacC5gF92PXipWpcWVIZkK7vvalGIZp PdLM/egJquBFVdO1lizvLxrt33/PB9+rV0Gr/6LgwC0duUp/m7Y65YrBYQF0na+WF92BBudbMEWAM mwBVI1obaS3ddN6B3h7oMVUF5i5L7HOuwN3lcF3sNko5VwWnksOiUsbGSS5CVZHe+TpEvIWOGGY0F oyal7oAsXbsxahkT6cu2S0NjheWZXnAZFKJa++blpzA+C+Kgjzecc7/o04tXg8qQnTS2aUxQElAnX HB5cf66g==; Received: from host86-186-213-42.range86-186.btcentralplus.com ([86.186.213.42]:59581 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nT7b0-0005WG-3q for gcc-patches@gcc.gnu.org; Sat, 12 Mar 2022 14:40:10 -0500 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] PR middle-end/104885: Fix ICE with large stack frame on powerpc64. Date: Sat, 12 Mar 2022 19:40:08 -0000 Message-ID: <006401d83648$fbdbc960$f3935c20$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Adg2SGrV3p3uNnVnQZ+FRU61kHw/mw== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" My recent testcase for PR c++/84964.C stress tests the middle-end by attempting to pass a UINT_MAX sized structure on the stack. Although my fix to PR84964 avoids the ICE after sorry() on x86_64 and similar targets, a related issue still exists on powerpc64 (and similar ACCUMULATE_OUTGOING_ARGS/ARGS_GROW_DOWNWARD targets) which don't issue a "sorry, unimplemented" message, but instead ICE elsewhere. After attempting several alternate fixes, the simplest solution is to just defensively check in mark_stack_region_used that the upper bound of the region lies within the allocated stack_usage_map array, which is of size highest_outgoing_arg_in_use. When this isn't the case, the code now follows the same path as for variable sized regions, and uses stack_usage_watermark rather than a map. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check to confirm there are no surprises, and with the cc1plus of a cross-compiler to powerpc64-linux-gnu to confirm the new test case no longer ICEs. Ok for mainline? 2022-03-12 Roger Sayle gcc/ChangeLog PR middle-end/104885 * calls.cc (mark_stack_region_used): Check that the region is within the allocated size of stack_usage_map. Thanks in advance, Roger diff --git a/gcc/calls.cc b/gcc/calls.cc index 50fa7b8..1ca96e7 100644 --- a/gcc/calls.cc +++ b/gcc/calls.cc @@ -201,7 +201,8 @@ mark_stack_region_used (poly_uint64 lower_bound, poly_uint64 upper_bound) { unsigned HOST_WIDE_INT const_lower, const_upper; const_lower = constant_lower_bound (lower_bound); - if (upper_bound.is_constant (&const_upper)) + if (upper_bound.is_constant (&const_upper) + && const_upper <= highest_outgoing_arg_in_use) for (unsigned HOST_WIDE_INT i = const_lower; i < const_upper; ++i) stack_usage_map[i] = 1; else