================
@@ -629,25 +629,46 @@ class ASTContext : public RefCountedBase<ASTContext> {
   void setRelocationInfoForCXXRecord(const CXXRecordDecl *,
                                      CXXRecordDeclRelocationInfo);
 
-  /// Examines a given type, and returns whether the T itself
+  /// Examines a given type, and returns whether the type itself
   /// is address discriminated, or any transitively embedded types
   /// contain data that is address discriminated. This includes
   /// implicitly authenticated values like vtable pointers, as well as
   /// explicitly qualified fields.
-  bool containsAddressDiscriminatedPointerAuth(QualType T);
-  // A simple helper function to short circuit pointer auth checks.
+  bool containsAddressDiscriminatedPointerAuth(QualType T) {
+    if (!isPointerAuthenticationAvailable())
+      return false;
+    return findPointerAuthContent(T) != PointerAuthContent::None;
+  }
 
-  bool isPointerAuthenticationAvailable() const {
-    return LangOpts.PointerAuthCalls || LangOpts.PointerAuthIntrinsics ||
-           LangOpts.PointerAuthVTPtrAddressDiscrimination;
+  /// Examines a given type, and returns whether the type itself
+  /// or any data it transitively contains has a pointer authentication
+  /// schema that is not safely relocatable. e.g. any data or fields
+  /// with address discrimination other than any otherwise similar
+  /// vtable pointers.
+  bool containsNonRelocatablePointerAuth(QualType T) {
+    if (!isPointerAuthenticationAvailable())
+      return false;
+    return findPointerAuthContent(T) == 
PointerAuthContent::AddressDiscriminatedData;
   }
 
 private:
   llvm::DenseMap<const CXXRecordDecl *, CXXRecordDeclRelocationInfo>
       RelocatableClasses;
 
   // FIXME: store in RecordDeclBitfields in future?
-  llvm::DenseMap<const RecordDecl *, bool>
+  enum class PointerAuthContent : uint8_t {
+    None,
+    AddressDiscriminatedVTable,
+    AddressDiscriminatedData
+  };
+
+  // A simple helper function to short circuit pointer auth checks.
+  bool isPointerAuthenticationAvailable() const {
+    return LangOpts.PointerAuthCalls || LangOpts.PointerAuthIntrinsics ||
+           LangOpts.PointerAuthVTPtrAddressDiscrimination;
+  }
----------------
ojhunt wrote:

The first is historical sadness, we can probably make this better when I move 
the pointer auth options and similar into the target info rather than the 
obtuse combination of codegen and langopts we currently have. When we do that 
we can probably just have a single "the target supports pointer auth" flag 
which is what this is trying to approximate.

The reason that `PointerAuthVTPtrAddressDiscrimination` is not sufficient is 
that there is a qualifier that can be specified explicitly.

That said as we discussed (for people following at home @cor3ntin and I are 
talking at wg21) if someone had `PointerAuthVTPtrAddressDiscrimination` enabled 
without `PointerAuthCalls` and `PointerAuthIntrinsics` would likely be in a 
world of hurt, so I'll remove that separate check.

https://github.com/llvm/llvm-project/pull/143969
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to