> From: Mattias Rönnblom [mailto:hof...@lysator.liu.se]
> Sent: Sunday, 13 October 2024 17.20
> 
> On 2024-10-13 15:37, Morten Brørup wrote:
> >> From: Mattias Rönnblom [mailto:mattias.ronnb...@ericsson.com]
> >> Sent: Sunday, 13 October 2024 13.57
> >>
> >> The macros generating the parallel test for atomic test-and-
> >> [set|clear|flip] functions used a 64-bit reference word when
> assuring
> >> no neighbouring bits were modified, even when generating code for
> the
> >> 32-bit version of the test.
> >>
> >> This issue causes spurious test failures on GCC 12.2.0 (the default
> >> compiler on for example Debian 12 "bookworm"), when optimization
> level
> >> 2 or higher are used.
> >>
> >> The test failures do not occur with GCC 11, 12.3 and 13.2.
> >>
> >> To the author, this looks like a promotion-related compiler bug in
> GCC
> >> 12.2.
> >
> > I am curious about the compiler bug...
> >
> > Did the bug occur when the most significant bit was set, so it sign
> related?
> >
> 
> It seems to happen a lot more often than 1/32 times. Also, all involved
> types are unsigned.

OK. I was speculating that the compiler bug might be treating an unsigned as a 
signed, and somehow sign extending the most significant bit of a negative value 
into the higher bits when converting the type to a bigger type.

> 
> If you set the optimization level to "1" (i.e.,
> __attribute__((optimize("O"))) on the
> test_bit_atomic_parallel_test_and_modify32 function, the test passes on
> 12.2.0.
> 
> > Maybe this will reveal something:
> >
> > TEST_ASSERT(expected_word == word,
> >    "Untouched bits have changed value, %" PRIx ## size
> >    " should be %" PRIx64,
> >    word, expected_word);
> >
> 
> Confusingly enough, the failing assertion is the one prior that
> assertion.

Ahh... I misread your "promotion" suspicion as "type promotion", not 
instruction reordering.

> 
> >>
> >> Fixes: 35326b61aecb ("bitops: add atomic bit operations in new API")
> >>
> >> Signed-off-by: Mattias Rönnblom <mattias.ronnb...@ericsson.com>
> >> ---
> >
> > I took a deep look into this.
> >
> > Regardless of what the compiler bug is,
> >
> > Reviewed-by: Morten Brørup <m...@smartsharesystems.com>
> >
> 
> Thanks.
> 
> I'm far from sure it's a compiler bug. Just look at the base rate: how
> often does the code you just wrote fail because of a bug in your code,
> and how often is the root cause to be found in the compiler or the
> standard libraries.
> 

A strong argument for rootcausing exactly what the specific compiler gets wrong 
when compiling the code triggering the error.

Reply via email to