-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cilksan] Fix handling of a realloc when the allocation of the given …
…old pointer is not instrumented. Fixes issue OpenCilk/opencilk-project#218
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Check that Cilksan correctly verifies that frees of realloc'd | ||
// pointers do not race. | ||
// | ||
// Thanks to bababuck for providing the original source code for this | ||
// issue. | ||
// | ||
// RUN: %clang_cilksan -fopencilk -O3 %s -o %t | ||
// RUN: %run %t 2>&1 | FileCheck %s | ||
|
||
#include <stdlib.h> | ||
#include <cilk/cilk.h> | ||
|
||
void test(int *arr, int count) { | ||
if (count == 0) { | ||
free(arr); | ||
return ; | ||
} | ||
|
||
cilk_scope { | ||
for (int i = 0; i < 15; ++i) { | ||
int *new_arr = malloc(10 * sizeof(int)); | ||
new_arr = realloc(new_arr, 10 * sizeof(int)); | ||
cilk_spawn test(new_arr, count - 1); | ||
} | ||
} | ||
return ; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
test(NULL, 1); | ||
} | ||
|
||
// CHECK-NOT: Race detected on location | ||
|
||
// CHECK: Cilksan detected 0 distinct races. | ||
// CHECK-NEXT: Cilksan suppressed 0 duplicate race reports. |