; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-attributes --include-generated-funcs --version 4
; RUN: opt < %s -passes='lowertypetests,default<O3>' -S | FileCheck %s
; This IR is based of the following C++
; which was compiled with:
; clang -cc1 -fexceptions -fcxx-exceptions \
; -std=c++11 -internal-isystem llvm-project/build/lib/clang/17/include \
; -nostdsysteminc -triple x86_64-unknown-linux -fsanitize=cfi-icall \
; -fsanitize-cfi-cross-dso -fsanitize-trap=cfi-icall -Oz -S -emit-llvm
; void (*catch_ptr)(int);
; void throw_e (int num) {
; if (num) throw 20;
; }
; void call_catch(int num) {
; catch_ptr = &throw_e;
; try{
; catch_ptr(num);
; } catch (int i) {
; }
; }
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux"
@catch_ptr = local_unnamed_addr global ptr null, align 8
@_ZTIi = external constant ptr
@llvm.used = appending global [1 x ptr] [ptr @__cfi_check_fail], section "llvm.metadata"
; Function Attrs: minsize mustprogress optsize
define dso_local void @_Z7throw_ei(i32 noundef %num) #0 !type !4 !type !5 !type !6 {
entry:
%tobool.not = icmp eq i32 %num, 0
br i1 %tobool.not, label %if.end, label %if.then
if.then: ; preds = %entry
%exception = tail call ptr @__cxa_allocate_exception(i64 4) #5
store i32 20, ptr %exception, align 16, !tbaa !7
tail call void @__cxa_throw(ptr nonnull %exception, ptr nonnull @_ZTIi, ptr null) #6
unreachable
if.end: ; preds = %entry
ret void
}
declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr
declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr
; Function Attrs: minsize mustprogress optsize
define dso_local void @_Z10call_catchi(i32 noundef %num) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 !type !4 !type !5 !type !6 {
entry:
store ptr @_Z7throw_ei, ptr @catch_ptr, align 8, !tbaa !11
%0 = tail call i1 @llvm.type.test(ptr nonnull @_Z7throw_ei, metadata !"_ZTSFviE"), !nosanitize !13
br i1 %0, label %cfi.cont, label %cfi.slowpath, !prof !14, !nosanitize !13
cfi.slowpath: ; preds = %entry
tail call void @__cfi_slowpath(i64 -8738933900360652027, ptr nonnull @_Z7throw_ei) #5, !nosanitize !13
br label %cfi.cont, !nosanitize !13
cfi.cont: ; preds = %cfi.slowpath, %entry
invoke void @_Z7throw_ei(i32 noundef %num) #7
to label %try.cont unwind label %lpad
lpad: ; preds = %cfi.cont
%1 = landingpad { ptr, i32 }
catch ptr @_ZTIi
%2 = extractvalue { ptr, i32 } %1, 1
%3 = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTIi) #5
%matches = icmp eq i32 %2, %3
br i1 %matches, label %catch, label %eh.resume
catch: ; preds = %lpad
%4 = extractvalue { ptr, i32 } %1, 0
%5 = tail call ptr @__cxa_begin_catch(ptr %4) #5
tail call void @__cxa_end_catch() #5
br label %try.cont
try.cont: ; preds = %cfi.cont, %catch
ret void
eh.resume: ; preds = %lpad
resume { ptr, i32 } %1
}
; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i1 @llvm.type.test(ptr, metadata) #1
declare void @__cfi_slowpath(i64, ptr) local_unnamed_addr
declare i32 @__gxx_personality_v0(...)
; Function Attrs: nofree nosync nounwind memory(none)
declare i32 @llvm.eh.typeid.for.p0(ptr) #2
declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr
declare void @__cxa_end_catch() local_unnamed_addr
; Function Attrs: minsize optsize
define weak_odr hidden void @__cfi_check_fail(ptr noundef %0, ptr noundef %1) #3 {
entry:
%.not = icmp eq ptr %0, null, !nosanitize !13
br i1 %.not, label %trap, label %cont, !nosanitize !13
trap: ; preds = %cont, %entry
tail call void @llvm.ubsantrap(i8 2) #8, !nosanitize !13
unreachable, !nosanitize !13
cont: ; preds = %entry
%2 = load i8, ptr %0, align 4, !nosanitize !13
%switch = icmp ult i8 %2, 5
br i1 %switch, label %trap, label %cont6
cont6: ; preds = %cont
ret void, !nosanitize !13
}
; Function Attrs: cold noreturn nounwind
declare void @llvm.ubsantrap(i8 immarg) #4
define weak void @__cfi_check(i64 %0, ptr %1, ptr %2) local_unnamed_addr {
entry:
tail call void @llvm.trap()
unreachable
}
; Function Attrs: cold noreturn nounwind
declare void @llvm.trap() #4
attributes #0 = { minsize mustprogress optsize "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nofree nosync nounwind memory(none) }
attributes #3 = { minsize optsize "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
attributes #4 = { cold noreturn nounwind }
attributes #5 = { nounwind }
attributes #6 = { noreturn }
attributes #7 = { minsize optsize }
attributes #8 = { noreturn nounwind }
!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 4, !"Cross-DSO CFI", i32 1}
!2 = !{i32 4, !"CFI Canonical Jump Tables", i32 0}
!3 = !{!"clang version 17.0.2"}
!4 = !{i64 0, !"_ZTSFviE"}
!5 = !{i64 0, !"_ZTSFviE.generalized"}
!6 = !{i64 0, i64 -8738933900360652027}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{}
!14 = !{!"branch_weights", i32 1048575, i32 1}
; CHECK: Function Attrs: minsize mustprogress optsize
; CHECK-LABEL: define dso_local void @_Z7throw_ei(
; CHECK-SAME: i32 noundef [[NUM:%.*]]) #[[ATTR0:[0-9]+]] !type [[META4:![0-9]+]] !type [[META5:![0-9]+]] !type [[META6:![0-9]+]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[NUM]], 0
; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[IF_END:%.*]], label [[IF_THEN:%.*]]
; CHECK: if.then:
; CHECK-NEXT: [[EXCEPTION:%.*]] = tail call ptr @__cxa_allocate_exception(i64 4) #[[ATTR6:[0-9]+]]
; CHECK-NEXT: store i32 20, ptr [[EXCEPTION]], align 16, !tbaa [[TBAA7:![0-9]+]]
; CHECK-NEXT: tail call void @__cxa_throw(ptr nonnull [[EXCEPTION]], ptr nonnull @_ZTIi, ptr null) #[[ATTR7:[0-9]+]]
; CHECK-NEXT: unreachable
; CHECK: if.end:
; CHECK-NEXT: ret void
;
;
; CHECK: Function Attrs: minsize mustprogress optsize
; CHECK-LABEL: define dso_local void @_Z10call_catchi(
; CHECK-SAME: i32 noundef [[NUM:%.*]]) local_unnamed_addr #[[ATTR0]] personality ptr @__gxx_personality_v0 !type [[META4]] !type [[META5]] !type [[META6]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: store ptr @_Z7throw_ei.cfi_jt, ptr @catch_ptr, align 8, !tbaa [[TBAA11:![0-9]+]]
; CHECK-NEXT: invoke void @_Z7throw_ei.cfi_jt(i32 noundef [[NUM]]) #[[ATTR8:[0-9]+]]
; CHECK-NEXT: to label [[TRY_CONT:%.*]] unwind label [[LPAD:%.*]], !callees [[META13:![0-9]+]]
; CHECK: lpad:
; CHECK-NEXT: [[TMP0:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT: catch ptr @_ZTIi
; CHECK-NEXT: [[TMP1:%.*]] = extractvalue { ptr, i32 } [[TMP0]], 1
; CHECK-NEXT: [[TMP2:%.*]] = tail call i32 @llvm.eh.typeid.for.p0(ptr nonnull @_ZTIi) #[[ATTR6]]
; CHECK-NEXT: [[MATCHES:%.*]] = icmp eq i32 [[TMP1]], [[TMP2]]
; CHECK-NEXT: br i1 [[MATCHES]], label [[CATCH:%.*]], label [[EH_RESUME:%.*]]
; CHECK: catch:
; CHECK-NEXT: [[TMP3:%.*]] = extractvalue { ptr, i32 } [[TMP0]], 0
; CHECK-NEXT: [[TMP4:%.*]] = tail call ptr @__cxa_begin_catch(ptr [[TMP3]]) #[[ATTR6]]
; CHECK-NEXT: tail call void @__cxa_end_catch() #[[ATTR6]]
; CHECK-NEXT: br label [[TRY_CONT]]
; CHECK: try.cont:
; CHECK-NEXT: ret void
; CHECK: eh.resume:
; CHECK-NEXT: resume { ptr, i32 } [[TMP0]]
;
;
; CHECK: Function Attrs: minsize optsize
; CHECK-LABEL: define weak_odr hidden void @__cfi_check_fail(
; CHECK-SAME: ptr noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]]) #[[ATTR2:[0-9]+]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq ptr [[TMP0]], null, !nosanitize [[META14:![0-9]+]]
; CHECK-NEXT: br i1 [[DOTNOT]], label [[TRAP:%.*]], label [[CONT:%.*]], !nosanitize [[META14]]
; CHECK: trap:
; CHECK-NEXT: tail call void @llvm.ubsantrap(i8 2) #[[ATTR9:[0-9]+]], !nosanitize [[META14]]
; CHECK-NEXT: unreachable, !nosanitize [[META14]]
; CHECK: cont:
; CHECK-NEXT: [[TMP2:%.*]] = load i8, ptr [[TMP0]], align 4, !nosanitize [[META14]]
; CHECK-NEXT: [[SWITCH:%.*]] = icmp ult i8 [[TMP2]], 5
; CHECK-NEXT: br i1 [[SWITCH]], label [[TRAP]], label [[CONT6:%.*]]
; CHECK: cont6:
; CHECK-NEXT: ret void, !nosanitize [[META14]]
;
;
; CHECK-LABEL: define weak void @__cfi_check(
; CHECK-SAME: i64 [[TMP0:%.*]], ptr [[TMP1:%.*]], ptr [[TMP2:%.*]]) local_unnamed_addr {
; CHECK-NEXT: entry:
; CHECK-NEXT: tail call void @llvm.trap()
; CHECK-NEXT: unreachable
;
;
; CHECK: Function Attrs: naked nocf_check noinline
; CHECK-LABEL: define internal void @_Z7throw_ei.cfi_jt(
; CHECK-SAME: ) #[[ATTR5:[0-9]+]] align 8 {
; CHECK-NEXT: entry:
; CHECK-NEXT: tail call void asm sideeffect "jmp ${0:c}@plt\0Aint3\0Aint3\0Aint3\0A", "s"(ptr nonnull @_Z7throw_ei) #[[ATTR6]]
; CHECK-NEXT: unreachable
;
;.
; CHECK: [[META4]] = !{i64 0, !"_ZTSFviE"}
; CHECK: [[META5]] = !{i64 0, !"_ZTSFviE.generalized"}
; CHECK: [[META6]] = !{i64 0, i64 -8738933900360652027}
; CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0}
; CHECK: [[META8]] = !{!"int", [[META9:![0-9]+]], i64 0}
; CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0}
; CHECK: [[META10]] = !{!"Simple C++ TBAA"}
; CHECK: [[TBAA11]] = !{[[META12:![0-9]+]], [[META12]], i64 0}
; CHECK: [[META12]] = !{!"any pointer", [[META9]], i64 0}
; CHECK: [[META13]] = !{ptr @_Z7throw_ei.cfi_jt}
; CHECK: [[META14]] = !{}
;.