Index: test/Instrumentation/AddressSanitizer/OptKnownBounds/double-loop-invalid-single-end.ll |
diff --git a/test/Instrumentation/AddressSanitizer/OptKnownBounds/double-loop-invalid-single-end.ll b/test/Instrumentation/AddressSanitizer/OptKnownBounds/double-loop-invalid-single-end.ll |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7002e0ef23d31800a1e3d4c9830bf57e9aaad15c |
--- /dev/null |
+++ b/test/Instrumentation/AddressSanitizer/OptKnownBounds/double-loop-invalid-single-end.ll |
@@ -0,0 +1,68 @@ |
+; Valid two-dimensional array iteration plus an invalid load (off by 1). |
+ |
+; RUN: opt < %s -asan -S -asan-opt=1 -asan-opt-known-bounds=1 | FileCheck %s -check-prefix=OPT1 |
+; RUN: opt < %s -asan -S -asan-opt=0 | FileCheck %s -check-prefix=OPT0 |
+ |
+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-S128" |
+target triple = "x86_64-unknown-linux-gnu" |
+ |
+define i32 @example() address_safety nounwind uwtable { |
+entry: |
+ %array = alloca [20 x [50 x i32]], align 16 |
+ br label %for.cond1.preheader |
+ |
+for.cond1.preheader: ; preds = %for.inc6, %entry |
+ %indvars.iv14 = phi i64 [ 0, %entry ], [ %indvars.iv.next15, %for.inc6 ] |
+ br label %for.body3 |
+ |
+for.body3: ; preds = %for.body3, %for.cond1.preheader |
+ %indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body3 ] |
+ %0 = add nsw i64 %indvars.iv, %indvars.iv14 |
+ %arrayidx5 = getelementptr inbounds [20 x [50 x i32]]* %array, i64 0, i64 %indvars.iv14, i64 %indvars.iv |
+ %1 = trunc i64 %0 to i32 |
+ store volatile i32 %1, i32* %arrayidx5, align 4 |
+ %indvars.iv.next = add i64 %indvars.iv, 1 |
+ %lftr.wideiv = trunc i64 %indvars.iv.next to i32 |
+ %exitcond = icmp eq i32 %lftr.wideiv, 50 |
+ br i1 %exitcond, label %for.inc6, label %for.body3 |
+ |
+for.inc6: ; preds = %for.body3 |
+ %indvars.iv.next15 = add i64 %indvars.iv14, 1 |
+ %lftr.wideiv16 = trunc i64 %indvars.iv.next15 to i32 |
+ %exitcond17 = icmp eq i32 %lftr.wideiv16, 20 |
+ br i1 %exitcond17, label %for.end8, label %for.cond1.preheader |
+ |
+for.end8: ; preds = %for.inc6 |
+ %arrayidx10 = getelementptr inbounds [20 x [50 x i32]]* %array, i64 0, i64 19, i64 50 |
+ %2 = load volatile i32* %arrayidx10, align 8 |
+ ret i32 %2 |
+} |
+ |
+; The first memory access is always fine. |
+; OPT1: @example |
+; OPT1-NOT: call void @__asan_report_ |
+; OPT1: store volatile i32 |
+ |
+; OPT0: @example |
+; OPT0: call void @__asan_report_ |
+; OPT0-NOT: call void @__asan_report_ |
+; OPT0: store volatile i32 |
+ |
+; The second memory access is invalid. |
+; OPT1: call void @__asan_report_ |
+; OPT1-NOT: call void @__asan_report_ |
+; OPT1: @asan.module_ctor |
+ |
+; OPT0: call void @__asan_report_ |
+; OPT0-NOT: call void @__asan_report_ |
+; OPT0: @asan.module_ctor |
+ |
+; C-example: #include <stdlib.h> |
+; C-example: |
+; C-example: int example(void) { |
+; C-example: volatile int array[20][50]; |
+; C-example: for(int i = 0; i < 20; ++i) |
+; C-example: for(int j = 0; j < 50; ++j) |
+; C-example: array[i][j] = i + j; |
+; C-example: return array[19][50]; // BUG |
+; C-example: } |