llvm / llvm/llvm-project

[libc][math] Unsequenced access to volatile var in file __support/math/log1p.h

Open Beginner friendly
#217,998 4 comments 0 reactions 0 assignees View on GitHub
libc
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

When trying to improved -Wunsequenced by taking into account the volatile qualifier in PR
https://github.com/llvm/llvm-project/pull/180955 some tests failed.
The checker triggered in file libc/src/__support/math/log1p.h:
```c++
volatile float tp = 1.0f;
volatile float tn = -1.0f;
bool rdp = (tp - 0x1p-25f != tp);
bool rdn = (tn - 0x1p-24f != tn)
```
For C and C++ standards order of evaluate binary operator != is unsequence and unsequence access for same volatile variable is UB(because read volatile qualified variable is side-effects).

https://github.com/llvm/llvm-project/blame/main/libc/src/__support/math/log1p.h#L947

Contributor guide

Open the contributing guide

Research direction

Start at libc/src/__support/math/log1p.h around line 947 and inspect the volatile tp and tn comparisons shown in the issue. Reproduce the diagnostic using the -Wunsequenced checker changes from PR 180955, then update the affected code and relevant tests so the checker no longer reports unsequenced volatile access while the log1p behavior remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.