Issue 233953
Summary [scan-build] False positive unix.BlockInCriticalSection for std::weak_ptr::lock
Labels new issue
Assignees
Reporter rubidium42
    First found using `Debian clang version 19.1.7 (3+b1)`, later reproduced using `clang version 23.1.4 (https://github.com/llvm/llvm-project 7a941dfb2877a0b8cf30323fefa85ad019e0b0f5)` (https://github.com/llvm/llvm-project/releases/tag/llvmorg-23.1.4).

The reduced test case code below triggers the following false-positive:
```
test.cpp:8:15: warning: Call to blocking function 'fgets' inside of critical section [unix.BlockInCriticalSection]
    8 | char *x = fgets(buffer, sizeof(buffer), stdin);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```

```c++
#include <memory>
#include <cstdio>

int main() {
    std::weak_ptr<int> ptr;
    char buffer[2048];
    ptr.lock();
 fgets(buffer, sizeof(buffer), stdin);
    return 0;
}
```

Expected result is no warning. I *hope* that `std::weak_ptr::lock` leaves no new critical section open after its call (it might open and close one inside the function).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to