From patchwork Wed Aug 12 10:40:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 1343613 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=suse.de 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 4BRR7k0p9pz9sTN for ; Wed, 12 Aug 2020 20:41:05 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C6A13861002; Wed, 12 Aug 2020 10:41:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id E4BAF3857C40 for ; Wed, 12 Aug 2020 10:40:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E4BAF3857C40 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 70672ABEA for ; Wed, 12 Aug 2020 10:41:20 +0000 (UTC) Date: Wed, 12 Aug 2020 12:40:57 +0200 From: Tom de Vries To: gcc-patches@gcc.gnu.org Subject: [committed][nvptx] Fix array dimension in nvptx_assemble_decl_begin Message-ID: <20200812104056.GA24615@delia> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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" Hi, When compiling test-case builtin-object-size-21.c, cc1 emits: ... .visible .global .align 1 .u32 xm3_3[-2305843009213693951] = ... for: ... struct Ax_m3 { char a[PTRDIFF_MAX - 3], ax[]; }; struct Ax_m3 xm3_3 = { { 0 }, { 1, 2, 3 } }; ... Fix this by: - changing the printing format for unsigned HOST_WIDE_INT init_frag.remaining to HOST_WIDE_INT_PRINT_UNSIGNED - changing the type of local variable elt_size in nvptx_assemble_decl_begin to unsigned HOST_WIDE_INT. such that we have: ... .visible .global .align 1 .u32 xm3_3[2305843009213693952] = ... where 2305843009213693952 == 0x2000000000000000, so the array is claiming 0x8000000000000000 bytes, which is one more than PTRDIFF_MAX. This is due to using .u32 instead of .u8, so strictly speaking we should downgrade to using .u8 in this case, but that corner-case problem doesn't look urgent enough to fix in this commit. Build on nvptx, tested with make check-gcc. Committed to trunk. Thanks, - Tom [nvptx] Fix array dimension in nvptx_assemble_decl_begin gcc/ChangeLog: * config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Make elt_size an unsigned HOST_WIDE_INT. Print init_frag.remaining using HOST_WIDE_INT_PRINT_UNSIGNED. --- gcc/config/nvptx/nvptx.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c index cf53a921e5b..39d0275493a 100644 --- a/gcc/config/nvptx/nvptx.c +++ b/gcc/config/nvptx/nvptx.c @@ -2202,7 +2202,7 @@ nvptx_assemble_decl_begin (FILE *file, const char *name, const char *section, /* Neither vector nor complex types can contain the other. */ type = TREE_TYPE (type); - unsigned elt_size = int_size_in_bytes (type); + unsigned HOST_WIDE_INT elt_size = int_size_in_bytes (type); /* Largest mode we're prepared to accept. For BLKmode types we don't know if it'll contain pointer constants, so have to choose @@ -2232,7 +2232,7 @@ nvptx_assemble_decl_begin (FILE *file, const char *name, const char *section, if (size) /* We make everything an array, to simplify any initialization emission. */ - fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC "]", init_frag.remaining); + fprintf (file, "[" HOST_WIDE_INT_PRINT_UNSIGNED "]", init_frag.remaining); else if (atype) fprintf (file, "[]"); }