llvm.org GIT mirror llvm / b523d2b
[asan] Do not instrument pointers with address space attributes Do not instrument pointers with address space attributes since we cannot track them anyway. Instrumenting them results in false positives in ASan and a compiler crash in TSan. (The compiler should not crash in any case, but that's a different problem.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273339 91177308-0d34-0410-b5e6-96231b3b80d8 Anna Zaks 4 years ago
4 changed file(s) with 82 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
951951 PtrOperand = XCHG->getPointerOperand();
952952 }
953953
954 // Do not instrument acesses from different address spaces; we cannot deal
955 // with them.
956 if (PtrOperand) {
957 Type *PtrTy = cast(PtrOperand->getType()->getScalarType());
958 if (PtrTy->getPointerAddressSpace() != 0)
959 return nullptr;
960 }
961
954962 // Treat memory accesses to promotable allocas as non-interesting since they
955963 // will not cause memory violations. This greatly speeds up the instrumented
956964 // executable at -O0.
275275 if (GV->getName() == "__llvm_gcov_ctr")
276276 return false;
277277 }
278
279 // Do not instrument acesses from different address spaces; we cannot deal
280 // with them.
281 if (Addr) {
282 Type *PtrTy = cast(Addr->getType()->getScalarType());
283 if (PtrTy->getPointerAddressSpace() != 0)
284 return false;
285 }
286
278287 return true;
279288 }
280289
0 ; RUN: opt < %s -asan -S | FileCheck %s
1 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
2 target triple = "x86_64-apple-macosx10.11.0"
3
4 ; Checks that we do not instrument loads and stores comming from custom address space.
5 ; These result in invalid (false positive) reports.
6 ; int foo(int argc, const char * argv[]) {
7 ; void *__attribute__((address_space(256))) *gs_base = (((void * __attribute__((address_space(256))) *)0));
8 ; void *somevalue = gs_base[-1];
9 ; return somevalue;
10 ; }
11
12 define i32 @foo(i32 %argc, i8** %argv) sanitize_address {
13 entry:
14 %retval = alloca i32, align 4
15 %argc.addr = alloca i32, align 4
16 %argv.addr = alloca i8**, align 8
17 %gs_base = alloca i8* addrspace(256)*, align 8
18 %somevalue = alloca i8*, align 8
19 store i32 0, i32* %retval, align 4
20 store i32 %argc, i32* %argc.addr, align 4
21 store i8** %argv, i8*** %argv.addr, align 8
22 store i8* addrspace(256)* null, i8* addrspace(256)** %gs_base, align 8
23 %0 = load i8* addrspace(256)*, i8* addrspace(256)** %gs_base, align 8
24 %arrayidx = getelementptr inbounds i8*, i8* addrspace(256)* %0, i64 -1
25 %1 = load i8*, i8* addrspace(256)* %arrayidx, align 8
26 store i8* %1, i8** %somevalue, align 8
27 %2 = load i8*, i8** %somevalue, align 8
28 %3 = ptrtoint i8* %2 to i32
29 ret i32 %3
30 }
31 ; CHECK-NOT: call void @__asan_report_load8
0 ; RUN: opt < %s -tsan -S | FileCheck %s
1 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
2 target triple = "x86_64-apple-macosx10.11.0"
3
4 ; Checks that we do not instrument loads and stores comming from custom address space.
5 ; These result in crashing the compiler.
6 ; int foo(int argc, const char * argv[]) {
7 ; void *__attribute__((address_space(256))) *gs_base = (((void * __attribute__((address_space(256))) *)0));
8 ; void *somevalue = gs_base[-1];
9 ; return somevalue;
10 ; }
11
12 define i32 @foo(i32 %argc, i8** %argv) sanitize_thread {
13 entry:
14 %retval = alloca i32, align 4
15 %argc.addr = alloca i32, align 4
16 %argv.addr = alloca i8**, align 8
17 %gs_base = alloca i8* addrspace(256)*, align 8
18 %somevalue = alloca i8*, align 8
19 store i32 0, i32* %retval, align 4
20 store i32 %argc, i32* %argc.addr, align 4
21 store i8** %argv, i8*** %argv.addr, align 8
22 store i8* addrspace(256)* null, i8* addrspace(256)** %gs_base, align 8
23 %0 = load i8* addrspace(256)*, i8* addrspace(256)** %gs_base, align 8
24 %arrayidx = getelementptr inbounds i8*, i8* addrspace(256)* %0, i64 -1
25 %1 = load i8*, i8* addrspace(256)* %arrayidx, align 8
26 store i8* %1, i8** %somevalue, align 8
27 %2 = load i8*, i8** %somevalue, align 8
28 %3 = ptrtoint i8* %2 to i32
29 ret i32 %3
30 }
31 ; CHECK-NOT: call void @__tsan_read
32 ; CHECK-NOT: addrspacecast