From patchwork Wed Jan 17 10:29:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 84242 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C42563857828 for ; Wed, 17 Jan 2024 10:30:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8C2213857C77 for ; Wed, 17 Jan 2024 10:29:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C2213857C77 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8C2213857C77 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705487380; cv=none; b=e25dChLUth9YOD6SBunGWcGvuYXQlioAmbojCLMCZ3tAsXm2A6/2bLossUSF/lElQykpFd1Z2XDDNT2NCWghVFmmeGYxnlC1Ct/gcwmMw26oAX2t8/g3BSgJg+qYP+8JZde2+0Hja7jxEZJlffdl4ju1aGAtnJDzdFLUnt1PyeM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705487380; c=relaxed/simple; bh=2GhYkgC9+xDlYZsidDh+hzD9/uhPcJFQTy3p4CQvLFw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=k/SPvEKjelf5pILgyRtLnTQ5ammaopb0jyp8mcrWDStbXKEwpjTAkuigU/QsXUxsJvXjvUtzFc+LFONRRFfheH04is9fZXLvXqXhSzlwvcBpIJxtwIxvwebEpYXeH2utFExsoInI7JOWl7qj/H8IlAzUYZp5EmJZKUdxWCj2qX0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705487377; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=ndKN27k4pUtMB+hftWoewygNLOyVCqbbGDsr14w4508=; b=Hdw+V2gX2iQu7gcuNtFQDueVOUbehUVeuSnEdkOQrerRfSeOEz6jZicaRqizQxTf9HkOmQ Bzbej8jKL4ZqY3OUBmU8oAt7SiJHG0FTfa65Mns+OGGBMRcpn6Q92ZrKReSqJ4ohfSiPov OeFWN9+w6nkqlpHEpkWR9c684siWoS8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-343-4lEb3otbPmil-SMN1oIzSQ-1; Wed, 17 Jan 2024 05:29:35 -0500 X-MC-Unique: 4lEb3otbPmil-SMN1oIzSQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8408D3C0F1AF for ; Wed, 17 Jan 2024 10:29:35 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.70]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 485B53C25 for ; Wed, 17 Jan 2024 10:29:35 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 40HATRwY2308951 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 17 Jan 2024 11:29:28 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 40HATQEc2308948; Wed, 17 Jan 2024 11:29:26 +0100 Date: Wed, 17 Jan 2024 11:29:26 +0100 From: Jakub Jelinek To: Richard Biener , Jeff Law Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] gimple-ssa-warn-access: Cast huge params to sizetype before using them in maybe_check_access_sizes [PR113410] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Hi! WHen a VLA is created with some very high precision size expression (say __int128, or _BitInt(65535) etc.), we cast it to sizetype, because we can't have arrays longer than what can be expressed in sizetype. But the maybe_check_access_sizes code when trying to determine ranges wasn't doing this but was using fixed buffers for the sizes. While __int128 could still be handled (fit into the buffers), obviously arbitrary _BitInt parameter ranges can't, they can be in the range of up to almost 20KB per number. It doesn't make sense to print such ranges though, no array can be larger than sizetype precision, and ranger's range_of_expr can handle NOP_EXPRs/CONVERT_EXPRs wrapping a PARM_DECL just fine, so the following patch just casts the excessively large counters for the range determination purposes to sizetype. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-01-17 Jakub Jelinek PR middle-end/113410 * gimple-ssa-warn-access.cc (pass_waccess::maybe_check_access_sizes): If access_nelts is integral with larger precision than sizetype, fold_convert it to sizetype. * gcc.dg/bitint-72.c: New test. Jakub --- gcc/gimple-ssa-warn-access.cc.jj 2024-01-03 11:51:30.087751231 +0100 +++ gcc/gimple-ssa-warn-access.cc 2024-01-16 19:25:35.408958088 +0100 @@ -3406,6 +3406,15 @@ pass_waccess::maybe_check_access_sizes ( else access_nelts = rwm->get (sizidx)->size; + /* If access_nelts is e.g. a PARM_DECL with larger precision than + sizetype, such as __int128 or _BitInt(34123) parameters, + cast it to sizetype. */ + if (access_nelts + && INTEGRAL_TYPE_P (TREE_TYPE (access_nelts)) + && (TYPE_PRECISION (TREE_TYPE (access_nelts)) + > TYPE_PRECISION (sizetype))) + access_nelts = fold_convert (sizetype, access_nelts); + /* Format the value or range to avoid an explosion of messages. */ char sizstr[80]; tree sizrng[2] = { size_zero_node, build_all_ones_cst (sizetype) }; --- gcc/testsuite/gcc.dg/bitint-72.c.jj 2024-01-16 19:31:33.839938120 +0100 +++ gcc/testsuite/gcc.dg/bitint-72.c 2024-01-16 19:31:06.000328741 +0100 @@ -0,0 +1,16 @@ +/* PR middle-end/113410 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-std=c23" } */ + +#if __BITINT_MAXWIDTH__ >= 905 +void bar (_BitInt(905) n, int[n]); +#else +void bar (int n, int[n]); +#endif + +void +foo (int n) +{ + int buf[n]; + bar (n, buf); +}