blob: 8074350f6a51eb3e747d7ff65053ba8216a23685 [file] [edit]
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --version 6
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fno-sanitize-trap=cfi-vcall -fsanitize-minimal-runtime -fsanitize-undefined-strip-path-components=-1 -emit-llvm -o - %s | FileCheck --implicit-check-not="private unnamed_addr constant" --check-prefix=MIN %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fsanitize-skip-hot-cutoff=cfi-vcall=0.5 -disable-llvm-passes -fsanitize-undefined-strip-path-components=-1 -emit-llvm -o - %s | FileCheck --implicit-check-not="private unnamed_addr constant" --check-prefix=TRAP_CUTOFF %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fsanitize-cfi-cross-dso -fsanitize-undefined-strip-path-components=-1 -emit-llvm -o - %s | FileCheck --implicit-check-not="private unnamed_addr constant" --check-prefix=XDSO_TRAP %s
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility=hidden -fsanitize=cfi-vcall -fsanitize-trap=cfi-vcall -fdevirtualize-speculatively -fsanitize-undefined-strip-path-components=-1 -emit-llvm -o - %s | FileCheck --implicit-check-not="private unnamed_addr constant" --check-prefix=SPEC_TRAP %s
// Tests how a failed cfi-vcall vtable check is reported in trap and
// minimal-runtime modes (with skip-hot-cutoff, cross-DSO CFI, and
// -fdevirtualize-speculatively). --implicit-check-not catches unused
// diagnostic data.
struct S {
virtual void f();
};
//.
// XDSO_TRAP: @llvm.used = appending global [1 x ptr] [ptr @__cfi_check_fail], section "llvm.metadata"
//.
// MIN-LABEL: define hidden void @test(
// MIN-SAME: ptr noundef [[S:%.*]]) #[[ATTR0:[0-9]+]] {
// MIN-NEXT: [[ENTRY:.*:]]
// MIN-NEXT: [[S_ADDR:%.*]] = alloca ptr, align 8
// MIN-NEXT: store ptr [[S]], ptr [[S_ADDR]], align 8
// MIN-NEXT: [[TMP0:%.*]] = load ptr, ptr [[S_ADDR]], align 8
// MIN-NEXT: [[VTABLE:%.*]] = load ptr, ptr [[TMP0]], align 8
// MIN-NEXT: [[TMP1:%.*]] = call i1 @llvm.type.test(ptr [[VTABLE]], metadata !"_ZTS1S"), !nosanitize [[META1:![0-9]+]]
// MIN-NEXT: br i1 [[TMP1]], label %[[CONT:.*]], label %[[HANDLER_CFI_CHECK_FAIL:.*]], !prof [[PROF2:![0-9]+]], !nosanitize [[META1]]
// MIN: [[HANDLER_CFI_CHECK_FAIL]]:
// MIN-NEXT: call void @__ubsan_handle_cfi_check_fail_minimal_abort() #[[ATTR3:[0-9]+]], !nosanitize [[META1]]
// MIN-NEXT: unreachable, !nosanitize [[META1]]
// MIN: [[CONT]]:
// MIN-NEXT: [[VFN:%.*]] = getelementptr inbounds ptr, ptr [[VTABLE]], i64 0
// MIN-NEXT: [[TMP2:%.*]] = load ptr, ptr [[VFN]], align 8
// MIN-NEXT: call void [[TMP2]](ptr noundef nonnull align 8 dereferenceable(8) [[TMP0]])
// MIN-NEXT: ret void
//
// TRAP_CUTOFF-LABEL: define hidden void @test(
// TRAP_CUTOFF-SAME: ptr noundef [[S:%.*]]) #[[ATTR0:[0-9]+]] {
// TRAP_CUTOFF-NEXT: [[ENTRY:.*:]]
// TRAP_CUTOFF-NEXT: [[S_ADDR:%.*]] = alloca ptr, align 8
// TRAP_CUTOFF-NEXT: store ptr [[S]], ptr [[S_ADDR]], align 8
// TRAP_CUTOFF-NEXT: [[TMP0:%.*]] = load ptr, ptr [[S_ADDR]], align 8
// TRAP_CUTOFF-NEXT: [[VTABLE:%.*]] = load ptr, ptr [[TMP0]], align 8
// TRAP_CUTOFF-NEXT: [[TMP1:%.*]] = call i1 @llvm.type.test(ptr [[VTABLE]], metadata !"_ZTS1S"), !nosanitize [[META1:![0-9]+]]
// TRAP_CUTOFF-NEXT: [[TMP2:%.*]] = call i1 @llvm.allow.ubsan.check(i8 54), !nosanitize [[META1]]
// TRAP_CUTOFF-NEXT: [[TMP3:%.*]] = xor i1 [[TMP2]], true, !nosanitize [[META1]]
// TRAP_CUTOFF-NEXT: [[TMP4:%.*]] = or i1 [[TMP1]], [[TMP3]], !nosanitize [[META1]]
// TRAP_CUTOFF-NEXT: br i1 [[TMP4]], label %[[CONT:.*]], label %[[TRAP:.*]], !prof [[PROF2:![0-9]+]], !nosanitize [[META1]]
// TRAP_CUTOFF: [[TRAP]]:
// TRAP_CUTOFF-NEXT: call void @llvm.ubsantrap(i8 2) #[[ATTR4:[0-9]+]], !nosanitize [[META1]]
// TRAP_CUTOFF-NEXT: unreachable, !nosanitize [[META1]]
// TRAP_CUTOFF: [[CONT]]:
// TRAP_CUTOFF-NEXT: [[VFN:%.*]] = getelementptr inbounds ptr, ptr [[VTABLE]], i64 0
// TRAP_CUTOFF-NEXT: [[TMP5:%.*]] = load ptr, ptr [[VFN]], align 8
// TRAP_CUTOFF-NEXT: call void [[TMP5]](ptr noundef nonnull align 8 dereferenceable(8) [[TMP0]])
// TRAP_CUTOFF-NEXT: ret void
//
// XDSO_TRAP-LABEL: define hidden void @test(
// XDSO_TRAP-SAME: ptr noundef [[S:%.*]]) #[[ATTR0:[0-9]+]] {
// XDSO_TRAP-NEXT: [[ENTRY:.*:]]
// XDSO_TRAP-NEXT: [[S_ADDR:%.*]] = alloca ptr, align 8
// XDSO_TRAP-NEXT: store ptr [[S]], ptr [[S_ADDR]], align 8
// XDSO_TRAP-NEXT: [[TMP0:%.*]] = load ptr, ptr [[S_ADDR]], align 8
// XDSO_TRAP-NEXT: [[VTABLE:%.*]] = load ptr, ptr [[TMP0]], align 8
// XDSO_TRAP-NEXT: [[TMP1:%.*]] = call i1 @llvm.type.test(ptr [[VTABLE]], metadata !"_ZTS1S"), !nosanitize [[META2:![0-9]+]]
// XDSO_TRAP-NEXT: br i1 [[TMP1]], label %[[CFI_CONT:.*]], label %[[CFI_SLOWPATH:.*]], !prof [[PROF3:![0-9]+]], !nosanitize [[META2]]
// XDSO_TRAP: [[CFI_SLOWPATH]]:
// XDSO_TRAP-NEXT: call void @__cfi_slowpath(i64 -7568795971037593456, ptr [[VTABLE]]) #[[ATTR5:[0-9]+]], !nosanitize [[META2]]
// XDSO_TRAP-NEXT: br label %[[CFI_CONT]], !nosanitize [[META2]]
// XDSO_TRAP: [[CFI_CONT]]:
// XDSO_TRAP-NEXT: [[VFN:%.*]] = getelementptr inbounds ptr, ptr [[VTABLE]], i64 0
// XDSO_TRAP-NEXT: [[TMP2:%.*]] = load ptr, ptr [[VFN]], align 8
// XDSO_TRAP-NEXT: call void [[TMP2]](ptr noundef nonnull align 8 dereferenceable(8) [[TMP0]])
// XDSO_TRAP-NEXT: ret void
//
// SPEC_TRAP-LABEL: define hidden void @test(
// SPEC_TRAP-SAME: ptr noundef [[S:%.*]]) #[[ATTR0:[0-9]+]] {
// SPEC_TRAP-NEXT: [[ENTRY:.*:]]
// SPEC_TRAP-NEXT: [[S_ADDR:%.*]] = alloca ptr, align 8
// SPEC_TRAP-NEXT: store ptr [[S]], ptr [[S_ADDR]], align 8
// SPEC_TRAP-NEXT: [[TMP0:%.*]] = load ptr, ptr [[S_ADDR]], align 8
// SPEC_TRAP-NEXT: [[VTABLE:%.*]] = load ptr, ptr [[TMP0]], align 8
// SPEC_TRAP-NEXT: [[TMP1:%.*]] = call i1 @llvm.type.test(ptr [[VTABLE]], metadata !"_ZTS1S"), !nosanitize [[META1:![0-9]+]]
// SPEC_TRAP-NEXT: br i1 [[TMP1]], label %[[CONT:.*]], label %[[TRAP:.*]], !prof [[PROF2:![0-9]+]], !nosanitize [[META1]]
// SPEC_TRAP: [[TRAP]]:
// SPEC_TRAP-NEXT: call void @llvm.ubsantrap(i8 2) #[[ATTR3:[0-9]+]], !nosanitize [[META1]]
// SPEC_TRAP-NEXT: unreachable, !nosanitize [[META1]]
// SPEC_TRAP: [[CONT]]:
// SPEC_TRAP-NEXT: [[VFN:%.*]] = getelementptr inbounds ptr, ptr [[VTABLE]], i64 0
// SPEC_TRAP-NEXT: [[TMP2:%.*]] = load ptr, ptr [[VFN]], align 8
// SPEC_TRAP-NEXT: call void [[TMP2]](ptr noundef nonnull align 8 dereferenceable(8) [[TMP0]])
// SPEC_TRAP-NEXT: ret void
//
extern "C" void test(S *s) {
s->f();
}
//.
// MIN: attributes #[[ATTR0]] = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
// MIN: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
// MIN: attributes #[[ATTR2:[0-9]+]] = { noreturn nounwind uwtable }
// MIN: attributes #[[ATTR3]] = { nomerge noreturn nounwind }
//.
// TRAP_CUTOFF: attributes #[[ATTR0]] = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
// TRAP_CUTOFF: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
// TRAP_CUTOFF: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
// TRAP_CUTOFF: attributes #[[ATTR3:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) }
// TRAP_CUTOFF: attributes #[[ATTR4]] = { nomerge }
//.
// XDSO_TRAP: attributes #[[ATTR0]] = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
// XDSO_TRAP: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
// XDSO_TRAP: attributes #[[ATTR2:[0-9]+]] = { noinline nounwind "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
// XDSO_TRAP: attributes #[[ATTR3:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) }
// XDSO_TRAP: attributes #[[ATTR4:[0-9]+]] = { noinline nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
// XDSO_TRAP: attributes #[[ATTR5]] = { nounwind }
// XDSO_TRAP: attributes #[[ATTR6:[0-9]+]] = { nomerge }
//.
// SPEC_TRAP: attributes #[[ATTR0]] = { mustprogress noinline nounwind optnone "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+mmx,+sse,+sse2,+x87" }
// SPEC_TRAP: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
// SPEC_TRAP: attributes #[[ATTR2:[0-9]+]] = { cold noreturn nounwind memory(inaccessiblemem: write) }
// SPEC_TRAP: attributes #[[ATTR3]] = { nomerge }
//.
// MIN: [[META0:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
// MIN: [[META1]] = !{}
// MIN: [[PROF2]] = !{!"branch_weights", i32 1048575, i32 1}
//.
// TRAP_CUTOFF: [[META0:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
// TRAP_CUTOFF: [[META1]] = !{}
// TRAP_CUTOFF: [[PROF2]] = !{!"branch_weights", i32 1048575, i32 1}
//.
// XDSO_TRAP: [[META0:![0-9]+]] = !{i32 4, !"Cross-DSO CFI", i32 1}
// XDSO_TRAP: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
// XDSO_TRAP: [[META2]] = !{}
// XDSO_TRAP: [[PROF3]] = !{!"branch_weights", i32 1048575, i32 1}
//.
// SPEC_TRAP: [[META0:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
// SPEC_TRAP: [[META1]] = !{}
// SPEC_TRAP: [[PROF2]] = !{!"branch_weights", i32 1048575, i32 1}
//.