From patchwork Mon Jun 29 17:19:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1318936 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: 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=qOKNZWF6; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 ozlabs.org (Postfix) with ESMTPS id 49wZ4B3NHsz9sRk for ; Tue, 30 Jun 2020 03:19:53 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BFC573851C2A; Mon, 29 Jun 2020 17:19:50 +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 CFC0C3851C2A for ; Mon, 29 Jun 2020 17:19:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CFC0C3851C2A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=roger@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=JhP6lDvvIeSRpLSxbie9+HrrnpSn7dXAN1v38Umzuno=; b=qOKNZWF6d3X2DjtAxnlUPRdEyl AJkFNFQHxdd92OCvXZg6YFS62PoO19hwc/3UumZho2vTu8wdXkVCzf8QHfhjbKSY+fU8W1BS+SU6s 651tAZoFY0CruU7Nco3dKwFJJk0OD1vV5LiYOS7hP3597XoKikS3y+Ut+/FwZIq/9Kpnh8uexSQxn yF2rMijPXQw+CnlW3UXHOAzl+tS+Eem9RIc+PUvocSeVddQQQgP0ca+WGAQL6ASzoDszY8tYwh4Xb EZBk4RjXp1jJaygA3g90nz6tUYWu0R9ZvItwGxHk8/09kv/XHJwSQBGYC3CMpqhCvSj64E4YW8hC4 AZ1nO7IA==; Received: from [185.62.158.67] (port=60191 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1jpxRb-0002mX-A5 for gcc-patches@gcc.gnu.org; Mon, 29 Jun 2020 13:19:47 -0400 From: "Roger Sayle" To: Subject: [PATCH] nvptx: Fix ICE in nvptx_vector_alignment on gcc.dg/attr-vector_size.c Date: Mon, 29 Jun 2020 18:19:45 +0100 Message-ID: <00ee01d64e39$7c796040$756c20c0$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdZONmDmbj/cBslwSRKGi8rg3P/HAw== 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=-11.1 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 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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@gcc.gnu.org Sender: "Gcc-patches" This patch addresses the ICE in gcc.dg/attr-vector_size.c during make -k check on nvptx-none. The actual ICE looks like: testsuite/gcc.dg/attr-vector_size.c:29:1: internal compiler error: in tree_to_shwi, at tree.c:7321 0xf53bf2 tree_to_shwi(tree_node const*) ../../gcc/gcc/tree.c:7321 0xff1969 nvptx_vector_alignment ../../gcc/gcc/config/nvptx/nvptx.c:5105^M The problem is that the caller has ensured that TYPE_SIZE(type) is representable as an unsigned HOST_WIDE_INT, but nvptx_vector_alignment is accessing it as a signed HOST_WIDE_INT which overflows in pathological conditions. Amongst those pathological conditions is that a TYPE_SIZE of zero can sometimes reach this function, prior to an error being emitted. Making sure the result is not less than the mode's alignment and not greater than BIGGEST_ALIGNMENT fixes the ICEs, and generates the expected compile-time error messages. Tested on --target=nvptx-none, with a "make" and "make check" which results in four fewer unexpected failures and three more expected passes. Ok for mainline? 2020-06-29 Roger Sayle gcc/ChangeLog: * config/nvptx/nvptx.c (nvptx_vector_alignment): Use tree_to_uhwi to access TYPE_SIZE (type). Return at least the mode's alignment. Thanks, Roger --- Roger Sayle NextMove Software Cambridge, UK diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index e3e84df..bfad91b 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -5102,9 +5102,10 @@ static const struct attribute_spec nvptx_attribute_table[] = static HOST_WIDE_INT nvptx_vector_alignment (const_tree type) { - HOST_WIDE_INT align = tree_to_shwi (TYPE_SIZE (type)); - - return MIN (align, BIGGEST_ALIGNMENT); + unsigned HOST_WIDE_INT align = tree_to_uhwi (TYPE_SIZE (type)); + if (align > BIGGEST_ALIGNMENT) + return BIGGEST_ALIGNMENT; + return MAX (align, GET_MODE_ALIGNMENT (TYPE_MODE (type))); } /* Indicate that INSN cannot be duplicated. */