On Thu, Aug 24, 2023 at 8:06 PM libreknight via Gcc-bugs <gcc-bugs@gcc.gnu.org> wrote: > > Greetings. > > I have come across erroneous behavior whilst comparing optimizations > performed by different compilers. Said behavior persists through > different versions of GCC and flags. The output from GCC is incorrect > and diverges from all compilers. > > In order to reproduce aforementioned behavior, compile with any flags of > your liking the following code: > > #include <stdio.h> > #include <stdlib.h> > > typedef struct > { > unsigned char value:1; > } boolean; > > int > main (void) > { > boolean var; > > var.value = 0; > > printf ("%d %d\n", --var.value, --var.value);
GCC does produce a warning: <source>: In function 'main': <source>:16:35: warning: operation on 'var.value' may be undefined [-Wsequence-point] 16 | printf ("%d %d\n", --var.value, --var.value); | ^~~~~~~~~~~ Anyways the order of evaluation is not specified in the C standard when it comes to function arguments; left to right or right to left is both valid. Thanks, Andrew Pinski > > return EXIT_SUCCESS; > } > > The outcome disparates from the expected by producing the opposite > result. > > GCC: > 0 1 > > clang, tcc, icc, icx, msvc, compcert: > 1 0 > > Inasmuch as the potential consequences of faulty logic allows for > undefined behavior, security vulnerabilities emerges. Nevertheless, > acknowledging the atypicality of causal application, I evaluate the > significance of low-medium priority. > > Thanks in advance.