[llvm-branch-commits] [clang] [Clang][CFI] Require -fwhole-program-vtables for llvm.type.checked.load (PR #241643)

Vitaly Buka via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 11 19:57:31 PST 2026


https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/241643

>From c70951c7350657984d8a854272492cca537b16cd Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 11 Nov 2026 19:05:39 -0800
Subject: [PATCH] [spr] update

Created using spr 2.0.0-beta.2
---
 clang/lib/CodeGen/CGClass.cpp              |  5 ++---
 clang/test/CodeGenCXX/cfi-vtable-check.cpp | 12 ++++++------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 00bc1eb0848d4..a1b61394571d4 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2980,9 +2980,8 @@ void CodeGenFunction::EmitVTableCheck(CFITypeCheckKind TCK, CanQualType T,
 }
 
 bool CodeGenFunction::ShouldEmitVTableTypeCheckedLoad(const CXXRecordDecl *RD) {
-  if ((!CGM.getCodeGenOpts().WholeProgramVTables ||
-       !CGM.HasHiddenLTOVisibility(RD)) &&
-      !CGM.getCodeGenOpts().DevirtualizeSpeculatively)
+  if (!CGM.getCodeGenOpts().WholeProgramVTables ||
+      !CGM.HasHiddenLTOVisibility(RD))
     return false;
 
   if (CGM.getCodeGenOpts().VirtualFunctionElimination)
diff --git a/clang/test/CodeGenCXX/cfi-vtable-check.cpp b/clang/test/CodeGenCXX/cfi-vtable-check.cpp
index 75fa25d047550..b5badb3b71162 100644
--- a/clang/test/CodeGenCXX/cfi-vtable-check.cpp
+++ b/clang/test/CodeGenCXX/cfi-vtable-check.cpp
@@ -75,15 +75,15 @@ struct S {
 // 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 { ptr, i1 } @llvm.type.checked.load(ptr [[VTABLE]], i32 0, metadata !"_ZTS1S"), !nosanitize [[META1:![0-9]+]]
-// SPEC_TRAP-NEXT:    [[TMP2:%.*]] = extractvalue { ptr, i1 } [[TMP1]], 1, !nosanitize [[META1]]
-// SPEC_TRAP-NEXT:    br i1 [[TMP2]], label %[[CONT:.*]], label %[[TRAP:.*]], !prof [[PROF2:![0-9]+]], !nosanitize [[META1]]
+// 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:    [[TMP3:%.*]] = extractvalue { ptr, i1 } [[TMP1]], 0, !nosanitize [[META1]]
-// SPEC_TRAP-NEXT:    call void [[TMP3]](ptr noundef nonnull align 8 dereferenceable(8) [[TMP0]])
+// 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) {
@@ -110,7 +110,7 @@ extern "C" void test(S *s) {
 // XDSO_TRAP: attributes #[[ATTR6:[0-9]+]] = { nomerge noreturn nounwind }
 //.
 // 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 willreturn memory(none) }
+// 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 noreturn nounwind }
 //.



More information about the llvm-branch-commits mailing list