Clang 22 Static Analyzer misdetects criticial section for std::unique_locks
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Version: clang version 22.1.6 with GNU libstdc++ 15.3.0 / openSUSE Tumbleweed x86_64 20260615
Input:
```c++
#include
#include
int main()
{
std::mutex m;
std::unique_lock lg(m);
lg.unlock();
sleep(1);
}
```
Observed output:
```
>clang++ 1.cpp -Wall --analyze
warning: Path diagnostic report is not generated. Current output format does not support diagnostics that cross file boundaries. Refer to --analyzer-output for valid output formats
1.cpp:9:2: warning: Call to blocking function 'sleep' inside of critical section [unix.BlockInCriticalSection]
9 | sleep(1);
| ^~~~~~~~
1 warning generated.
```
Expected output:
Stay silent. The sleep occurs outside the locked section.
Contributor guide
Research direction
Reproduce the report with the shown 1.cpp input using clang++ 1.cpp -Wall --analyze and observe the unix.BlockInCriticalSection warning after unique_lock::unlock(). Start by tracing the static analyzer's handling of std::unique_lock and unlock; done means the sleep call outside the locked section no longer produces this warning, with regression coverage for the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100