[clang] [PAC] Add support for __ptrauth type qualifier (PR #100830)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 20 08:03:22 PST 2025
================
@@ -166,6 +193,88 @@ CGPointerAuthInfo CodeGenModule::getPointerAuthInfoForType(QualType T) {
return ::getPointerAuthInfoForType(*this, T);
}
+static std::pair<llvm::Value *, CGPointerAuthInfo>
+emitLoadOfOrigPointerRValue(CodeGenFunction &CGF, const LValue &LV,
+ SourceLocation Loc) {
+ auto *Value = CGF.EmitLoadOfScalar(LV, Loc);
+ CGPointerAuthInfo AuthInfo;
+ if (PointerAuthQualifier PtrAuth = LV.getQuals().getPointerAuth())
+ AuthInfo = CGF.EmitPointerAuthInfo(PtrAuth, LV.getAddress());
+ else
+ AuthInfo = getPointerAuthInfoForType(CGF.CGM, LV.getType());
+ return {Value, AuthInfo};
+}
+
+/// Retrieve a pointer rvalue and its ptrauth info. When possible, avoid
+/// needlessly resigning the pointer.
+std::pair<llvm::Value *, CGPointerAuthInfo>
+CodeGenFunction::EmitOrigPointerRValue(const Expr *E) {
+ assert(E->getType()->isSignableType());
+
+ E = E->IgnoreParens();
+ if (const auto *Load = dyn_cast<ImplicitCastExpr>(E)) {
+ if (Load->getCastKind() == CK_LValueToRValue) {
+ E = Load->getSubExpr()->IgnoreParens();
+
+ // We're semantically required to not emit loads of certain DREs naively.
+ if (const auto *RefExpr = dyn_cast<DeclRefExpr>(E)) {
+ if (auto Result = tryEmitAsConstant(RefExpr)) {
----------------
AaronBallman wrote:
Please spell out the type.
https://github.com/llvm/llvm-project/pull/100830
More information about the cfe-commits
mailing list