llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

bool bitfield += complex gets infinite loop

Open tydeman opened this issue 1 year ago • 6 comments

The following code gets an infinity loop at runtime.

#include <assert.h>	/* assert */
#include <stddef.h>	/* offsetof */
#include <float.h>	/* FLT_SNAN */
#include <complex.h>	/* FLT_CMPLX */
#include <wchar.h>	/* wchar_t */
#include <stdio.h>	/* printf */
int main(void){
  if(1){
    struct bit2 {
      unsigned int uibf : 7;
        signed int sibf : 7;
              bool bobf : 1;
    } bits = { 1u, 1, 1 };
    struct bit2 res;
    res.bobf = bits.bobf += CMPLXF( 1.5f, 1.5f );
  }
  return 0;
}

tydeman avatar Oct 13 '25 08:10 tydeman

I failed to reproduce the bug on Compiler Explorer. Could you provide a link to a reproducing example?

frederick-vs-ja avatar Oct 13 '25 08:10 frederick-vs-ja

I also failed to reproduce this one: https://godbolt.org/z/nTz8vdWcY

AaronBallman avatar Oct 13 '25 12:10 AaronBallman

@llvm/issue-subscribers-clang-frontend

Author: Fred Tydeman (tydeman)

The following code gets an infinity loop at runtime.
#include &lt;assert.h&gt;	/* assert */
#include &lt;stddef.h&gt;	/* offsetof */
#include &lt;float.h&gt;	/* FLT_SNAN */
#include &lt;complex.h&gt;	/* FLT_CMPLX */
#include &lt;wchar.h&gt;	/* wchar_t */
#include &lt;stdio.h&gt;	/* printf */
int main(void){
  if(1){
    struct bit2 {
      unsigned int uibf : 7;
        signed int sibf : 7;
              bool bobf : 1;
    } bits = { 1u, 1, 1 };
    struct bit2 res;
    res.bobf = bits.bobf += CMPLXF( 1.5f, 1.5f );
  }
  return 0;
}

llvmbot avatar Oct 13 '25 12:10 llvmbot

System is: Intel Core i5 x86_64 running Fedora Linux 42

Command line flags:

# flags common to both compiler and linker
export CLFLAGS="-g \
 -fsanitize=memory \
 -fsanitize=undefined \
 -fno-sanitize=float-cast-overflow \
 -fno-sanitize=float-divide-by-zero"
# -fsanitize=address added 2019/04/28 => kills compile; not w/ memory
# flags for compiler
export CFLAGS="-H -std=c23 -m64 -mfpmath=sse -msse2 -pedantic -O0 \
 -fno-fast-math \
 -fdenormal-fp-math=ieee \
 -fstrict-float-cast-overflow \
 -fmath-errno \
 -ftrapping-math \
 -ffp-contract=on \
 -fhonor-infinities \
 -fhonor-nans \
 -fsigned-zeros \
 -fno-associative-math \
 -fno-reciprocal-math \
 -fno-unsafe-math-optimizations \
 -fno-finite-math-only \
 -frounding-math \
 -ffp-model=strict \
 -ffp-exception-behavior=strict \
 -Xclang -disable-llvm-optzns ${INCS}"

glibc: glibc.x86_64 2.41-11.fc42 updates gcc: gcc.x86_64 15.2.1-1.fc42 updates llvm: llvm.x86_64 20.1.8-4.fc42 updates clang: clang.x86_64 20.1.8-4.fc42 updates

tydeman avatar Oct 13 '25 22:10 tydeman

Clang crashed with -fsanitize=undefined: Godbolt link. Not sure whether that is the same issue.

frederick-vs-ja avatar Oct 14 '25 01:10 frederick-vs-ja

The issue was additionally reported for *= and /= - lets track everything in the same place

cor3ntin avatar Oct 15 '25 08:10 cor3ntin