From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 913043858C30 for ; Mon, 20 Feb 2023 14:52:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 913043858C30 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-wm1-x334.google.com with SMTP id p3-20020a05600c358300b003e206711347so1088721wmq.0 for ; Mon, 20 Feb 2023 06:52:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=1Jv6rDCBDqw6vEcQF4xMyUGCnAjFlAYC7gk0dKzD1Gc=; b=bl9Bpz6xnMave7G7IXphwnchPhtGrSwCs7wCzjezmBSZAo3XPdGsAdqf5EHTPG5TsR UtKFUDS7KCamb56Nr/ib4qNJP0F4jYTGZiOMtFhMIMwmLUcUrWCVbQ5ouwkj3OuKSjb5 hHlPFrx02uaM7xgtSTJ+EG4v5I+SkxuoLippFkEQENt0jgxoXVNHQgAevV1PXXOsTb6g MW3jaMRvVtRL6mqKUbA+98Ggas8lfJ2+PWaHbAX+MV7Ip8NF4QQqla2RHAMEvM82bAX+ Oea6/Cqid/KzNJuSSykB4Zb56LyPfpUTJU4YQg6RRJq+01xEX4u00bYllwpqzGoAEjZ0 Iv8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1Jv6rDCBDqw6vEcQF4xMyUGCnAjFlAYC7gk0dKzD1Gc=; b=2ADNb06lnkmp2lSqmfZ8CSQnPY9lOjLwKKelhmCeXbbt2MKqdfcfOabQCnUwnsZg5o 8ESAL2OZvFpOw8IiF46E1Ix7oOTOjtQHJCeE8JAc++ctU2LRisBq2n/SEg3cvL8ayS0C l4MhF22SFLr5WwzrhfAhLqLhLX/7FOzQjKBuSmFnzPbwpZwZmKlZbzfgAPkFfW6jjC5Q YaFiY126tMJppjHOkw3DpdY2T1B4wIZy+BQmelX8jFXEjq/dp/yxLm0J6XvvE5/s9VEo 3a3W2ePTkq64sl4uURnMaA3eV0g/8+EBo3Zhh2s/orQGE9Q+yCtPiozek0FLi8m/P3gW Wazw== X-Gm-Message-State: AO0yUKVZ8nD/mevV3vvQmhyVvhz4ma7k7EF3w3Zak7vehRacHh8WiRe0 NnESgxRC7f1OIRht8XvD+Vg= X-Google-Smtp-Source: AK7set9ZoOp5zTuI1VWwY3HdgClPiYHoWVsIFUATe86gYBBn3c3w0avWj+MeJk9lyVShAqb8Iu1ZKw== X-Received: by 2002:a05:600c:1818:b0:3e2:1fa5:98de with SMTP id n24-20020a05600c181800b003e21fa598demr683898wmp.30.1676904754105; Mon, 20 Feb 2023 06:52:34 -0800 (PST) Received: from [10.30.0.6] (190-2-138-15.hosted-by-worldstream.net. [190.2.138.15]) by smtp.gmail.com with ESMTPSA id n15-20020a05600c3b8f00b003e224ff61a8sm519451wms.43.2023.02.20.06.52.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Feb 2023 06:52:33 -0800 (PST) Message-ID: Date: Mon, 20 Feb 2023 15:50:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: std::string add nullptr attribute To: Segher Boessenkool , Marc Glisse via Gcc-help Cc: Marc Glisse , Xi Ruoyao , Jonathan Wakely , Jonny Grant References: <6b530d67-723a-a0c9-15bc-12b7341653a7@jguk.org> <96f99315a6ffd3dd3919b23a4ade2597747a580a.camel@xry111.site> <1e62a6f51b748454abe88438f2040486722c5803.camel@xry111.site> <7e54f0b6-0c58-e340-46a3-b46fa321a201@inria.fr> <20230220112838.GO25951@gate.crashing.org> Content-Language: en-US From: Gabriel Ravier In-Reply-To: <20230220112838.GO25951@gate.crashing.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_ABUSEAT,RCVD_IN_BARRACUDACENTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: *** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2/20/23 12:28, Segher Boessenkool wrote: > On Mon, Feb 20, 2023 at 12:18:36PM +0100, Marc Glisse via Gcc-help wrote: >> On Mon, 20 Feb 2023, Gabriel Ravier via Gcc-help wrote: >> >>> This is the kind of thing that makes me wonder why there isn't some kind >>> of `__builtin_unreachable_do_not_optimize()` builtin that allows one to >>> mark places in code that should never be reached and should thus be warned >>> about if such a thing happens while at the same time never doing any >>> optimization on the basis of the presence of the call. >> -fsanitize=unreachable -fsanitize=null and others prevent the kind of >> optimization you are worried about. > Or even just __builtin_trap(), or abort(), or similar. Just a printf() > thing if you really want to just warn. > > "Never doing any optimisation" based on is of course not a > reasonable expectation; but you *can* ask for reachable code not to be > optimised away. This is the default, just don't mark reachable code as > unreachable :-) > > > Segher What I mean is that it would be nice to have a builtin that has the same effect as a `*(char *)0 = 0` in that the compiler will warn you if it thinks code execution will reach it, except that it should do do nothing else. `*(char *)0 = 0` is a really bad solution in that regard because while it will result in the compiler emitting a warning, it will also result in actual undefined behavior that can crash the program or get optimized out. `__builtin_trap` and `abort` are also equally bad in that they result in visible behavior at runtime, which is equivalently bad if you solely want a warning and nothing else (also, as far as I know, GCC will not emit a warning on the basis that they are reached either, so they're completely useless if one's goal is to get a build-time warning). Something that seems instead quite useful would be some kind of builtin that would result in a warning if GCC thinks code execution will reach it, while having absolutely no other effect on code generation or execution (i.e. no optimization, no trap, no abort, no nothing), which neither deliberate UB nor calls to functions like `abort` or `__builtin_trap` will result in.