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

#pragma STDC FENV_ROUND FE_TONEAREST gives misleading warning

Open tydeman opened this issue 11 months ago • 6 comments

The statement: #pragma STDC FENV_ROUND FE_TONEAREST

Gets: warning: expected identifier in '#pragma FENV_ROUND' - ignored [-Wignored-pragmas] which is misleading.

  1. The 'STDC' got dropped in the message.
  2. FE_TONEAREST is a valid 'direction' as per the C standard.

If the pragma is not supported, the warning should say so. If the pragma is supported, there should be no warning.

tydeman avatar Dec 19 '25 20:12 tydeman

I see the following (https://godbolt.org/z/P4Woh3z8Y):

<source>:1:38: warning: pragma STDC FENV_ROUND is not supported [-Wunknown-pragmas]
    1 |  #pragma STDC FENV_ROUND FE_TONEAREST
      |                                      ^
1 warning generated.
Compiler returned: 0

Can you give reproduction steps or a godbolt link?

efriedma-quic avatar Dec 19 '25 21:12 efriedma-quic

Here is the program:

#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){ return 0; }

Here are the 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}"

tydeman avatar Dec 19 '25 22:12 tydeman

Happens only if <fenv.h> is included first because it #defines FE_TONEAREST.

Minimal reproducer (https://godbolt.org/z/E5cbPrebe):

#define FE_TONEAREST    0
#pragma STDC FENV_ROUND FE_TONEAREST

keinflue avatar Dec 20 '25 09:12 keinflue

@efriedma-quic @keinflue I’d like to work on this issue.

Vinayak-RZ avatar Dec 30 '25 11:12 Vinayak-RZ

@Vinayak-RZ I do not have the ability to assign issues. However, you can suggest a PR or ask questions without being assigned.

keinflue avatar Dec 30 '25 18:12 keinflue

@Vinayak-RZ I do not have the ability to assign issues. However, you can suggest a PR or ask questions without being assigned.

We don't assign issues until you have a PR and we have verified that it looks like it is moving in the right direction.

shafik avatar Dec 30 '25 18:12 shafik