From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 808A13850409 for ; Fri, 17 Feb 2023 12:05:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 808A13850409 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x534.google.com with SMTP id i28so2906943eda.8 for ; Fri, 17 Feb 2023 04:05:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=hpSIyNpg+dM3aLxgfaTzC8j4mZ7UkJecXQcgFUK4A50=; b=IF7cqtN56CnVxhziVJkq94S8BaYSpHFn67DfSTJv1pFO4PoQ+72kTKKrsV8q4LJPSy /397/5zkhNTrtUb6A/cVF2lpLrzMOs0HqE5FcFke0lYIB7wxD6xZ7BwCvpoNghwbuNtn dG1s44VIH0xQlacFg0dJmcS8LOi4RhjFV1MK0GHAmenzd0d6lcenS39BmJqVYmL4G316 jMVl/viR9jKsPPT5Y2t1U33WFKbkZMb/LXPrsa9QD5NMqF9kEEmzZkeFpGX9tIsSPEIx zhNs9+/INOz+sO+OLPwdS5LMjDoDxUVCrJcBl3bnfvNp6ZI13MAo6JJdfDtbU5OB+s9n 8+ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hpSIyNpg+dM3aLxgfaTzC8j4mZ7UkJecXQcgFUK4A50=; b=UduYYtrooeIHGNh3E5NDD7AtiQJM0b5BqV/QmlLIezDIy8mLMHXcutZjJIkm86UYLQ aL+RCr2dM77+1iTR2ZS20OMXqtAf+/zLR++r3RJ4gb3Pr9NFOuntWAudjniPimwRoZcN P2WyIHS/4v/9r9Icr9mLDpTW2Ffc+6OndMEaAgoutbA6l50VNWa0m3fFxK/kVRMP3vao OHmWZOvo9Ww6ywA0DCYg44BUptsD9Y+qkMaMx93FYLtRMeNV9j9BD+3Eihp45zUDoJON DdukulaiTNHHr01Pyv+ALlVhZjyvawZ4bNxw2R2e1meDarZDQCQ/VjAYmh02U8exAm9U bnTQ== X-Gm-Message-State: AO0yUKWZu4fSO7xhMxFlRqudmTr1YpzgP0Q+ez3dnX5+CiVc7BeKM428 UE8IDLmiYpCZXUBPt2XitPjslM5p0E+g2WzYUjQ= X-Google-Smtp-Source: AK7set/sMs8v6gFtxQdWyDyChhb34hXg8MkP5+PvjwFs5sXpNGFHIt8rBEFcI3aIhklQFm9CNt4bzAGbkyNnMR+shBc= X-Received: by 2002:a50:d0d7:0:b0:4ab:c702:65a with SMTP id g23-20020a50d0d7000000b004abc702065amr624464edf.5.1676635503314; Fri, 17 Feb 2023 04:05:03 -0800 (PST) MIME-Version: 1.0 References: <8ed6d28c-69dc-fed8-5ab5-99f685f06fac@gmail.com> <38e7e994a81d2a18666404dbaeb556f3508a6bd6.camel@redhat.com> <6aaff906-1c3b-c625-7d5c-68c56583257d@gmail.com> In-Reply-To: <6aaff906-1c3b-c625-7d5c-68c56583257d@gmail.com> From: Jonathan Wakely Date: Fri, 17 Feb 2023 12:04:50 +0000 Message-ID: Subject: Re: Missed warning (-Wuse-after-free) To: Alejandro Colomar Cc: David Malcolm , GCC , Iker Pedrosa , Siddhesh Poyarekar , Florian Weimer , Sam James , Paul Eggert , Michael Kerrisk , Martin Uecker , =?UTF-8?B?SuKCkeKCmeKCmyBHdXN0ZWR0?= , Yann Droneaud Content-Type: multipart/alternative; boundary="00000000000097c90205f4e41fbc" X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,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: --00000000000097c90205f4e41fbc Content-Type: text/plain; charset="UTF-8" On Fri, 17 Feb 2023, 11:43 Alejandro Colomar, wrote: > Hi Jonathan, > > On 2/17/23 12: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. > > (uintptr_t)p is defined (I believe) for C <= C17. However, as noted in my > last email, even that is UB for C2x. Of course, UB means that the compiler > might make it defined, but as Martin suggested, that's might have its own > issues. > Yes, I just meant in C++, and C++ has no such rules. > > > > 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 > > :-) > > I would warn in C++ too, as some of that code might be in interfaces that > should be compatible with C. Maybe not include it in -Wextra in C++ (but > include it in C's -Wextra)... > I agree with warning in C++, just not optimizing based on the assumption that any use of an invalid pointer implies unreachable code (as in your original example). --00000000000097c90205f4e41fbc--