Skip to content

Commit 35c135b

Browse files
committed
More tests
1 parent ae0e0ec commit 35c135b

File tree

4 files changed

+104
-6
lines changed

4 files changed

+104
-6
lines changed

offload/include/Shared/Sanitizer.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
#include "Types.h"
1515
#include "Utils.h"
1616

17-
extern "C" int ompx_block_id(int Dim);
18-
extern "C" int ompx_block_dim(int Dim);
19-
extern "C" int ompx_thread_id(int Dim);
17+
extern "C" {
18+
int ompx_block_id(int Dim);
19+
int ompx_block_dim(int Dim);
20+
int ompx_thread_id(int Dim);
21+
[[clang::disable_sanitizer_instrumentation, gnu::noinline]] inline int64_t
22+
__san_get_location_value() {
23+
return -1;
24+
}
25+
}
2026

2127
enum class AllocationKind { LOCAL, GLOBAL, LAST = GLOBAL };
2228

@@ -176,6 +182,7 @@ struct SanitizerTrapInfoTy {
176182
uint32_t ThreadId[3];
177183
uint64_t PC;
178184
uint64_t LocationId;
185+
uint64_t CallId;
179186
/// }
180187

181188
[[clang::disable_sanitizer_instrumentation]] void
@@ -185,6 +192,7 @@ struct SanitizerTrapInfoTy {
185192
ThreadId[Dim] = ompx_thread_id(Dim);
186193
}
187194
LocationId = SourceId;
195+
CallId = __san_get_location_value();
188196
}
189197

190198
template <enum AllocationKind AK>

offload/plugins-nextgen/common/src/PluginInterface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "Utils/ELF.h"
2222
#include "omptarget.h"
2323
#include "llvm/Support/ErrorHandling.h"
24+
#include <cstdio>
2425
#include <string>
2526

2627
#ifdef OMPT_SUPPORT
@@ -2235,9 +2236,7 @@ void GPUSanTy::checkAndReportError() {
22352236
fprintf(stderr, " no backtrace available\n");
22362237
return;
22372238
}
2238-
printf("Loc %p : %u\n", LocationsGV.getPtr(), LocationsGV.getSize());
2239-
printf("Nam %p : %u\n", LocationNamesGV.getPtr(),
2240-
LocationNamesGV.getSize());
2239+
fprintf(stderr, "%lu\n", STI->CallId);
22412240
char *LocationNames = LocationNamesGV.getPtrAs<char>();
22422241
LocationEncodingTy *Locations = LocationsGV.getPtrAs<LocationEncodingTy>();
22432242
int32_t FrameIdx = 0;
@@ -2249,6 +2248,7 @@ void GPUSanTy::checkAndReportError() {
22492248
LocationId = LE.ParentIdx;
22502249
FrameIdx++;
22512250
} while (LocationId >= 0);
2251+
fputc('\n', stderr);
22522252
};
22532253

22542254
auto DiagnoseAccess = [&](StringRef Name) {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// clang-format off
2+
// : %libomptarget-compileopt-generic -fsanitize=offload -O1
3+
// : not %libomptarget-run-generic 2> %t.out
4+
// : %fcheck-generic --check-prefixes=CHECK < %t.out
5+
// : %libomptarget-compileopt-generic -fsanitize=offload -O3
6+
// : not %libomptarget-run-generic 2> %t.out
7+
// RUN: %libomptarget-compileopt-generic -fsanitize=offload -O3 -g
8+
// RUN: not %libomptarget-run-generic 2> %t.out
9+
// RUN: %fcheck-generic --check-prefixes=DEBUG < %t.out
10+
// clang-format on
11+
12+
// UNSUPPORTED: aarch64-unknown-linux-gnu
13+
// UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
14+
// UNSUPPORTED: x86_64-pc-linux-gnu
15+
// UNSUPPORTED: x86_64-pc-linux-gnu-LTO
16+
// UNSUPPORTED: s390x-ibm-linux-gnu
17+
// UNSUPPORTED: s390x-ibm-linux-gnu-LTO
18+
19+
[[clang::optnone]] int deref(int *P) { return *P; }
20+
21+
[[gnu::always_inline]] int bar(int *P) { return deref(P); }
22+
23+
int main(void) {
24+
25+
#pragma omp target
26+
{
27+
int *NullPtr = 0;
28+
// clang-format off
29+
// CHECK: ERROR: OffloadSanitizer out-of-bounds access on address 0x0000000000000000 at pc [[PC:.*]]
30+
// CHECK: WRITE of size 4 at 0x0000000000000000 thread <0, 0, 0> block <0, 0, 0> (acc 1, heap)
31+
// CHECK: #0 [[PC]] omp target (main:[[@LINE-6]]) in <unknown>:0
32+
//
33+
// CHECK: 0x0000000000000000 is located 0 bytes inside of a 0-byte region [0x0000000000000000,0x0000000000000000)
34+
//
35+
// DEBUG: ERROR: OffloadSanitizer out-of-bounds access on address 0x0000000000000000 at pc [[PC:.*]]
36+
// DEBUG: WRITE of size 4 at 0x0000000000000000 thread <0, 0, 0> block <0, 0, 0> (acc 1, heap)
37+
// DEBUG: #0 [[PC]] omp target (main:[[@LINE-12]]) in {{.*}}volatile_stack_null.c:[[@LINE+4]]
38+
//
39+
// DEBUG: 0x0000000000000000 is located 0 bytes inside of a 0-byte region [0x0000000000000000,0x0000000000000000)
40+
// clang-format on
41+
bar(NullPtr);
42+
}
43+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// clang-format off
2+
// : %libomptarget-compileopt-generic -fsanitize=offload -O1
3+
// : not %libomptarget-run-generic 2> %t.out
4+
// : %fcheck-generic --check-prefixes=CHECK < %t.out
5+
// : %libomptarget-compileopt-generic -fsanitize=offload -O3
6+
// : not %libomptarget-run-generic 2> %t.out
7+
// RUN: %libomptarget-compileopt-generic -fsanitize=offload -O3 -g
8+
// RUN: not %libomptarget-run-generic 2> %t.out
9+
// RUN: %fcheck-generic --check-prefixes=DEBUG < %t.out
10+
// clang-format on
11+
12+
// UNSUPPORTED: aarch64-unknown-linux-gnu
13+
// UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
14+
// UNSUPPORTED: x86_64-pc-linux-gnu
15+
// UNSUPPORTED: x86_64-pc-linux-gnu-LTO
16+
// UNSUPPORTED: s390x-ibm-linux-gnu
17+
// UNSUPPORTED: s390x-ibm-linux-gnu-LTO
18+
19+
[[clang::optnone]] int deref(int *P) { return *P; }
20+
21+
[[gnu::noinline]] int bar(int *P) { return deref(P); }
22+
[[gnu::noinline]] int baz(int *P) { return deref(P); }
23+
24+
int main(void) {
25+
26+
#pragma omp target
27+
{
28+
int *NullPtr = 0;
29+
int X;
30+
int *Valid = &X;
31+
// clang-format off
32+
// CHECK: ERROR: OffloadSanitizer out-of-bounds access on address 0x0000000000000000 at pc [[PC:.*]]
33+
// CHECK: WRITE of size 4 at 0x0000000000000000 thread <0, 0, 0> block <0, 0, 0> (acc 1, heap)
34+
// CHECK: #0 [[PC]] omp target (main:[[@LINE-6]]) in <unknown>:0
35+
//
36+
// CHECK: 0x0000000000000000 is located 0 bytes inside of a 0-byte region [0x0000000000000000,0x0000000000000000)
37+
//
38+
// DEBUG: ERROR: OffloadSanitizer out-of-bounds access on address 0x0000000000000000 at pc [[PC:.*]]
39+
// DEBUG: WRITE of size 4 at 0x0000000000000000 thread <0, 0, 0> block <0, 0, 0> (acc 1, heap)
40+
// DEBUG: #0 [[PC]] omp target (main:[[@LINE-12]]) in {{.*}}volatile_stack_null.c:[[@LINE+4]]
41+
//
42+
// DEBUG: 0x0000000000000000 is located 0 bytes inside of a 0-byte region [0x0000000000000000,0x0000000000000000)
43+
// clang-format on
44+
bar(Valid);
45+
baz(NullPtr);
46+
}
47+
}

0 commit comments

Comments
 (0)