bool bitfield += complex gets infinite loop
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;
}
I failed to reproduce the bug on Compiler Explorer. Could you provide a link to a reproducing example?
I also failed to reproduce this one: https://godbolt.org/z/nTz8vdWcY
@llvm/issue-subscribers-clang-frontend
Author: Fred Tydeman (tydeman)
#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;
}
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
Clang crashed with -fsanitize=undefined: Godbolt link. Not sure whether that is the same issue.
The issue was additionally reported for *= and /= - lets track everything in the same place