Skip to content

[cfi][NFCI] Precommit tests to show nomerge functionality #135104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2025

Conversation

thurstond
Copy link
Contributor

#120464 (and earlier CLs) added -fsanitize-merge functionality, which is intended to work for all "sanitizers". It is nearly correct for CFI.

This patch precommits some tests for CFI, to track the progress of future -fsanitize-merge fixes for CFI.

llvm#120464 (and earlier CLs) added -fsanitize-merge functionality, which is intended to work for all "sanitizers". It is nearly correct for CFI.

This patch precommits some tests for CFI, to track the progress of
future -fsanitize-merge fixes.
@thurstond thurstond requested review from pcc and vitalybuka April 10, 2025 00:05
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 10, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 10, 2025

@llvm/pr-subscribers-clang

Author: Thurston Dang (thurstond)

Changes

#120464 (and earlier CLs) added -fsanitize-merge functionality, which is intended to work for all "sanitizers". It is nearly correct for CFI.

This patch precommits some tests for CFI, to track the progress of future -fsanitize-merge fixes for CFI.


Patch is 36.55 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/135104.diff

3 Files Affected:

  • (added) clang/test/CodeGen/cfi-check-fail-nomerge.c (+232)
  • (added) clang/test/CodeGen/cfi-check-fail2-nomerge.c (+206)
  • (added) clang/test/CodeGenCXX/cfi-mfcall-nomerge.cpp (+131)
diff --git a/clang/test/CodeGen/cfi-check-fail-nomerge.c b/clang/test/CodeGen/cfi-check-fail-nomerge.c
new file mode 100644
index 0000000000000..05ea8d8327904
--- /dev/null
+++ b/clang/test/CodeGen/cfi-check-fail-nomerge.c
@@ -0,0 +1,232 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --version 5
+//
+// N.B. although the clang driver defaults to merge, clang_cc1 defaults to non-merge.
+// (This is similar to -fsanitize-recover, for which the default is also applied
+// at the driver level only.)
+// If optimization is disabled, merging is disabled (overrides -fsanitize-merge).
+
+// RUN: %clang_cc1 -O3 -triple x86_64-unknown-linux -fsanitize-cfi-cross-dso \
+// RUN:     -fsanitize=cfi-icall,cfi-nvcall,cfi-vcall,cfi-unrelated-cast,cfi-derived-cast \
+// RUN:     -fsanitize-trap=cfi-icall,cfi-nvcall \
+// RUN:     -fsanitize-merge=cfi-icall,cfi-nvcall \
+// RUN:     -emit-llvm -o - %s | FileCheck %s --check-prefix=MERGE
+
+// RUN: %clang_cc1 -O3 -triple x86_64-unknown-linux -fsanitize-cfi-cross-dso \
+// RUN:     -fsanitize=cfi-icall,cfi-nvcall,cfi-vcall,cfi-unrelated-cast,cfi-derived-cast \
+// RUN:     -fsanitize-trap=cfi-icall,cfi-nvcall \
+// RUN:     -emit-llvm -o - %s | FileCheck %s --check-prefix=NO-MERGE
+
+// NOMERGE-LABEL: define dso_local void @caller(
+// NOMERGE-SAME: ptr noundef [[F:%.*]]) #[[ATTR0:[0-9]+]] !type [[META4:![0-9]+]] !type [[META5:![0-9]+]] !type [[META6:![0-9]+]] {
+// NOMERGE-NEXT:  [[ENTRY:.*:]]
+// NOMERGE-NEXT:    [[F_ADDR:%.*]] = alloca ptr, align 8
+// NOMERGE-NEXT:    store ptr [[F]], ptr [[F_ADDR]], align 8
+// NOMERGE-NEXT:    [[TMP0:%.*]] = load ptr, ptr [[F_ADDR]], align 8
+// NOMERGE-NEXT:    [[TMP1:%.*]] = call i1 @llvm.type.test(ptr [[TMP0]], metadata !"_ZTSFvvE"), !nosanitize [[META7:![0-9]+]]
+// NOMERGE-NEXT:    br i1 [[TMP1]], label %[[CFI_CONT:.*]], label %[[CFI_SLOWPATH:.*]], !prof [[PROF8:![0-9]+]], !nosanitize [[META7]]
+// NOMERGE:       [[CFI_SLOWPATH]]:
+// NOMERGE-NEXT:    call void @__cfi_slowpath(i64 9080559750644022485, ptr [[TMP0]]) #[[ATTR7:[0-9]+]], !nosanitize [[META7]]
+// NOMERGE-NEXT:    br label %[[CFI_CONT]], !nosanitize [[META7]]
+// NOMERGE:       [[CFI_CONT]]:
+// NOMERGE-NEXT:    call void [[TMP0]]()
+// NOMERGE-NEXT:    ret void
+void caller(void (*f)(void)) {
+  f();
+}
+
+
+
+// MERGE-LABEL: define dso_local void @caller(
+// MERGE-SAME: ptr noundef [[F:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !type [[META4:![0-9]+]] !type [[META5:![0-9]+]] !type [[META6:![0-9]+]] {
+// MERGE-NEXT:  [[ENTRY:.*:]]
+// MERGE-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[F]], metadata !"_ZTSFvvE"), !nosanitize [[META7:![0-9]+]]
+// MERGE-NEXT:    br i1 [[TMP0]], label %[[CFI_CONT:.*]], label %[[CFI_SLOWPATH:.*]], !prof [[PROF8:![0-9]+]], !nosanitize [[META7]]
+// MERGE:       [[CFI_SLOWPATH]]:
+// MERGE-NEXT:    tail call void @__cfi_slowpath(i64 9080559750644022485, ptr [[F]]) #[[ATTR5:[0-9]+]], !nosanitize [[META7]]
+// MERGE-NEXT:    br label %[[CFI_CONT]], !nosanitize [[META7]]
+// MERGE:       [[CFI_CONT]]:
+// MERGE-NEXT:    tail call void [[F]]() #[[ATTR5]]
+// MERGE-NEXT:    ret void
+//
+//
+// MERGE-LABEL: define weak_odr hidden void @__cfi_check_fail(
+// MERGE-SAME: ptr noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]]) #[[ATTR0]] {
+// MERGE-NEXT:  [[ENTRY:.*:]]
+// MERGE-NEXT:    [[DOTNOT:%.*]] = icmp eq ptr [[TMP0]], null, !nosanitize [[META7]]
+// MERGE-NEXT:    br i1 [[DOTNOT]], label %[[TRAP:.*]], label %[[CONT:.*]], !prof [[PROF9:![0-9]+]], !nosanitize [[META7]]
+// MERGE:       [[TRAP]]:
+// MERGE-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR6:[0-9]+]], !nosanitize [[META7]]
+// MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// MERGE:       [[CONT]]:
+// MERGE-NEXT:    [[TMP2:%.*]] = load i8, ptr [[TMP0]], align 4, !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP3:%.*]] = tail call i1 @llvm.type.test(ptr [[TMP1]], metadata !"all-vtables"), !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP4:%.*]] = zext i1 [[TMP3]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    switch i8 [[TMP2]], label %[[CONT8:.*]] [
+// MERGE-NEXT:      i8 0, label %[[HANDLER_CFI_CHECK_FAIL:.*]]
+// MERGE-NEXT:      i8 1, label %[[TRAP]]
+// MERGE-NEXT:      i8 2, label %[[HANDLER_CFI_CHECK_FAIL4:.*]]
+// MERGE-NEXT:      i8 3, label %[[HANDLER_CFI_CHECK_FAIL6:.*]]
+// MERGE-NEXT:      i8 4, label %[[TRAP]]
+// MERGE-NEXT:    ], !prof [[PROF10:![0-9]+]]
+// MERGE:       [[HANDLER_CFI_CHECK_FAIL]]:
+// MERGE-NEXT:    [[TMP5:%.*]] = ptrtoint ptr [[TMP0]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP6:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP5]], i64 [[TMP6]], i64 [[TMP4]]) #[[ATTR7:[0-9]+]], !nosanitize [[META7]]
+// MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// MERGE:       [[HANDLER_CFI_CHECK_FAIL4]]:
+// MERGE-NEXT:    [[TMP7:%.*]] = ptrtoint ptr [[TMP0]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP8:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP7]], i64 [[TMP8]], i64 [[TMP4]]) #[[ATTR7]], !nosanitize [[META7]]
+// MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// MERGE:       [[HANDLER_CFI_CHECK_FAIL6]]:
+// MERGE-NEXT:    [[TMP9:%.*]] = ptrtoint ptr [[TMP0]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP10:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP9]], i64 [[TMP10]], i64 [[TMP4]]) #[[ATTR7]], !nosanitize [[META7]]
+// MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// MERGE:       [[CONT8]]:
+// MERGE-NEXT:    ret void, !nosanitize [[META7]]
+//
+//
+// MERGE-LABEL: define weak void @__cfi_check(
+// MERGE-SAME: i64 noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]], ptr noundef [[TMP2:%.*]]) local_unnamed_addr #[[ATTR4:[0-9]+]] align 4096 {
+// MERGE-NEXT:  [[ENTRY:.*:]]
+// MERGE-NEXT:    [[DOTNOT_I:%.*]] = icmp eq ptr [[TMP2]], null, !nosanitize [[META7]]
+// MERGE-NEXT:    br i1 [[DOTNOT_I]], label %[[TRAP_I:.*]], label %[[CONT_I:.*]], !prof [[PROF9]], !nosanitize [[META7]]
+// MERGE:       [[TRAP_I]]:
+// MERGE-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR6]], !nosanitize [[META7]]
+// MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// MERGE:       [[CONT_I]]:
+// MERGE-NEXT:    [[TMP3:%.*]] = load i8, ptr [[TMP2]], align 4, !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP4:%.*]] = tail call i1 @llvm.type.test(ptr [[TMP1]], metadata !"all-vtables"), !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP5:%.*]] = zext i1 [[TMP4]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    switch i8 [[TMP3]], label %[[__CFI_CHECK_FAIL_EXIT:.*]] [
+// MERGE-NEXT:      i8 0, label %[[HANDLER_CFI_CHECK_FAIL_I:.*]]
+// MERGE-NEXT:      i8 1, label %[[TRAP_I]]
+// MERGE-NEXT:      i8 2, label %[[HANDLER_CFI_CHECK_FAIL4_I:.*]]
+// MERGE-NEXT:      i8 3, label %[[HANDLER_CFI_CHECK_FAIL6_I:.*]]
+// MERGE-NEXT:      i8 4, label %[[TRAP_I]]
+// MERGE-NEXT:    ], !prof [[PROF10]]
+// MERGE:       [[HANDLER_CFI_CHECK_FAIL_I]]:
+// MERGE-NEXT:    [[TMP6:%.*]] = ptrtoint ptr [[TMP2]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP7:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP6]], i64 [[TMP7]], i64 [[TMP5]]) #[[ATTR7]], !nosanitize [[META7]]
+// MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// MERGE:       [[HANDLER_CFI_CHECK_FAIL4_I]]:
+// MERGE-NEXT:    [[TMP8:%.*]] = ptrtoint ptr [[TMP2]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP9:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP8]], i64 [[TMP9]], i64 [[TMP5]]) #[[ATTR7]], !nosanitize [[META7]]
+// MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// MERGE:       [[HANDLER_CFI_CHECK_FAIL6_I]]:
+// MERGE-NEXT:    [[TMP10:%.*]] = ptrtoint ptr [[TMP2]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    [[TMP11:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP10]], i64 [[TMP11]], i64 [[TMP5]]) #[[ATTR7]], !nosanitize [[META7]]
+// MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// MERGE:       [[__CFI_CHECK_FAIL_EXIT]]:
+// MERGE-NEXT:    ret void
+//
+//
+// NO-MERGE-LABEL: define dso_local void @caller(
+// NO-MERGE-SAME: ptr noundef [[F:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !type [[META4:![0-9]+]] !type [[META5:![0-9]+]] !type [[META6:![0-9]+]] {
+// NO-MERGE-NEXT:  [[ENTRY:.*:]]
+// NO-MERGE-NEXT:    [[TMP0:%.*]] = tail call i1 @llvm.type.test(ptr [[F]], metadata !"_ZTSFvvE"), !nosanitize [[META7:![0-9]+]]
+// NO-MERGE-NEXT:    br i1 [[TMP0]], label %[[CFI_CONT:.*]], label %[[CFI_SLOWPATH:.*]], !prof [[PROF8:![0-9]+]], !nosanitize [[META7]]
+// NO-MERGE:       [[CFI_SLOWPATH]]:
+// NO-MERGE-NEXT:    tail call void @__cfi_slowpath(i64 9080559750644022485, ptr [[F]]) #[[ATTR5:[0-9]+]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    br label %[[CFI_CONT]], !nosanitize [[META7]]
+// NO-MERGE:       [[CFI_CONT]]:
+// NO-MERGE-NEXT:    tail call void [[F]]() #[[ATTR5]]
+// NO-MERGE-NEXT:    ret void
+//
+//
+// NO-MERGE-LABEL: define weak_odr hidden void @__cfi_check_fail(
+// NO-MERGE-SAME: ptr noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]]) #[[ATTR0]] {
+// NO-MERGE-NEXT:  [[ENTRY:.*:]]
+// NO-MERGE-NEXT:    [[DOTNOT:%.*]] = icmp eq ptr [[TMP0]], null, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    br i1 [[DOTNOT]], label %[[TRAP:.*]], label %[[CONT:.*]], !prof [[PROF9:![0-9]+]], !nosanitize [[META7]]
+// NO-MERGE:       [[TRAP]]:
+// NO-MERGE-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR6:[0-9]+]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[CONT]]:
+// NO-MERGE-NEXT:    [[TMP2:%.*]] = load i8, ptr [[TMP0]], align 4, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP3:%.*]] = tail call i1 @llvm.type.test(ptr [[TMP1]], metadata !"all-vtables"), !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP4:%.*]] = zext i1 [[TMP3]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    switch i8 [[TMP2]], label %[[CONT10:.*]] [
+// NO-MERGE-NEXT:      i8 0, label %[[HANDLER_CFI_CHECK_FAIL:.*]]
+// NO-MERGE-NEXT:      i8 1, label %[[TRAP3:.*]]
+// NO-MERGE-NEXT:      i8 2, label %[[HANDLER_CFI_CHECK_FAIL5:.*]]
+// NO-MERGE-NEXT:      i8 3, label %[[HANDLER_CFI_CHECK_FAIL7:.*]]
+// NO-MERGE-NEXT:      i8 4, label %[[TRAP9:.*]]
+// NO-MERGE-NEXT:    ], !prof [[PROF10:![0-9]+]]
+// NO-MERGE:       [[HANDLER_CFI_CHECK_FAIL]]:
+// NO-MERGE-NEXT:    [[TMP5:%.*]] = ptrtoint ptr [[TMP0]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP6:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP5]], i64 [[TMP6]], i64 [[TMP4]]) #[[ATTR7:[0-9]+]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[TRAP3]]:
+// NO-MERGE-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR7]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[HANDLER_CFI_CHECK_FAIL5]]:
+// NO-MERGE-NEXT:    [[TMP7:%.*]] = ptrtoint ptr [[TMP0]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP8:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP7]], i64 [[TMP8]], i64 [[TMP4]]) #[[ATTR7]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[HANDLER_CFI_CHECK_FAIL7]]:
+// NO-MERGE-NEXT:    [[TMP9:%.*]] = ptrtoint ptr [[TMP0]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP10:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP9]], i64 [[TMP10]], i64 [[TMP4]]) #[[ATTR7]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[TRAP9]]:
+// NO-MERGE-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR7]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[CONT10]]:
+// NO-MERGE-NEXT:    ret void, !nosanitize [[META7]]
+//
+//
+// NO-MERGE-LABEL: define weak void @__cfi_check(
+// NO-MERGE-SAME: i64 noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]], ptr noundef [[TMP2:%.*]]) local_unnamed_addr #[[ATTR4:[0-9]+]] align 4096 {
+// NO-MERGE-NEXT:  [[ENTRY:.*:]]
+// NO-MERGE-NEXT:    [[DOTNOT_I:%.*]] = icmp eq ptr [[TMP2]], null, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    br i1 [[DOTNOT_I]], label %[[TRAP_I:.*]], label %[[CONT_I:.*]], !prof [[PROF9]], !nosanitize [[META7]]
+// NO-MERGE:       [[TRAP_I]]:
+// NO-MERGE-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR6]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[CONT_I]]:
+// NO-MERGE-NEXT:    [[TMP3:%.*]] = load i8, ptr [[TMP2]], align 4, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP4:%.*]] = tail call i1 @llvm.type.test(ptr [[TMP1]], metadata !"all-vtables"), !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP5:%.*]] = zext i1 [[TMP4]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    switch i8 [[TMP3]], label %[[__CFI_CHECK_FAIL_EXIT:.*]] [
+// NO-MERGE-NEXT:      i8 0, label %[[HANDLER_CFI_CHECK_FAIL_I:.*]]
+// NO-MERGE-NEXT:      i8 1, label %[[TRAP3_I:.*]]
+// NO-MERGE-NEXT:      i8 2, label %[[HANDLER_CFI_CHECK_FAIL5_I:.*]]
+// NO-MERGE-NEXT:      i8 3, label %[[HANDLER_CFI_CHECK_FAIL7_I:.*]]
+// NO-MERGE-NEXT:      i8 4, label %[[TRAP9_I:.*]]
+// NO-MERGE-NEXT:    ], !prof [[PROF10]]
+// NO-MERGE:       [[HANDLER_CFI_CHECK_FAIL_I]]:
+// NO-MERGE-NEXT:    [[TMP6:%.*]] = ptrtoint ptr [[TMP2]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP7:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP6]], i64 [[TMP7]], i64 [[TMP5]]) #[[ATTR7]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[TRAP3_I]]:
+// NO-MERGE-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR7]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[HANDLER_CFI_CHECK_FAIL5_I]]:
+// NO-MERGE-NEXT:    [[TMP8:%.*]] = ptrtoint ptr [[TMP2]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP9:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP8]], i64 [[TMP9]], i64 [[TMP5]]) #[[ATTR7]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[HANDLER_CFI_CHECK_FAIL7_I]]:
+// NO-MERGE-NEXT:    [[TMP10:%.*]] = ptrtoint ptr [[TMP2]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    [[TMP11:%.*]] = ptrtoint ptr [[TMP1]] to i64, !nosanitize [[META7]]
+// NO-MERGE-NEXT:    tail call void @__ubsan_handle_cfi_check_fail_abort(i64 [[TMP10]], i64 [[TMP11]], i64 [[TMP5]]) #[[ATTR7]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[TRAP9_I]]:
+// NO-MERGE-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR7]], !nosanitize [[META7]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META7]]
+// NO-MERGE:       [[__CFI_CHECK_FAIL_EXIT]]:
+// NO-MERGE-NEXT:    ret void
+
+// MERGE: [[ATTR5]] = { nounwind }
+// MERGE: [[ATTR6]] = { noreturn nounwind }
+
+// NO-MERGE: [[ATTR6]] = { noreturn nounwind }
+// NO-MERGE: [[ATTR7]] = { nomerge noreturn nounwind }
diff --git a/clang/test/CodeGen/cfi-check-fail2-nomerge.c b/clang/test/CodeGen/cfi-check-fail2-nomerge.c
new file mode 100644
index 0000000000000..76ebec9c08c11
--- /dev/null
+++ b/clang/test/CodeGen/cfi-check-fail2-nomerge.c
@@ -0,0 +1,206 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --include-generated-funcs --version 5
+// __cfi_check_fail codegen when not all CFI checkers are enabled.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O3 -fsanitize-cfi-cross-dso \
+// RUN:     -fsanitize=cfi-vcall \
+// RUN:     -emit-llvm -o - %s | FileCheck %s --check-prefix=NO-MERGE
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -O3 -fsanitize-cfi-cross-dso \
+// RUN:     -fsanitize=cfi-vcall \
+// RUN:     -fsanitize-merge=cfi-vcall \
+// RUN:     -emit-llvm -o - %s | FileCheck %s --check-prefix=MERGE
+
+void caller(void (*f)(void)) {
+  f();
+}
+
+// CHECK: define weak_odr hidden void @__cfi_check_fail(ptr noundef %0, ptr noundef %1)
+// CHECK: store ptr %0, ptr %[[ALLOCA0:.*]], align 8
+// CHECK: store ptr %1, ptr %[[ALLOCA1:.*]], align 8
+// CHECK: %[[DATA:.*]] = load ptr, ptr %[[ALLOCA0]], align 8
+// CHECK: %[[ADDR:.*]] = load ptr, ptr %[[ALLOCA1]], align 8
+// CHECK: %[[ICMP_NOT_NULL:.*]] = icmp ne ptr %[[DATA]], null
+// CHECK: br i1 %[[ICMP_NOT_NULL]], label %[[CONT0:.*]], label %[[TRAP:.*]], !prof
+
+// CHECK: [[TRAP]]:
+// CHECK-NEXT:   call void @llvm.ubsantrap(i8 2)
+// CHECK-NEXT:   unreachable
+
+// CHECK: [[CONT0]]:
+// CHECK:   %[[KINDPTR:.*]] = getelementptr {{.*}} %[[DATA]], i32 0, i32 0
+// CHECK:   %[[KIND:.*]] = load i8, ptr %[[KINDPTR]], align 4
+// CHECK:   %[[VTVALID0:.*]] = call i1 @llvm.type.test(ptr %[[ADDR]], metadata !"all-vtables")
+// CHECK:   %[[VTVALID:.*]] = zext i1 %[[VTVALID0]] to i64
+// CHECK:   %[[NOT_0:.*]] = icmp ne i8 %[[KIND]], 0
+// CHECK:   br i1 %[[NOT_0]], label %[[CONT1:.*]], label %[[HANDLE0:.*]], !prof
+
+// CHECK: [[HANDLE0]]:
+// CHECK:   %[[DATA0:.*]] = ptrtoint ptr %[[DATA]] to i64,
+// CHECK:   %[[ADDR0:.*]] = ptrtoint ptr %[[ADDR]] to i64,
+// CHECK:   call void @__ubsan_handle_cfi_check_fail_abort(i64 %[[DATA0]], i64 %[[ADDR0]], i64 %[[VTVALID]])
+// CHECK:   unreachable
+
+// CHECK: [[CONT1]]:
+// CHECK:   %[[NOT_1:.*]] = icmp ne i8 %[[KIND]], 1
+// CHECK:   br i1 %[[NOT_1]], label %[[CONT2:.*]], label %[[HANDLE1:.*]], !prof
+
+// CHECK: [[HANDLE1]]:
+// CHECK-NEXT:   call void @llvm.ubsantrap(i8 2)
+// CHECK-NEXT:   unreachable
+
+// CHECK: [[CONT2]]:
+// CHECK:   %[[NOT_2:.*]] = icmp ne i8 %[[KIND]], 2
+// CHECK:   br i1 %[[NOT_2]], label %[[CONT3:.*]], label %[[HANDLE2:.*]], !prof
+
+// CHECK: [[HANDLE2]]:
+// CHECK-NEXT:   call void @llvm.ubsantrap(i8 2)
+// CHECK-NEXT:   unreachable
+
+// CHECK: [[CONT3]]:
+// CHECK:   %[[NOT_3:.*]] = icmp ne i8 %[[KIND]], 3
+// CHECK:   br i1 %[[NOT_3]], label %[[CONT4:.*]], label %[[HANDLE3:.*]], !prof
+
+// CHECK: [[HANDLE3]]:
+// CHECK-NEXT:   call void @llvm.ubsantrap(i8 2)
+// CHECK-NEXT:   unreachable
+
+// CHECK: [[CONT4]]:
+// CHECK:   %[[NOT_4:.*]] = icmp ne i8 %[[KIND]], 4
+// CHECK:   br i1 %[[NOT_4]], label %[[CONT5:.*]], label %[[HANDLE4:.*]], !prof
+
+// CHECK: [[HANDLE4]]:
+// CHECK-NEXT:   call void @llvm.ubsantrap(i8 2)
+// CHECK-NEXT:   unreachable
+
+// CHECK: [[CONT5]]:
+// CHECK:   ret void
+// NO-MERGE-LABEL: define dso_local void @caller(
+// NO-MERGE-SAME: ptr noundef readonly captures(none) [[F:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// NO-MERGE-NEXT:  [[ENTRY:.*:]]
+// NO-MERGE-NEXT:    tail call void [[F]]() #[[ATTR5:[0-9]+]]
+// NO-MERGE-NEXT:    ret void
+//
+//
+// NO-MERGE-LABEL: define weak_odr hidden void @__cfi_check_fail(
+// NO-MERGE-SAME: ptr noundef [[TMP0:%.*]], ptr noundef [[TMP1:%.*]]) #[[ATTR0]] {
+// NO-MERGE-NEXT:  [[ENTRY:.*:]]
+// NO-MERGE-NEXT:    [[DOTNOT:%.*]] = icmp eq ptr [[TMP0]], null, !nosanitize [[META3:![0-9]+]]
+// NO-MERGE-NEXT:    br i1 [[DOTNOT]], label %[[TRAP:.*]], label %[[CONT:.*]], !prof [[PROF4:![0-9]+]], !nosanitize [[META3]]
+// NO-MERGE:       [[TRAP]]:
+// NO-MERGE-NEXT:    tail call void @llvm.ubsantrap(i8 2) #[[ATTR6:[0-9]+]], !nosanitize [[META3]]
+// NO-MERGE-NEXT:    unreachable, !nosanitize [[META3]]
+// NO-MERGE:       [[CONT]]:
+// NO-MERGE-NEXT:    [[TMP2:%.*]] = load i8, ptr [[TMP0]], align 4, !nosanitize [[META3]]
+// NO-MERGE-NEXT:    switch i8 [[TMP2]], label %[[CONT6:.*]] [
+// NO-MERGE-NEXT:      i8 0, label %[[HANDLER_CFI_CHECK_FAIL:.*]]
+// NO-MERGE-NEXT:      i8 1, label %[[TRAP]]
+// NO-MERGE-NEXT:      i8 2, label %[[TRAP]]
+// NO-MERGE-NEXT:      i8 3, label %[[TRAP]]
+// NO-MERGE-NEXT:      i8 4, label %[[TRAP]]
+// NO-MERGE-NEXT:    ], !p...
[truncated]

@thurstond thurstond merged commit d1badf5 into llvm:main Apr 10, 2025
13 checks passed
AllinLeeYL pushed a commit to AllinLeeYL/llvm-project that referenced this pull request Apr 10, 2025
llvm#120464 (and earlier CLs) added -fsanitize-merge functionality, which is intended to work for all "sanitizers". It is nearly correct for CFI.

This patch precommits some tests for CFI, to track the progress of future -fsanitize-merge fixes for CFI.
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
llvm#120464 (and earlier CLs) added -fsanitize-merge functionality, which is intended to work for all "sanitizers". It is nearly correct for CFI.

This patch precommits some tests for CFI, to track the progress of future -fsanitize-merge fixes for CFI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants