-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[sanitizer] Fix asserts in asan and tsan in pthread interceptors. #75394
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
goussepi
merged 1 commit into
llvm:main
from
goussepi:pthread_join-interceptors-crash-fix
Jan 11, 2024
Merged
Changes from all commits
Commits
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 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
This file contains 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
This file contains 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
This file contains 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
47 changes: 47 additions & 0 deletions
47
compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_join_invalid.cpp
This file contains 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,47 @@ | ||
// RUN: %clangxx -pthread %s -o %t | ||
|
||
// RUN: %env_tool_opts=detect_invalid_join=true not %run %t 0 2>&1 | FileCheck %s | ||
// RUN: %env_tool_opts=detect_invalid_join=true not %run %t 1 2>&1 | FileCheck %s | ||
// RUN: %env_tool_opts=detect_invalid_join=true not %run %t 2 2>&1 | FileCheck %s | ||
// RUN: %env_tool_opts=detect_invalid_join=true not %run %t 3 2>&1 | FileCheck %s --check-prefix=DETACH | ||
|
||
// REQUIRES: glibc && (asan || hwasan || lsan) | ||
|
||
#include <assert.h> | ||
#include <ctime> | ||
#include <errno.h> | ||
#include <pthread.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
|
||
static void *fn(void *args) { | ||
sleep(1); | ||
return nullptr; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
int n = atoi(argv[1]); | ||
pthread_t thread; | ||
assert(!pthread_create(&thread, nullptr, fn, nullptr)); | ||
void *res; | ||
if (n == 0) { | ||
while (pthread_tryjoin_np(thread, &res)) | ||
sleep(1); | ||
pthread_tryjoin_np(thread, &res); | ||
} else if (n == 1) { | ||
timespec tm = {0, 1}; | ||
while (pthread_timedjoin_np(thread, &res, &tm)) | ||
sleep(1); | ||
pthread_timedjoin_np(thread, &res, &tm); | ||
} else if (n == 2) { | ||
assert(!pthread_join(thread, &res)); | ||
pthread_join(thread, &res); | ||
} else if (n == 3) { | ||
assert(!pthread_detach(thread)); | ||
pthread_join(thread, &res); | ||
} | ||
// CHECK: Joining already joined thread | ||
// DETACH: Joining detached thread | ||
return 0; | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I missed
if (gen_ == kInvalidGen) = 0
,so we don't need the one introduced with b96deb8