Re: Avoid removing an if (false) statement and its corresponding branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for the reply, but the solution was right there all along...

if (volatile bool _ = false)

On Mon, Jul 24, 2023 at 12:53 AM David Brown <david.brown@xxxxxxxxxxxx>
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 = 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 PM Gabriel Ravier <gabravier@xxxxxxxxx>
> 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 = false;` somewhere and use it in
> >> place of `false`, when you want to avoid the if statement being
> >> optimized out.
> >>
> >>
> >
>
>




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux