llvm.org GIT mirror llvm / 0ca032b
The patch resolves the conflict between AddressSanitizer and load widening (GVN). The problem initially reported by Mozilla folks (http://code.google.com/p/address-sanitizer/issues/detail?id=20), but it also prevents us from enabling LLVM bootstrap with AddressSanitizer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149925 91177308-0d34-0410-b5e6-96231b3b80d8 Kostya Serebryany 7 years ago
2 changed file(s) with 51 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
321321 if (NewLoadByteSize > LoadAlign ||
322322 !TD.fitsInLegalInteger(NewLoadByteSize*8))
323323 return 0;
324
325 if (LIOffs+NewLoadByteSize > MemLocEnd &&
326 LI->getParent()->getParent()->hasFnAttr(Attribute::AddressSafety)) {
327 // We will be reading past the location accessed by the original program.
328 // While this is safe in a regular build, Address Safety analysis tools
329 // may start reporting false warnings. So, don't do widening.
330 return 0;
331 }
324332
325333 // If a load of this width would include all of MemLoc, then we succeed.
326334 if (LIOffs+NewLoadByteSize >= MemLocEnd)
0 ; RUN: opt < %s -basicaa -gvn -asan -S | FileCheck %s
1 ; ASAN conflicts with load widening iff the widened load accesses data out of bounds
2 ; (while the original unwidened loads do not).
3 ; http://code.google.com/p/address-sanitizer/issues/detail?id=20#c1
4
5
6 ; 32-bit little endian target.
7 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
8
9 %struct_of_7_bytes_4_aligned = type { i32, i8, i8, i8}
10
11 @f = global %struct_of_7_bytes_4_aligned zeroinitializer, align 4
12
13 ; Accessing bytes 4 and 6, not ok to widen to i32 if address_safety is set.
14
15 define i32 @test_widening_bad(i8* %P) nounwind ssp noredzone address_safety {
16 entry:
17 %tmp = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 1), align 4
18 %conv = zext i8 %tmp to i32
19 %tmp1 = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 3), align 1
20 %conv2 = zext i8 %tmp1 to i32
21 %add = add nsw i32 %conv, %conv2
22 ret i32 %add
23 ; CHECK: @test_widening_bad
24 ; CHECK: __asan_report_load1
25 ; CHECK: __asan_report_load1
26 ; CHECK-ret i32
27 }
28
29 ;; Accessing byets 4 and 5. Ok to widen to i16.
30
31 define i32 @test_widening_ok(i8* %P) nounwind ssp noredzone address_safety {
32 entry:
33 %tmp = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 1), align 4
34 %conv = zext i8 %tmp to i32
35 %tmp1 = load i8* getelementptr inbounds (%struct_of_7_bytes_4_aligned* @f, i64 0, i32 2), align 1
36 %conv2 = zext i8 %tmp1 to i32
37 %add = add nsw i32 %conv, %conv2
38 ret i32 %add
39 ; CHECK: @test_widening_ok
40 ; CHECK: __asan_report_load1
41 ; CHECK-ret i32
42 }