From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id A0E913858CDB for ; Wed, 17 Jan 2024 12:36:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A0E913858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A0E913858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705494979; cv=none; b=S9u+7k7xGRfbIZOy9nOYT/Jl11s3EJIcnOcpzFW9cMckWgC8XI8VQPEgtEkEKGDJHxlWUmZVKwBx0NrpmxlmKMDk5cZYgBeIwpA0CNIeQkkkjF5a2xjbgThk95pxaaZdx5g7u+P/aqgT79sn0Ly9JUAJCZussgv0JdS6XbueaqM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705494979; c=relaxed/simple; bh=9j8QEYpIgNGCgiwz2/6PxlRzUhS0xMNDIaHjJpek1iA=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:Message-ID:MIME-Version; b=EY/l6zQ4/phX+wzzX4GWxK3mqi5ibVqR2Lq/egavkh98YwHE5NQb5HnKiHKZVU06E1keV+cybpDbk151ZcLKfFnvCYf5evNZyRZmn2ONZ6DLFTuTnsF36ccJptGBobMbANaCITvZBExicZwjiiECRg+1HTNOAwstHaBXXOaQFAc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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 smtp-out2.suse.de (Postfix) with ESMTPS id 941401FC84; Wed, 17 Jan 2024 12:36:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705494976; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LGPn5epSB0/FAgyeqdZ2J4eAr5hXZin32LTVcjBg9sc=; b=tdQCIFLRm4rXA3wogDT/SKgfc+RUMMF9iNrqL943zIhAMDdlgZ8QkgJSUdUhnZBwlEkr0A sERASXkxR6TyKoLJJcuskOJA9giyRBGOYg7nCCGI92t3lAGt1FEYFv14iUu+2VVeIN8aXf v2M8gFUGBplHq5T3+7u385e52Hr4ICY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705494976; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LGPn5epSB0/FAgyeqdZ2J4eAr5hXZin32LTVcjBg9sc=; b=8IQpQ1OQaCsnk09RAf0IiWQY5VRuORxbf4//xJay9ciKOkESkf9l5dNnMygGxXUFalbpKR Fcc73y63UfpSeWAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1705494976; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LGPn5epSB0/FAgyeqdZ2J4eAr5hXZin32LTVcjBg9sc=; b=tdQCIFLRm4rXA3wogDT/SKgfc+RUMMF9iNrqL943zIhAMDdlgZ8QkgJSUdUhnZBwlEkr0A sERASXkxR6TyKoLJJcuskOJA9giyRBGOYg7nCCGI92t3lAGt1FEYFv14iUu+2VVeIN8aXf v2M8gFUGBplHq5T3+7u385e52Hr4ICY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1705494976; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LGPn5epSB0/FAgyeqdZ2J4eAr5hXZin32LTVcjBg9sc=; b=8IQpQ1OQaCsnk09RAf0IiWQY5VRuORxbf4//xJay9ciKOkESkf9l5dNnMygGxXUFalbpKR Fcc73y63UfpSeWAg== Date: Wed, 17 Jan 2024 13:31:09 +0100 (CET) From: Richard Biener To: Jakub Jelinek cc: Jeff Law , gcc-patches@gcc.gnu.org Subject: Re: [PATCH] gimple-ssa-warn-access: Cast huge params to sizetype before using them in maybe_check_access_sizes [PR113410] In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [-0.10 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_CC(0.00)[gmail.com,gcc.gnu.org]; BAYES_HAM(-0.00)[41.24%] X-Spam-Level: X-Spam-Score: -0.10 X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,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 List-Id: 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 > > 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 > > -- Richard Biener SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)