[llvm-branch-commits] [clang] baf1cb6 - [clang][KCFI] Skip the KCFIPass on Hexagon (#211716)

Douglas Yung via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 20 13:48:17 PDT 2026


Author: Brian Cain
Date: 2026-08-20T20:48:03Z
New Revision: baf1cb68d5a01c0c76fcd63b0e1a43d2a90f0b39

URL: https://github.com/llvm/llvm-project/commit/baf1cb68d5a01c0c76fcd63b0e1a43d2a90f0b39
DIFF: https://github.com/llvm/llvm-project/commit/baf1cb68d5a01c0c76fcd63b0e1a43d2a90f0b39.diff

LOG: [clang][KCFI] Skip the KCFIPass on Hexagon (#211716)

Hexagon implements KCFI operand-bundle lowering in the back end
HexagonTargetLowering::EmitKCFICheck emits a KCFI_CHECK pseudo, which
HexagonAsmPrinter::LowerKCFI_CHECK expands into a type-hash check and a
trap - like PS_crash.

Hexagon was never added to the list in addKCFIPass() of targets whose
back end lowers the bundles, so Clang kept running the middle-end
KCFIPass for it.

Add Hexagon to the addKCFIPass() early-return so the "kcfi" bundles
reach the back end, which then emits the trapping load that actually
blocks the call.

(cherry picked from commit 23a601dc9690d42a0b6e69b10279a6f002708ee6)

Added: 
    clang/test/CodeGen/kcfi-hexagon.c

Modified: 
    clang/lib/CodeGen/BackendUtil.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 2b755fa916e55..e3ae446fbe81b 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -668,7 +668,8 @@ static void addKCFIPass(const Triple &TargetTriple, const LangOptions &LangOpts,
   // If the back-end supports KCFI operand bundle lowering, skip KCFIPass.
   if (TargetTriple.getArch() == llvm::Triple::x86_64 ||
       TargetTriple.isAArch64(64) || TargetTriple.isRISCV() ||
-      TargetTriple.isARM() || TargetTriple.isThumb())
+      TargetTriple.isARM() || TargetTriple.isThumb() ||
+      TargetTriple.getArch() == llvm::Triple::hexagon)
     return;
 
   // Ensure we lower KCFI operand bundles with -O0.

diff  --git a/clang/test/CodeGen/kcfi-hexagon.c b/clang/test/CodeGen/kcfi-hexagon.c
new file mode 100644
index 0000000000000..b08758d4b81a4
--- /dev/null
+++ b/clang/test/CodeGen/kcfi-hexagon.c
@@ -0,0 +1,14 @@
+// Hexagon lowers KCFI operand bundles in the back end. Clang must leave the "kcfi"
+// operand bundles in place for the back end instead of running the middle-end
+// KCFIPass, which would rewrite them into a software llvm.debugtrap check.
+//
+// Verify the bundle survives the optimizer pipeline at both -O0 and -O2 and
+// is not lowered to debugtrap.
+//
+// RUN: %clang_cc1 -triple hexagon-unknown-linux-musl -O0 -fsanitize=kcfi -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple hexagon-unknown-linux-musl -O2 -fsanitize=kcfi -emit-llvm -o - %s | FileCheck %s
+
+// CHECK-LABEL: define {{.*}}void @call(
+// CHECK: call void %{{.*}}() {{.*}}[ "kcfi"(i32 {{-?[0-9]+}}) ]
+// CHECK-NOT: @llvm.debugtrap
+void call(void (*f)(void)) { f(); }


        


More information about the llvm-branch-commits mailing list