@@ -3404,6 +3404,62 @@ uint16_t ASTContext::getPointerAuthVTablePointerDiscriminator(
34043404 return getPointerAuthStringDiscriminator(*this, Str.c_str());
34053405}
34063406
3407+ std::pair<bool, int>
3408+ ASTContext::getPointerAuthStructKey(const RecordDecl *RD) const {
3409+ if (auto *Attr = RD->getAttr<PointerAuthStructAttr>()) {
3410+ Expr *E = Attr->getKey();
3411+ if (E->isValueDependent())
3412+ return {false, 0};
3413+ std::optional<llvm::APSInt> V = E->getIntegerConstantExpr(*this);
3414+ return {true, V->getExtValue()};
3415+ }
3416+
3417+ return {true, PointerAuthKeyNone};
3418+ }
3419+
3420+ std::pair<bool, unsigned>
3421+ ASTContext::getPointerAuthStructDisc(const RecordDecl *RD) const {
3422+ if (auto *Attr = RD->getAttr<PointerAuthStructAttr>()) {
3423+ Expr *E = Attr->getDiscriminator();
3424+ if (E->isValueDependent())
3425+ return {false, 0};
3426+ std::optional<llvm::APSInt> V = E->getIntegerConstantExpr(*this);
3427+ return {true, V->getExtValue()};
3428+ }
3429+
3430+ return {true, 0};
3431+ }
3432+
3433+ bool ASTContext::hasPointerAuthStructMismatch(const RecordDecl *RD0,
3434+ const RecordDecl *RD1) const {
3435+ if (RD0 == RD1)
3436+ return true;
3437+
3438+ int Key0, Key1;
3439+ unsigned Disc0, Disc1;
3440+ bool Known0, Known1;
3441+ std::tie(Known0, Key0) = getPointerAuthStructKey(RD0);
3442+ std::tie(Known1, Key1) = getPointerAuthStructKey(RD1);
3443+
3444+ if (!Known0 || !Known1)
3445+ return false;
3446+
3447+ if (Key0 != Key1)
3448+ return true;
3449+
3450+ // If the key is none, skip checking the discriminators.
3451+ if (Key0 == PointerAuthKeyNone)
3452+ return false;
3453+
3454+ std::tie(Known0, Disc0) = getPointerAuthStructDisc(RD0);
3455+ std::tie(Known1, Disc1) = getPointerAuthStructDisc(RD1);
3456+
3457+ if (!Known0 || !Known1)
3458+ return false;
3459+
3460+ return Disc0 != Disc1;
3461+ }
3462+
34073463bool ASTContext::typeContainsAuthenticatedNull(const Type *type) const {
34083464 return typeContainsAuthenticatedNull(QualType(type, 0));
34093465}
0 commit comments