llvm / llvm/llvm-project

Initialization of union not raise expected FPU flag

Open
#166,866 1 comment 0 reactions 0 assignees View on GitHub
clang:codegen floating-point
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```c
#include
#include
#include
#include
#include
#include
#include
#include /* glibc 2.41-11 */

#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){
feclearexcept(FE_ALL_EXCEPT);
errno = 0;
if(1){
union { float f32; int i; } uf0 = { 0.F / 0.F };
int flags;
flags = fetestexcept(FE_ALL_EXCEPT);
assert( 0 == errno );
assert( isnan( uf0.f32 ) );
assert( 0 != flags ); /* fails here */
assert( FE_INVALID == flags );
}
return 0;
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the C reproducer in the issue and compile and run it with LLVM to confirm the missing exception flag. Investigate how union initialization interacts with floating-point environment semantics; done means the reproducer observes FE_INVALID and its existing assertions pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.