llvm/llvm/test/Instrumentation/BoundsChecking/ubsan-unique-traps.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=bounds-checking -bounds-checking-unique-traps -S | FileCheck %s
target datalayout = "e-p:64:64:64-p1:16:16:16-p2:64:64:64:48-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"

declare noalias ptr @malloc(i64) nounwind allocsize(0)

define void @f() nounwind {
; CHECK-LABEL: @f(
; CHECK-NEXT:    [[TMP1:%.*]] = tail call ptr @malloc(i64 32)
; CHECK-NEXT:    [[IDX:%.*]] = getelementptr inbounds i32, ptr [[TMP1]], i64 8
; CHECK-NEXT:    br label [[TRAP:%.*]]
; CHECK:       2:
; CHECK-NEXT:    store i32 3, ptr [[IDX]], align 4
; CHECK-NEXT:    [[TMP3:%.*]] = tail call ptr @malloc(i64 32)
; CHECK-NEXT:    [[IDX2:%.*]] = getelementptr inbounds i32, ptr [[TMP3]], i64 8
; CHECK-NEXT:    br label [[TRAP1:%.*]]
; CHECK:       4:
; CHECK-NEXT:    store i32 3, ptr [[IDX2]], align 4
; CHECK-NEXT:    [[TMP5:%.*]] = tail call ptr @malloc(i64 32)
; CHECK-NEXT:    [[IDX3:%.*]] = getelementptr inbounds i32, ptr [[TMP5]], i64 8
; CHECK-NEXT:    br label [[TRAP2:%.*]]
; CHECK:       6:
; CHECK-NEXT:    store i32 3, ptr [[IDX3]], align 4
; CHECK-NEXT:    ret void
; CHECK:       trap:
; CHECK-NEXT:    call void @llvm.ubsantrap(i8 3) #[[ATTR3:[0-9]+]]
; CHECK-NEXT:    unreachable
; CHECK:       trap1:
; CHECK-NEXT:    call void @llvm.ubsantrap(i8 5) #[[ATTR3]]
; CHECK-NEXT:    unreachable
; CHECK:       trap2:
; CHECK-NEXT:    call void @llvm.ubsantrap(i8 7) #[[ATTR3]]
; CHECK-NEXT:    unreachable
;
  %1 = tail call ptr @malloc(i64 32)
  %idx = getelementptr inbounds i32, ptr %1, i64 8
  store i32 3, ptr %idx, align 4
  %2 = tail call ptr @malloc(i64 32)
  %idx2 = getelementptr inbounds i32, ptr %2, i64 8
  store i32 3, ptr %idx2, align 4
  %3 = tail call ptr @malloc(i64 32)
  %idx3 = getelementptr inbounds i32, ptr %3, i64 8
  store i32 3, ptr %idx3, align 4
  ret void
}