================
@@ -92,6 +94,97 @@ class RetainPtrSafetyModel : public PtrRefSafetyModel {
RetainTypeChecker *retainTypeChecker() const override { return &RTC; }
};
+QualType objectType(QualType T) {
+ while (!T.isNull()) {
+ QualType Pointee = T->getPointeeType();
+ if (Pointee.isNull())
+ break;
+ T = Pointee;
+ }
+ return T;
+}
+
+QualType borrowedType(QualType T) {
+ const auto *Specialization =
+ dyn_cast_or_null<ClassTemplateSpecializationDecl>(
+ T->getAsCXXRecordDecl());
+ if (!Specialization)
+ return QualType();
+ const auto &Args = Specialization->getTemplateArgs();
+ if (!Args.size() || Args[0].getKind() != TemplateArgument::Type)
+ return QualType();
+ return Args[0].getAsType();
+}
+
+class BorrowSafetyModel : public PtrRefSafetyModel {
+public:
+ std::optional<bool> isUnsafeType(QualType QT) const override {
+ return isView(QT);
+ }
+ std::optional<bool> isUnsafePtr(QualType QT, bool) const override {
+ return isView(QT);
+ }
+ bool isSafePtr(const CXXRecordDecl *Record) const override {
+ return isBorrow(Record);
+ }
+ bool isSafePtrType(QualType T) const override { return isBorrowType(T); }
+ bool isPtrType(const std::string &Name) const override {
+ return isBorrow(Name);
+ }
+
+ bool isSafeExpr(const Expr *Origin,
+ bool CrossedLifetimeBound) const override {
----------------
rniwa wrote:
I'm not sure `CrossedLifetimeBound` clearly communicates the semantics.
Maybe `DependsOnLifetimeBoundVar`?
https://github.com/llvm/llvm-project/pull/225274
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits