[llvm] [PAC][IR][AArch64] Add "ptrauth(...)" Constant to represent signed pointers. (PR #85738)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 18:21:48 PDT 2024
================
@@ -1007,6 +1007,73 @@ struct OperandTraits<NoCFIValue> : public FixedNumOperandTraits<NoCFIValue, 1> {
DEFINE_TRANSPARENT_OPERAND_ACCESSORS(NoCFIValue, Value)
+/// A signed pointer
+///
+class ConstantPtrAuth final : public Constant {
+ friend struct ConstantPtrAuthKeyType;
+ friend class Constant;
+
+ ConstantPtrAuth(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc,
+ Constant *AddrDisc);
+
+ void *operator new(size_t s) { return User::operator new(s, 4); }
+
+ void destroyConstantImpl();
+ Value *handleOperandChangeImpl(Value *From, Value *To);
+
+public:
+ /// Return a pointer authenticated with the specified parameters.
+ static ConstantPtrAuth *get(Constant *Ptr, ConstantInt *Key,
+ ConstantInt *Disc, Constant *AddrDisc);
+
+ /// Produce a new ptrauth expression signing the given value using
+ /// the same schema as is stored in one.
+ ConstantPtrAuth *getWithSameSchema(Constant *Pointer) const;
+
+ /// Transparently provide more efficient getOperand methods.
+ DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
+
+ /// The pointer that is authenticated in this authenticated global reference.
+ Constant *getPointer() const { return cast<Constant>(Op<0>().get()); }
+
+ /// The Key ID, an i32 constant.
+ ConstantInt *getKey() const { return cast<ConstantInt>(Op<1>().get()); }
+
+ /// The discriminator.
+ ConstantInt *getDiscriminator() const {
+ return cast<ConstantInt>(Op<2>().get());
+ }
+
+ /// The address discriminator if any, or the null constant.
+ /// If present, this must be a value equivalent to the storage location of
+ /// the only user of the authenticated ptrauth global.
+ Constant *getAddrDiscriminator() const {
+ return cast<Constant>(Op<3>().get());
+ }
+
+ /// Whether there is any non-null address discriminator.
+ bool hasAddressDiversity() const {
+ return !getAddrDiscriminator()->isNullValue();
+ }
+
+ /// Check whether an authentication operation with key \p KeyV and (possibly
----------------
nikic wrote:
```suggestion
/// Check whether an authentication operation with key \p Key and (possibly
```
https://github.com/llvm/llvm-project/pull/85738
More information about the llvm-commits
mailing list