[clang] [LifetimeSafety] Model pointer-to-data-member access in the fact generator (PR #204612)
Utkarsh Saxena via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 23 05:37:34 PDT 2026
================
@@ -497,6 +497,27 @@ void FactsGenerator::handlePointerArithmetic(const BinaryOperator *BO) {
}
void FactsGenerator::VisitBinaryOperator(const BinaryOperator *BO) {
+ if (BO->getOpcode() == BO_PtrMemD || BO->getOpcode() == BO_PtrMemI) {
+ // `obj.*pm` / `objptr->*pm` names a member of the object, so a borrow of it
+ // borrows the object; flow the object's origin into the result. For `.*`
+ // the object is the LHS; for `->*` it is the LHS pointer's pointee.
+ //
+ // Only the result's outer (storage) origin relates to the object: borrowing
+ // the member borrows the object's storage. Deeper levels of the result (a
+ // pointer/view member's own pointee) are the member's value, with no
+ // counterpart in the object's origin -- so the lists may differ in length
+ // and we flow just the top level, leaving the member's value untouched.
+ OriginList *Dst = getOriginsList(*BO);
+ OriginList *ObjSrc =
+ BO->getOpcode() == BO_PtrMemD
+ ? getOriginsList(*BO->getLHS())
+ : getRValueOrigins(BO->getLHS(), getOriginsList(*BO->getLHS()));
+ if (Dst && ObjSrc)
+ CurrentBlockFacts.push_back(FactMgr.createFact<OriginFlowFact>(
+ Dst->getOuterOriginID(), ObjSrc->getOuterOriginID(), /*Kill=*/true));
+ handleUse(BO->getLHS());
----------------
usx95 wrote:
Why do we need the `use` here ?
Is it something that can be fixed by https://github.com/llvm/llvm-project/pull/205323
https://github.com/llvm/llvm-project/pull/204612
More information about the cfe-commits
mailing list