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

static float f = 0.f / 0.f; will not compile

Open tydeman opened this issue 11 months ago • 5 comments

static float f = 0.f / 0.f; will not compile with clang 21.1.7 (and others) on Linux on Intel x86_64

It should be a quiet NaN.

tydeman avatar Dec 19 '25 20:12 tydeman

It does seem to compile on both clang trunk: https://godbolt.org/z/P5qdqdfo9 and 21.1.0. Please be more specific.

Thibault-Monnier avatar Dec 19 '25 23:12 Thibault-Monnier

#include <assert.h>
#include <limits.h>
#include <errno.h>
#include <stdio.h>
#include <float.h>
#include <fenv.h>
#include <complex.h>
#include <math.h>

#pragma STDC FENV_ACCESS ON
#pragma STDC FP_CONTRACT OFF
#pragma STDC FENV_ROUND FE_TONEAREST
#pragma STDC FENV_DEC_ROUND FE_DEC_TONEAREST
#pragma STDC CX_LIMITED_RANGE OFF

int main(void){

  if(1){
    static float f27 = 0.f / 0.f;/* cannot compile this constant l-value expression yet */
  }
  return 0;
}

with command line options:

# 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"
# 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}"

Fedora Linux 43, Intel i5 x64, clang Fedora 21.1.7-1.fc43

tydeman avatar Dec 20 '25 01:12 tydeman

Reproduce: https://godbolt.org/z/3MosvdqWa , std=c23 error it.

hstk30-hw avatar Dec 20 '25 03:12 hstk30-hw

How is this different from https://github.com/llvm/llvm-project/issues/161806?

tbaederr avatar Dec 20 '25 06:12 tbaederr

Which is itself a duplicate of #101499

Thibault-Monnier avatar Dec 20 '25 09:12 Thibault-Monnier