blob: 5d4d5efd0776bbc08d90bf817a45725ce22868ef [file] [edit]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes='default<O2>' -S < %s | FileCheck %s
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; The pointer-overflow check that -fsanitize=pointer-overflow emits for a
; constant index into a static array must be discharged, otherwise the check
; keeps the array alive and the load cannot be folded. The index here is a
; multiple of the array's alignment, so known bits alone cannot prove that the
; computed address is non-null; the size of the object is what makes it
; provable.
; The check is discharged, so nothing refers to the array and it is removed.
; CHECK-NOT: @arr =
@arr = internal global [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], align 16
@.src = private unnamed_addr constant [8 x i8] c"t.c\00\00\00\00\00", align 1
@loc = private unnamed_addr global { ptr, i32, i32 } { ptr @.src, i32 2, i32 25 }
declare void @__ubsan_handle_pointer_overflow(ptr, i64, i64)
define i32 @load_last_element() {
; CHECK-LABEL: @load_last_element(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i32 5
;
entry:
%0 = icmp ne i64 add (i64 ptrtoaddr (ptr @arr to i64), i64 16), 0, !nosanitize !0
br i1 %0, label %cont, label %handler.pointer_overflow, !nosanitize !0
handler.pointer_overflow:
call void @__ubsan_handle_pointer_overflow(ptr @loc, i64 ptrtoaddr (ptr @arr to i64), i64 add (i64 ptrtoaddr (ptr @arr to i64), i64 16)), !nosanitize !0
br label %cont, !nosanitize !0
cont:
%1 = load i32, ptr getelementptr inbounds nuw (i8, ptr @arr, i64 16), align 16
ret i32 %1
}
!0 = !{}