diff options
author | Oliver Hunt <oliver@apple.com> | 2025-06-04 00:21:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-06-04 00:21:20 -0700 |
commit | 93314bd9462d5c41a23fb402be7ae0c7d099e274 (patch) | |
tree | 1f0d1875d646ac9783eb12da95237ba60a6defd3 /clang/lib/CodeGen | |
parent | e8b0a16f0c0126555fbb4062c715b59e3e5e727b (diff) | |
download | llvm-93314bd9462d5c41a23fb402be7ae0c7d099e274.zip llvm-93314bd9462d5c41a23fb402be7ae0c7d099e274.tar.gz llvm-93314bd9462d5c41a23fb402be7ae0c7d099e274.tar.bz2 |
[clang][PAC] Add __builtin_get_vtable_pointer (#139790)
With pointer authentication it becomes non-trivial to correctly load the
vtable pointer of a polymorphic object.
__builtin_get_vtable_pointer is a function that performs the load and
performs the appropriate authentication operations if necessary.
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 369cff3..dff2334 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -17,6 +17,7 @@ #include "CGDebugInfo.h" #include "CGObjCRuntime.h" #include "CGOpenCLRuntime.h" +#include "CGPointerAuthInfo.h" #include "CGRecordLayout.h" #include "CGValue.h" #include "CodeGenFunction.h" @@ -5621,6 +5622,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, return RValue::get(Result); } + case Builtin::BI__builtin_get_vtable_pointer: { + const Expr *Target = E->getArg(0); + QualType TargetType = Target->getType(); + const CXXRecordDecl *Decl = TargetType->getPointeeCXXRecordDecl(); + assert(Decl); + auto ThisAddress = EmitPointerWithAlignment(Target); + assert(ThisAddress.isValid()); + llvm::Value *VTablePointer = + GetVTablePtr(ThisAddress, Int8PtrTy, Decl, VTableAuthMode::MustTrap); + return RValue::get(VTablePointer); + } + case Builtin::BI__exception_code: case Builtin::BI_exception_code: return RValue::get(EmitSEHExceptionCode()); |