gimple-ssa-warn-access: Cast huge params to sizetype before using them in maybe_check_access_sizes [PR113410]
Message ID | ZaesBsXuRvdIwLH9@tucnak |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp815654dye; Wed, 17 Jan 2024 02:30:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9/DoxnRVGup6ywqFeLMneK/uyKAtGs2FfLCdW8Qqf3zSqXJGV9daw6A9V+wOjsdZOjDDE X-Received: by 2002:a05:620a:24c5:b0:783:25f9:ca96 with SMTP id m5-20020a05620a24c500b0078325f9ca96mr10811666qkn.118.1705487427779; Wed, 17 Jan 2024 02:30:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705487427; cv=pass; d=google.com; s=arc-20160816; b=ncObMe4wIaTo0HcHFbRXIVklBhlX2yamFvAGxICJHr6LU0YzvTCHCHyHpm+7jHLekz qzs2nsa1XdeVsZKxvFS4/zdhR+u7AXKlau8R+wsufSc3WzMoGJTzvtjZJFkF9jDdXx1H C0y4dkPmenywt84a7i4fUbQNhA3uXhNbf3TYi2LBuojUSlHr1B3YiCFs5Jv0pnHfIUQS XS2myl+Jf4wLxUqowuB7TVHi2bMoJ8bissyQUHdKSHJQEHjXR49xoc9xrevevepopdl9 u1pz4xeo/lufHF5ygvSCu5AtmFQFQb8wSN7gt8Nlad7BdCctKS2cib2nLvLmfYn2gn+U Es6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=ndKN27k4pUtMB+hftWoewygNLOyVCqbbGDsr14w4508=; fh=OitT9p6YzAYnzQG1GM6oocakGJB9G2lF/75SDe33HZI=; b=0eLsetZGYVH3z4toCnIHYd3Cc2Ia3O2N2u6Chq4/n4LiT9OlT47pvDQlGYWUfeTnAr VDXZTrodyNcwX1vScD5AnKo2XtNY/FVBTmGJ8aWLeSQZ4/Rm/kLRm8ljfGW62I8jq0R5 qk34y0HGdco6uHnDGMkTkjHzkG0iRx2dWocFMjmjDWShFicM+Hr6NUMZ/PiPOMwfM9I6 myOivrbm6iQjZdlMOesRQTOM7+jZCwhV7lGfu8hF3FNhe1Nj2HWFwSbIqD7fYNdOEix1 iidLXBHIb+270ACrVQFkR8WnQ9mBvVlhuXO1WEkMy8gU3Obaj/qEyIOKU6DBoGLwIU9A EhcA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Hdw+V2gX; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x3-20020a05620a098300b00783190cc239si11488343qkx.496.2024.01.17.02.30.27 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 02:30:27 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Hdw+V2gX; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79E203858414 for <ouuuleilei@gmail.com>; Wed, 17 Jan 2024 10:30:27 +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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <jakub@redhat.com> To: Richard Biener <rguenther@suse.de>, Jeff Law <jeffreyalaw@gmail.com> 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: <ZaesBsXuRvdIwLH9@tucnak> 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-Type: text/plain; charset=us-ascii 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Reply-To: Jakub Jelinek <jakub@redhat.com> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788333185332450773 X-GMAIL-MSGID: 1788333185332450773 |
Series |
gimple-ssa-warn-access: Cast huge params to sizetype before using them in maybe_check_access_sizes [PR113410]
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Jakub Jelinek
Jan. 17, 2024, 10:29 a.m. UTC
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 <jakub@redhat.com> 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
Comments
On Wed, 17 Jan 2024, Jakub Jelinek wrote: > 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? OK > 2024-01-17 Jakub Jelinek <jakub@redhat.com> > > 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. > > --- 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); > +} > > 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); +}