[clang] [PAC] Implement function pointer re-signing (PR #98847)
Daniil Kovalev via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 15 06:48:41 PDT 2024
================
@@ -165,6 +166,88 @@ CGPointerAuthInfo CodeGenModule::getPointerAuthInfoForType(QualType T) {
return ::getPointerAuthInfoForType(*this, T);
}
+static bool isZeroConstant(llvm::Value *value) {
+ if (auto ci = dyn_cast<llvm::ConstantInt>(value))
+ return ci->isZero();
+ return false;
+}
+
+static bool equalAuthPolicies(const CGPointerAuthInfo &left,
+ const CGPointerAuthInfo &right) {
+ if (left.isSigned() != right.isSigned())
+ return false;
+ assert(left.isSigned() && right.isSigned() &&
+ "should only be called with non-null auth policies");
+ return left.getKey() == right.getKey() &&
+ left.getAuthenticationMode() == right.getAuthenticationMode();
+}
+
+llvm::Value *CodeGenFunction::EmitPointerAuthResign(
+ llvm::Value *value, QualType type, const CGPointerAuthInfo &curAuthInfo,
+ const CGPointerAuthInfo &newAuthInfo, bool isKnownNonNull) {
+ // Fast path: if neither schema wants a signature, we're done.
+ if (!curAuthInfo && !newAuthInfo)
+ return value;
+
+ llvm::Value *null = nullptr;
+ // If the value is obviously null, we're done.
+ if (auto pointerValue = dyn_cast<llvm::PointerType>(value->getType())) {
+ null = CGM.getNullPointer(pointerValue, type);
+ } else {
+ assert(value->getType()->isIntegerTy());
+ null = llvm::ConstantInt::get(IntPtrTy, 0);
+ }
+ if (value == null) {
+ return value;
+ }
+
+ // If both schemas sign the same way, we're done.
+ if (equalAuthPolicies(curAuthInfo, newAuthInfo)) {
----------------
kovdan01 wrote:
It looks like this is the only place where `equalAuthPolicies`, and checks against discriminator can probably be moved to that function from the code below, so the resulting if statement would be smth like
```
if (equalAuthPolicies(curAuthInfo, newAuthInfo))
return value;
```
Feel free to ignore
https://github.com/llvm/llvm-project/pull/98847
More information about the cfe-commits
mailing list