From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by sourceware.org (Postfix) with ESMTPS id 35E3F3857713 for ; Tue, 25 Jul 2023 05:53:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35E3F3857713 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-qt1-x829.google.com with SMTP id d75a77b69052e-403cb525738so44389761cf.2 for ; Mon, 24 Jul 2023 22:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690264391; x=1690869191; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=vTh9RMqEnHNf08DeOQZ3c4LX9lAotCINu//p3ogRjsA=; b=mWNoUXpXt6ga2+fYuqwswpmUAj1GSJEgiWEmhqyUMVPB4E7EH0i7NTib8HfbdDZYcs +r+DbRTQWrSfAMFBKjjYs/DgipfRt0/OBMebIZSC/TybrQt0owTVuCRf3U75XqpP0vet tan5X8/HjgWC+6JwcTrBXQVuhx0fGIZeWWYPlCsc0364R0nDHGOxgCvAw5VwxJj8ob1R rwjeuW5H1xc41LwS+piBReP+tLgdGWZEyIvQjuO54B0vuB4mSM7Ozew2FOOJXU9aU83g +lIyxB8YVl4QIURYgGkQzwNEyPfUDAKKEu2HHxoTOF+nBCCbYaY/Ujg9uPVWphAH8g4u WNLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690264391; x=1690869191; h=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=vTh9RMqEnHNf08DeOQZ3c4LX9lAotCINu//p3ogRjsA=; b=PpO4Q+PyGyCZhzV0gEfrS+oHNCkhNkcGoKJFtC8hDtULDrCXW4ez+9muSK38ZhjTcg j0IegJ9GIvhl1dTAGFuRI8/JoOfcIc3bS5uzymkIpwSt4apUTWeh9d7lJh5li/wG0bmM No+9nbAz7WlgARz/gDYBEr3KcYBnmqLO+g5uCSb2m4LcEvmz6ZU2o3jYzKYuaEuTQ8Lz hW3aQN7kO2mXfdxtSxZQMf1exN9qkHB7PPe4fbDyAQWvU4wv/m00BcuJ7yDzXK6xzu19 L0Id2ZLV57MofB9K61Z1tLFiJJ95KFyv5+EKU9t0msa/TqOurSBPUScUtCEnvqI/hbid S+0Q== X-Gm-Message-State: ABy/qLaPEssGIw0SF89aKyejZD/Sn7ZjdEj1+Jt5sbuJx2HXLEuQirqM BO6n+UsTbymqvo52taiycRzfRvgRotgh+/gNzU8= X-Google-Smtp-Source: APBJJlEX/JrH6hK99KkdJ1wl+hrqZKns8yZvrn+96zH8p4KhA2NJkhTq7aNbwyZBdkywKdKcxBb8yw8YJW9XgoMnMWg= X-Received: by 2002:ac8:5c07:0:b0:403:aa49:606e with SMTP id i7-20020ac85c07000000b00403aa49606emr1934080qti.30.1690264391266; Mon, 24 Jul 2023 22:53:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Julian Waters Date: Tue, 25 Jul 2023 13:52:31 +0800 Message-ID: Subject: Re: Avoid removing an if (false) statement and its corresponding branch To: David Brown , gcc-help@gcc.gnu.org Content-Type: multipart/alternative; boundary="0000000000009e36b2060149581f" X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,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: --0000000000009e36b2060149581f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for the reply, but the solution was right there all along... if (volatile bool _ =3D false) On Mon, Jul 24, 2023 at 12:53=E2=80=AFAM David Brown wrote: > On 23/07/2023 16:27, Julian Waters via Gcc-help wrote: > > I just tried it and it does work, even on O3, however I would like to > avoid > > allocating a variable if possible. It's a shame that gnu::used doesn't > > seem to work with if statements (If anyone knows where to look in the > > source code do tell me). But thanks for the suggestion nonetheless! > > > > How about: > > static inline bool False(void) { > bool b =3D false; > asm volatile("" : "+r" (b)); > return b; > } > > Then use "if (False()) ..." instead of "if (false) ...". > > The generated overhead is going to be minimal, and no volatile variables > are created. It's also quite cool (IMHO) to have 100% portable inline > assembly! > > mvh., > > David > > > > > best regards, > > Julian > > > > On Sun, Jul 23, 2023 at 10:14=E2=80=AFPM Gabriel Ravier > wrote: > > > >> On 7/23/23 14:45, Julian Waters via Gcc-help wrote: > >>> Hi all, > >>> > >>> Is there a way to stop gcc from nuking an if (false) statement and the > >>> corresponding branch from the compiled code for debugging purposes? > >>> Even turning off all optimizations doesn't achieve this > >>> > >>> best regards, > >>> Julian > >> > >> IMO the simplest way would be to define something like `static const > >> volatile bool unoptimizable_false =3D false;` somewhere and use it in > >> place of `false`, when you want to avoid the if statement being > >> optimized out. > >> > >> > > > > --0000000000009e36b2060149581f--