aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGClass.cpp
diff options
context:
space:
mode:
authorPiJoules <6019989+PiJoules@users.noreply.github.com>2025-02-28 12:26:29 -0800
committerGitHub <noreply@github.com>2025-02-28 12:26:29 -0800
commitd9edca4fe05245ace93f7f1577a2eb79ec6898b1 (patch)
treecf44f2e8ca8423d12d28095551912dbac8bca43d /clang/lib/CodeGen/CGClass.cpp
parentb8337bc5126d2728f84ce0e06bd019c486203b31 (diff)
downloadllvm-d9edca4fe05245ace93f7f1577a2eb79ec6898b1.zip
llvm-d9edca4fe05245ace93f7f1577a2eb79ec6898b1.tar.gz
llvm-d9edca4fe05245ace93f7f1577a2eb79ec6898b1.tar.bz2
[CodeGen] Ensure relative vtables use llvm.type.checked.load.relative (#126785)
This intrinsic is used when whole program vtables is used in conjunction with either CFI or virtual function elimination. The `llvm.type.checked.load` is unconditionally used, but we need to use the relative intrinsic for WPD and CFI to work correctly.
Diffstat (limited to 'clang/lib/CodeGen/CGClass.cpp')
-rw-r--r--clang/lib/CodeGen/CGClass.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 7a1096f..fa69caa4 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -2937,9 +2937,13 @@ llvm::Value *CodeGenFunction::EmitVTableTypeCheckedLoad(
CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
llvm::Value *TypeId = llvm::MetadataAsValue::get(CGM.getLLVMContext(), MD);
+ auto CheckedLoadIntrinsic = CGM.getVTables().useRelativeLayout()
+ ? llvm::Intrinsic::type_checked_load_relative
+ : llvm::Intrinsic::type_checked_load;
llvm::Value *CheckedLoad = Builder.CreateCall(
- CGM.getIntrinsic(llvm::Intrinsic::type_checked_load),
+ CGM.getIntrinsic(CheckedLoadIntrinsic),
{VTable, llvm::ConstantInt::get(Int32Ty, VTableByteOffset), TypeId});
+
llvm::Value *CheckResult = Builder.CreateExtractValue(CheckedLoad, 1);
std::string TypeName = RD->getQualifiedNameAsString();