Index: test/Instrumentation/AddressSanitizer/OptKnownBounds/single-before-start.ll |
diff --git a/test/Instrumentation/AddressSanitizer/OptKnownBounds/single-before-start.ll b/test/Instrumentation/AddressSanitizer/OptKnownBounds/single-before-start.ll |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bb9b35936e06216f57b72966ee0dbafbc3cfe411 |
--- /dev/null |
+++ b/test/Instrumentation/AddressSanitizer/OptKnownBounds/single-before-start.ll |
@@ -0,0 +1,30 @@ |
+; Invalid access of the first element before the start of a global array. |
+ |
+; 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" |
+ |
+@global_array = internal global [50 x i32] zeroinitializer, align 16 |
+ |
+define i32 @example() address_safety nounwind uwtable readonly { |
+entry: |
+ %0 = load i32* getelementptr inbounds ([50 x i32]* @global_array, i64 0, i64 50), align 4 |
+ ret i32 %0 |
+} |
+ |
+; OPT1: @example |
+; OPT1: call void @__asan_report_ |
+; OPT1-NOT: call void @__asan_report_ |
+; OPT1: @asan.module_ctor |
+ |
+; OPT0: @example |
+; OPT0: call void @__asan_report_ |
+; OPT0-NOT: call void @__asan_report_ |
+; OPT0: @asan.module_ctor |
+ |
+; C-example: static int global_array[50]; |
+; C-example: int example(void) { |
+; C-example: return global_array[-1]; // BUG |
+; C-example: } |