================
@@ -3145,27 +3144,71 @@ static bool isSmartOwningPtrType(QualType QT) {
if (!ND)
return false;
- // Accept both std and custom smart pointer implementations for broader
- // coverage
- return isSmartOwningPtrName(ND->getName());
+ // For broader coverage we recognize all template classes with names that
+ // match the allowlist even if they are not declared in namespace 'std'.
+ return isSmartPtrName(ND->getName());
}
return false;
}
+/// Helper struct for collecting smart owning pointer field regions.
+/// This allows both hasSmartPtrField and
+/// collectSmartPtrFieldRegions to share the same traversal logic,
+/// ensuring consistency.
+struct FieldConsumer {
+ const MemRegion *Reg;
+ CheckerContext *C;
+ llvm::SmallPtrSetImpl<const MemRegion *> *Out;
+
+ FieldConsumer(const MemRegion *Reg, CheckerContext &C,
+ llvm::SmallPtrSetImpl<const MemRegion *> &Out)
+ : Reg(Reg), C(&C), Out(&Out) {}
+
+ void consume(const FieldDecl *FD) {
+ SVal L = C->getState()->getLValue(FD, loc::MemRegionVal(Reg));
+ if (const MemRegion *FR = L.getAsRegion())
+ Out->insert(FR);
+ }
+
+ std::optional<FieldConsumer> switchToBase(const CXXRecordDecl *BaseDecl,
+ bool IsVirtual) {
+ // Get the base class region
+ SVal BaseL =
+ C->getState()->getLValue(BaseDecl, Reg->getAs<SubRegion>(), IsVirtual);
+ if (const MemRegion *BaseObjRegion = BaseL.getAsRegion()) {
+ // Return a consumer for the base class
+ return FieldConsumer{BaseObjRegion, *C, *Out};
+ }
+ return std::nullopt;
+ }
+};
+
/// Check if a record type has smart owning pointer fields (directly or in base
-/// classes).
-static bool hasSmartOwningPtrField(const CXXRecordDecl *CRD) {
+/// classes). When FC is provided, also collect the field regions.
----------------
NagyDonat wrote:
Thanks!
https://github.com/llvm/llvm-project/pull/152751
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits