From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202]) by sourceware.org (Postfix) with ESMTPS id F0EC93858D28 for ; Mon, 31 Jul 2023 20:06:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F0EC93858D28 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=tugraz.at Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tugraz.at Received: from vra-168-87.tugraz.at (vra-168-87.tugraz.at [129.27.168.87]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4RF8QY1fMFz1LM0K; Mon, 31 Jul 2023 22:06:44 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4RF8QY1fMFz1LM0K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1690834005; bh=P6H5E706Z+9AaBJX8rZd74LWFtU4fUW1exhddulo3X4=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=pi5fZmsIFJcYnikui3JBijf3S5zM70N6wWpAC4KH5wWN2gtfHM/9ODZCE8ZipZBKR w2M/Cu4xEhOc+sVTT0I7buPfRRiXNUP9v5XtCEdBmgcOGUhB2aYkoymOzuAInFww5W 6XzAK3uyvxX0r+E3NKBorRwdaf/Ai+j7oBSZG8Ws= Message-ID: <5e7e4be39deeedf52496f939cb4616a1066d5e10.camel@tugraz.at> Subject: Re: [C PATCH]: Add Walloc-type to warn about insufficient size in allocations From: Martin Uecker To: Siddhesh Poyarekar , gcc-patches@gcc.gnu.org Cc: Joseph Myers Date: Mon, 31 Jul 2023 22:06:44 +0200 In-Reply-To: <9a779b3b-f576-90db-ab86-efc53a264592@gotplt.org> References: <9a779b3b-f576-90db-ab86-efc53a264592@gotplt.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4-2 MIME-Version: 1.0 X-TUG-Backscatter-control: G/VXY7/6zeyuAY/PU2/0qw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.117 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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: Am Montag, dem 31.07.2023 um 15:39 -0400 schrieb Siddhesh Poyarekar: > On 2023-07-21 07:21, Martin Uecker via Gcc-patches wrote: > >=20 > >=20 > > This patch adds a warning for allocations with insufficient size > > based on the "alloc_size" attribute and the type of the pointer > > the result is assigned to. While it is theoretically legal to > > assign to the wrong pointer type and cast it to the right type > > later, this almost always indicates an error. Since this catches > > common mistakes and is simple to diagnose, it is suggested to > > add this warning. > > =20 ... > >=20 >=20 > Wouldn't this be much more useful in later phases with ranger feedback= =20 > like with the warn_access warnings? That way the comparison won't be=20 > limited to constant sizes. Possibly. Having it in the FE made it simple to implement and also reliable.=C2=A0 One thing I considered is also looking deeper into the argument and detect obvious mistakes, e.g. if the type in a sizeof is the right one. Such extensions would be easier in the FE. But I wouldn't mind replacing or extending this with something smarter emitted from later phases. I probably do not have time to work on this is myself in the=C2=A0near future though. Martin