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);

  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.

Reply via email to