From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by sourceware.org (Postfix) with ESMTPS id B483B3858401 for ; Mon, 5 Aug 2024 09:46:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B483B3858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B483B3858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2604:1380:40e1:4800::1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722851166; cv=none; b=WYfaMTYZtQ+dEkK7BSxxu9UkbvAmDifOmgaQMbhUdCLb3axhuwmTtQu7WqjVz2cjfUDlumavWjFClkvlUGntXOy1vMbb5X4EGtZ92LuTMmb3TUlzW7CVf2nVIUp9O/H3DL0LiCDiZGgAFTEadoR8zTMAAOat4sgL7Z7tu7PfMME= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722851166; c=relaxed/simple; bh=80ieqFcsSamvjp9pFkdX0cM8WhWcdsU22tgjWm1qMWM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=KsSvEEdUP/Th1fDuVh5okoVoIuE/h1NdkRwU0J5c1meZinsDBrD6Q7KMJVLipURVqfumKhR3v6ABtNdEk6aoc59uc8RCLdHfVwZL/VszNXG6AzAwTjaDcEgt6FaaXCihCY6A50ri+Y0uQfKk4gc8Ir+lYNg9sAVNUelQNAJo0mk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CE33ACE09D2; Mon, 5 Aug 2024 09:46:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FFB3C4AF0E; Mon, 5 Aug 2024 09:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1722851160; bh=80ieqFcsSamvjp9pFkdX0cM8WhWcdsU22tgjWm1qMWM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mQC3hbtzWFoAsGlgfC3yNI76SKSvtBu2++yQZThRWzByD6slRO3ogl0yUaFKBKGB+ f23Xa5WcDwN25DwdRrllLksOKrlMn218klT+Bci1vUR+N/4IiP1a5BsqkXrUqZ9u6g 1eJ4dCAwzTTZHxsgOTcSVDs6242+CMyUwDBp95u+OohIln2A0sJ49P2a3nnwwmUIjg UwI7Pj6TEMIG5dE1KXxvrHAQ54ytG44/dig4AVSGg8St/Dnal4hJHBVgrb2+BplOMn 7MgQG8mdXJd6Tf2FgyPjkcdogkcTlCpAqgwqhSDkcYVuoArDCKdX8RkUpcmbB+oNXT fS/4JiBgguxIQ== Date: Mon, 5 Aug 2024 11:45:56 +0200 From: Alejandro Colomar To: Joseph Myers Cc: Martin Uecker , gcc-patches@gcc.gnu.org, Xavier Del Campo Romero , Gabriel Ravier , Jakub Jelinek , Kees Cook , Qing Zhao Subject: Re: [RFC v3 3/3] c: Add __lengthof__() operator Message-ID: References: <20240803231702.89150-1-alx@kernel.org> <20240803231702.89150-4-alx@kernel.org> <6tgx7qtkvlxxtap65ribwqkjjyhgrplyfq3c2eiemcbpzt6cai@f26emhwlew55> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ze3yh7bkvrtu2xfa" Content-Disposition: inline In-Reply-To: <6tgx7qtkvlxxtap65ribwqkjjyhgrplyfq3c2eiemcbpzt6cai@f26emhwlew55> X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP 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: --ze3yh7bkvrtu2xfa Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable From: Alejandro Colomar To: Joseph Myers Cc: Martin Uecker , gcc-patches@gcc.gnu.org, Xavier Del Campo Romero , Gabriel Ravier , Jakub Jelinek , Kees Cook , Qing Zhao Subject: Re: [RFC v3 3/3] c: Add __lengthof__() operator References: <20240803231702.89150-1-alx@kernel.org> <20240803231702.89150-4-alx@kernel.org> <6tgx7qtkvlxxtap65ribwqkjjyhgrplyfq3c2eiemcbpzt6cai@f26emhwlew55> MIME-Version: 1.0 In-Reply-To: <6tgx7qtkvlxxtap65ribwqkjjyhgrplyfq3c2eiemcbpzt6cai@f26emhwlew55> [CC +=3D Kees, Qing] Hi Joseph, On Sun, Aug 04, 2024 at 08:34:24PM GMT, Alejandro Colomar wrote: > On Sun, Aug 04, 2024 at 08:02:25PM GMT, Martin Uecker wrote: > D'oh! I screwed it. I wanted to have written this: >=20 > $ cat star.c=20 > void foo(char (*a)[3][*], int (*x)[__lengthof__(*a)]); I think this answers your question of if we want __lengthof__ to evaluate its operand if the top-level array is non-VLA but an inner array is VLA. We clearly want it to not evaluate, because we want this __lengthof__ to be a constant expression, ... > void bar(char (*a)[*][3], int (*x)[__lengthof__(*a)]); > void foo2(char (*a)[3][*], int (*x)[sizeof(**a)]); > void bar2(char (*a)[*][3], int (*x)[sizeof(**a)]); >=20 > int > main(void) > { > int i3[3]; > int i5[5]; > char c35[3][5]; > char c53[5][3]; >=20 > foo(&c35, &i3); > foo(&c35, &i5); // I'd expect this to err =2E.. and thus cause a compile-time error here (-Wincompatible-pointer-types). I suspect we need to modify array_type_nelts_minus_one() for that; I'm going to investigate. Have a lovely day! Alex > bar(&c53, &i3); // I'd expect this to warn > bar(&c53, &i5); >=20 > foo2(&c35, &i3); // I'd expect this to warn > foo2(&c35, &i5); > bar2(&c53, &i3); > //bar2(&c53, &i5); // error: -Wincompatible-pointer-types > } > $ /opt/local/gnu/gcc/lengthof/bin/gcc -Wall -Wextra star.c -S > $=20 --=20 --ze3yh7bkvrtu2xfa Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmawn04ACgkQnowa+77/ 2zJS6A/+I1YgeGasOXkpoq8aVpXFabPBS70VRjAIUs0vpIOZxq9vhdTil5XX0igs 5GLuHYGCIjoe2rghWZhEPWlND7ycVYpyzs4cLAaZboZ4xwKrlbA4lwueYrGCWDZg LLTkoE7zljcfKraJo5uAIL8DvDSsYWYyyDPZ5iylZqsW0S34nG6JY8RT4qi7Hten FQ9TeIFILdm2YISmGjGxmyTB3rYfyROm6ttCBo9ODHVk5hMixR7C+nR77XAdPEWR BnzJJt9dLubSikFoLqZtsgn1eCupJXYdb1DXPwh/MuHYzGlXYnI/lUeAfBQcDNaF YC0IyZKJdgr9syJQSdEnsIpH6oOGSSRIPleD45fwHAJwCXu9GgeK3bJ27WcIa12b L1fw1V5TYapmZ1igKLPnfP0CLH7JwiTMRHMUMWZj6NrWSf6skxekcokkFedV7vBL IlMdCaPz++drfJhseL8eJMISGb81ykS/fDiwzLpslj21z0lbE7CyZDENRSHnrdKQ BmRpwuTdTQRmQuvf8+xfXOufGoddSuW5yS9bmJaIoJfKUvamHAK58yJdbM7SbeuW 878Zlveoql2+kk5ecamU1esurSWffcE9l7PCfzFUImtCeLjSZt1ls8QTyMWIyY26 hEqSK6YVTQ46QgjwM5kTDR3Gp/dTgaezdMuZMCCxDo+czecqX4Y= =mLaR -----END PGP SIGNATURE----- --ze3yh7bkvrtu2xfa--