-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang][analyzer] Teach the BlockInCriticalSectionChecker about O_NONBLOCK streams #127049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c916dad
[clang][analyzer] fix false positive of BlockInCriticalSectionChecker
flovent f2f9287
add new line
flovent 20bec01
update based on review advice
flovent edac8dc
use BugReportVisitor instead set
flovent 007baf9
NFC Rename a couple of things
steakhal 534201d
NFC More simplification
steakhal 10ec66c
NFC Remove trailing ws
steakhal a2bc110
NFC Simplify RUN line
steakhal 8dfeec8
NFC Add missing newline
steakhal c591851
Cleanup header simulator
steakhal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
clang/test/Analysis/Inputs/system-header-simulator-cxx-std-locks.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma clang system_header | ||
|
||
namespace std { | ||
struct mutex { | ||
void lock(); | ||
void unlock(); | ||
}; | ||
|
||
template <typename T> struct lock_guard { | ||
lock_guard(std::mutex &); | ||
~lock_guard(); | ||
}; | ||
} // namespace std |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// RUN: %clang_analyze_cc1 \ | ||
// RUN: -analyzer-checker=core,unix.BlockInCriticalSection \ | ||
// RUN: -analyzer-output text -verify %s | ||
|
||
// expected-no-diagnostics | ||
|
||
#include "Inputs/system-header-simulator-cxx-std-locks.h" | ||
|
||
std::mutex mtx; | ||
using ssize_t = long long; | ||
using size_t = unsigned long long; | ||
int open(const char *__file, int __oflag, ...); | ||
ssize_t read(int fd, void *buf, size_t count); | ||
void close(int fd); | ||
#define O_RDONLY 00 | ||
#define O_NONBLOCK 04000 | ||
|
||
void foo() { | ||
std::lock_guard<std::mutex> lock(mtx); | ||
|
||
const char *filename = "example.txt"; | ||
int fd = open(filename, O_RDONLY | O_NONBLOCK); | ||
|
||
char buffer[200] = {}; | ||
read(fd, buffer, 199); // no-warning: fd is a non-block file descriptor or equals to -1 | ||
close(fd); | ||
} | ||
|
||
void foo1(int fd) { | ||
std::lock_guard<std::mutex> lock(mtx); | ||
|
||
const char *filename = "example.txt"; | ||
char buffer[200] = {}; | ||
if (fd == -1) | ||
read(fd, buffer, 199); // no-warning: consider file descriptor is a symbol equals to -1 | ||
close(fd); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.