From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from frog.ash.relay.mailchannels.net (frog.ash.relay.mailchannels.net [23.83.222.63]) by sourceware.org (Postfix) with ESMTPS id 375083858C31 for ; Fri, 17 Feb 2023 12:53:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 375083858C31 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 3C605640B20; Fri, 17 Feb 2023 12:53:26 +0000 (UTC) Received: from pdx1-sub0-mail-a305.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id A1593641582; Fri, 17 Feb 2023 12:53:25 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1676638405; a=rsa-sha256; cv=none; b=7aUUUnKzDOSl1B0RcblfRbvOl6NPgvNXmksP1LNG4S0p5+m1/MSR7FumUcv9o7USdhHI4w kbWQCXs797JwVNDcaCmn9EE2FfYylJMLQvWT9FKhK/9f36yC7Qa/E1h+Oi9UrU4eu0VPcN kmBtfHeKDEK4AWClVHj2H94ShBuFVa4MiRx5YIzRrIKdV/dRJZigqnOaqNel7EhYb8Bkh6 aAojQJU+vsFlqXJlMbLh4Wf/lMt5/aqcrJAMzsJRsyRTxPd6TcYab08Yh/vTrmdifrHeyR 3fQlHhho+WFTnLpweUpJsNZfq8m+H24ceg5ZWQNjsWZsP5rA756QlxIbTvbAsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1676638405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=h+3YZt4Lb/dZWmd8UrkoBf32ol3scMe1wQnRNdY830k=; b=0WJRYAAYh1YgfWGcUXpxzMR0oz7QzlI9C9H5QHszsMsRA9ocya8fobm+UWs8XKK8DFckRK wE1Oz0gyB6rifrMzEQQIke6MqLI+jFThQwpH4HAmf2GTy3AAOpuE5WQTMUOY8J3A8mkKYZ mTjupVYGUvxcD+FGwZLnv8sBzA/OZrgk4CxYhPBcThbpW2Ho4T3pS42uabOsLoYkd7cAnv Zhzs7INcBroIRpgXg1Fqv5j2uGSNeN8L/syoFVUPSbQeIq3lOn2yaLWTcG2oqnV3pmQnyc g+URpUDrrUh2SixPBw+2Bb1e5TaFGHijDglji1UrhY/V5smwxkSXGDlww2FoCA== ARC-Authentication-Results: i=1; rspamd-b9c55767f-5dvsx; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Shrill-Macabre: 2d5bc2be7374fac2_1676638405926_4241832038 X-MC-Loop-Signature: 1676638405926:33578191 X-MC-Ingress-Time: 1676638405925 Received: from pdx1-sub0-mail-a305.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.109.138.42 (trex/6.7.1); Fri, 17 Feb 2023 12:53:25 +0000 Received: from [192.168.0.182] (bras-vprn-toroon4834w-lp130-09-174-91-45-59.dsl.bell.ca [174.91.45.59]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305.dreamhost.com (Postfix) with ESMTPSA id 4PJBZD6FbQz8J; Fri, 17 Feb 2023 04:53:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gotplt.org; s=dreamhost; t=1676638405; bh=smS/OdnPERiq2J/jtY1BcRaWcFpqlfTQ46rrltJ8V+U=; h=Date:Subject:To:Cc:From:Content-Type:Content-Transfer-Encoding; b=Xtn6YpeqcuCXC7XjQ6sapoJXKNeY1OZ9PxRzwubs0RAVHOUeJVbGdIRP3bnv68ucq /yhso9aVww+D0epJxLvSrUdRQLZ69Wf27HdPEEHi8HGVv5NK2fyOlRGP+rUtiKkq1P TRDg9qFuq3oXgNtphFMinX96StqgbCFuFbOlhPa/A+CGYnrz/4zVyWWbIUVrRPKPmy VrC8I8JSfwncghu7+upWiT+U2Hd0zbK1MvnUGUlxhIrkBK1OVF8yOz5AtC51/oDbxr 7gWHLOPSkcDaIq1vA6NUSj5rJKbeSKXsZK1bBxciV4HUc2csueYjcnFshnNiKRWdJL HWBmhHWzXN4Lg== Message-ID: Date: Fri, 17 Feb 2023 07:53:23 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: Missed warning (-Wuse-after-free) Content-Language: en-US To: Jonathan Wakely Cc: David Malcolm , Alejandro Colomar , GCC , Iker Pedrosa References: <8ed6d28c-69dc-fed8-5ab5-99f685f06fac@gmail.com> <38e7e994a81d2a18666404dbaeb556f3508a6bd6.camel@redhat.com> From: Siddhesh Poyarekar In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3030.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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: On 2023-02-17 06:24, Jonathan Wakely wrote: > Please be aware that in C++ it's implementation-defined, not undefined. > > That means that an implementation without trap representations for > pointers can choose to make it behave just like using (uintptr_t)p. > > https://cplusplus.github.io/CWG/issues/1438.html > > https://cplusplus.github.io/CWG/issues/623.html > > https://cplusplus.github.io/CWG/issues/616.html > > https://cplusplus.github.io/CWG/issues/312.html > > > We could still warn in C++ (because the code isn't portable) but I would > strongly suggest we don't influence C++ codegen based on deallocated > pointers being undefined. I don't think gcc supports any targets with > trapping pointers, and there are quite enough sources of UB already. We > don't need to create traps for users where there are no traps for > pointers :-) The codegen problem is a pointer provenance issue and AFAICT, -Wuse-after-free=3 is also framed in that context and not as a problem with simply taking the numeric value of the pointer to, e.g. log it somewhere. More concretely, something like this is what causes problems: Foo *old = malloc (sz); ... Foo *new = realloc (old, newsz); if (new != old) { old = new; /* Adjust references. */ } /* Otherwise continue using old unchanged */ ... The problem is the assumption that the old pointer continues to be valid because it has the same numeric value as the new one. This is not an uncommon code pattern in C, what about C++? On a fat pointer-like scheme such as the Arm Morello cpu, this won't work at all because even though old and new have the same numeric values, old will have been invalidated. Sid