llvm.org GIT mirror llvm / 30ea429
[ASan] Don't instrument load/stores with !nosanitize metadata. This is used to avoid instrumentation of instructions added by UBSan in Clang frontend (see r213291). This fixes PR20085. Reviewed in http://reviews.llvm.org/D4544. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213292 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 6 years ago
2 changed file(s) with 55 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
654654 // and set IsWrite/Alignment. Otherwise return NULL.
655655 static Value *isInterestingMemoryAccess(Instruction *I, bool *IsWrite,
656656 unsigned *Alignment) {
657 // Skip memory accesses inserted by another instrumentation.
658 if (I->getMetadata("nosanitize"))
659 return nullptr;
657660 if (LoadInst *LI = dyn_cast(I)) {
658661 if (!ClInstrumentReads) return nullptr;
659662 *IsWrite = false;
0 ; ASan shouldn't instrument code added by UBSan.
1
2 ; RUN: opt < %s -asan -asan-module -S | FileCheck %s
3
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
5 target triple = "x86_64-unknown-linux-gnu"
6
7 %struct.A = type { i32 (...)** }
8 declare void @__ubsan_handle_dynamic_type_cache_miss(i8*, i64, i64) uwtable
9 @__ubsan_vptr_type_cache = external global [128 x i64]
10 @.src = private unnamed_addr constant [19 x i8] c"tmp/ubsan/vptr.cpp\00", align 1
11 @0 = private unnamed_addr constant { i16, i16, [4 x i8] } { i16 -1, i16 0, [4 x i8] c"'A'\00" }
12 @_ZTI1A = external constant i8*
13 @1 = private unnamed_addr global { { [19 x i8]*, i32, i32 }, { i16, i16, [4 x i8] }*, i8*, i8 } { { [19 x i8]*, i32, i32 } { [19 x i8]* @.src, i32 2, i32 18 }, { i16, i16, [4 x i8] }* @0, i8* bitcast (i8** @_ZTI1A to i8*), i8 4 }
14
15 define void @_Z3BarP1A(%struct.A* %a) uwtable sanitize_address {
16 ; CHECK-LABEL: define void @_Z3BarP1A
17 entry:
18 %0 = bitcast %struct.A* %a to void (%struct.A*)***
19 %vtable = load void (%struct.A*)*** %0, align 8
20 ; CHECK: __asan_report_load8
21 %1 = load void (%struct.A*)** %vtable, align 8
22 ; CHECK: __asan_report_load8
23 %2 = ptrtoint void (%struct.A*)** %vtable to i64
24 %3 = xor i64 %2, -303164226014115343, !nosanitize !0
25 %4 = mul i64 %3, -7070675565921424023, !nosanitize !0
26 %5 = lshr i64 %4, 47, !nosanitize !0
27 %6 = xor i64 %4, %2, !nosanitize !0
28 %7 = xor i64 %6, %5, !nosanitize !0
29 %8 = mul i64 %7, -7070675565921424023, !nosanitize !0
30 %9 = lshr i64 %8, 47, !nosanitize !0
31 %10 = xor i64 %9, %8, !nosanitize !0
32 %11 = mul i64 %10, -7070675565921424023, !nosanitize !0
33 %12 = and i64 %11, 127, !nosanitize !0
34 %13 = getelementptr inbounds [128 x i64]* @__ubsan_vptr_type_cache, i64 0, i64 %12, !nosanitize !0
35 ; CHECK-NOT: __asan_report_load8
36 %14 = load i64* %13, align 8, !nosanitize !0
37 %15 = icmp eq i64 %14, %11, !nosanitize !0
38 br i1 %15, label %cont, label %handler.dynamic_type_cache_miss, !nosanitize !0
39
40 handler.dynamic_type_cache_miss: ; preds = %entry
41 %16 = ptrtoint %struct.A* %a to i64, !nosanitize !0
42 tail call void @__ubsan_handle_dynamic_type_cache_miss(i8* bitcast ({ { [19 x i8]*, i32, i32 }, { i16, i16, [4 x i8] }*, i8*, i8 }* @1 to i8*), i64 %16, i64 %11) #2, !nosanitize !0
43 br label %cont, !nosanitize !0
44
45 cont: ; preds = %handler.dynamic_type_cache_miss, %entry
46 tail call void %1(%struct.A* %a)
47 ; CHECK: ret void
48 ret void
49 }
50
51 !0 = metadata !{}