Re: [PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-23 Thread Dan Hoffman
I went ahead and wrote a clang-tidy pass that attempts to find other cases of this behavior (i.e. compile-time short-circuit behavior that could lead to undefined references). All of these cases should also be caught by `-Wunreachable-code`, but that uncovers a lot and I'd like a green light before

Re: [PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-21 Thread Dan Hoffman
>From their Discord server in reply to a question about whether such a patch would be upstreamed: "I suspect this only works in gcc -O0 because of its AST-level "fold", which clang intentionally doesn't implement. So probably not." I hope that's enough information to resolve this patch. If any of

Re: [PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-21 Thread Dan Hoffman
I'm writing a patch to clang's constant folding to address this case (doesn't seem too difficult). I'll either follow up with a link to some submissions I've made or a bug report on the project describing the issue. On Tue, Nov 21, 2023 at 10:15 AM Eric Blake wrote: > > On Mon, Nov 20, 2023 at

Re: [PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-21 Thread Eric Blake
On Mon, Nov 20, 2023 at 11:20:52AM +0100, Philippe Mathieu-Daudé wrote: > (Cc'ing Eric) > > On 20/11/23 10:28, Michael S. Tsirkin wrote: > > On Sun, Nov 19, 2023 at 07:34:58PM -0600, Dan Hoffman wrote: > > > As far as I can tell, yes. Any optimization level above O0 does not have > > > this > > >

Re: [PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-20 Thread Richard Henderson
On 11/20/23 02:20, Philippe Mathieu-Daudé wrote: (Cc'ing Eric) On 20/11/23 10:28, Michael S. Tsirkin wrote: On Sun, Nov 19, 2023 at 07:34:58PM -0600, Dan Hoffman wrote: As far as I can tell, yes. Any optimization level above O0 does not have this issue (on this version of Clang, at least) Ah

Re: [PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-20 Thread Philippe Mathieu-Daudé
(Cc'ing Eric) On 20/11/23 10:28, Michael S. Tsirkin wrote: On Sun, Nov 19, 2023 at 07:34:58PM -0600, Dan Hoffman wrote: As far as I can tell, yes. Any optimization level above O0 does not have this issue (on this version of Clang, at least) Aha, this is with -O0. That makes sense. But then,

Re: [PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-20 Thread Michael S. Tsirkin
On Sun, Nov 19, 2023 at 07:34:58PM -0600, Dan Hoffman wrote: > As far as I can tell, yes. Any optimization level above O0 does not have this > issue (on this version of Clang, at least) Aha, this is with -O0. That makes sense. We have: ;; --enable-debug) # Enable debugging options that a

Re: [PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-19 Thread Dan Hoffman
As far as I can tell, yes. Any optimization level above O0 does not have this issue (on this version of Clang, at least) On Sun, Nov 19, 2023 at 4:54 PM Philippe Mathieu-Daudé wrote: > Hi, > > On 19/11/23 21:31, Daniel Hoffman wrote: > > `kvm_enabled()` is compiled down to `0` and short-circuit

Re: [PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-19 Thread Philippe Mathieu-Daudé
Hi, On 19/11/23 21:31, Daniel Hoffman wrote: `kvm_enabled()` is compiled down to `0` and short-circuit logic is used to remove references to undefined symbols at the compile stage. Some build configurations with some compilers don't attempt to simplify this logic down in some cases (the pattern

[PATCH v3] hw/i386: fix short-circuit logic with non-optimizing builds

2023-11-19 Thread Daniel Hoffman
`kvm_enabled()` is compiled down to `0` and short-circuit logic is used to remove references to undefined symbols at the compile stage. Some build configurations with some compilers don't attempt to simplify this logic down in some cases (the pattern appears to be that the literal false must be the