[clang] [clang][dataflow] Propagate locations from result objects to initializers. (PR #87320)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 8 05:58:40 PDT 2024
================
@@ -460,25 +460,35 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
// So make sure we have a value if we didn't propagate one above.
if (S->isPRValue() && S->getType()->isRecordType()) {
if (Env.getValue(*S) == nullptr) {
- Value *Val = Env.createValue(S->getType());
- // We're guaranteed to always be able to create a value for record
- // types.
- assert(Val != nullptr);
- Env.setValue(*S, *Val);
+ auto &Loc = Env.getResultObjectLocation(*S);
+ Env.initializeFieldsWithValues(Loc);
+ refreshRecordValue(Loc, Env);
}
}
}
void VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *S) {
const Expr *InitExpr = S->getExpr();
assert(InitExpr != nullptr);
- propagateValueOrStorageLocation(*InitExpr, *S, Env);
+ if (!(S->getType()->isRecordType() && S->isPRValue()))
+ propagateValueOrStorageLocation(*InitExpr, *S, Env);
}
void VisitCXXConstructExpr(const CXXConstructExpr *S) {
const CXXConstructorDecl *ConstructorDecl = S->getConstructor();
assert(ConstructorDecl != nullptr);
+ // `CXXConstructExpr` can have array type if default-initializing an array
+ // of records. We don't handle this specifically beyond potentially inlining
+ // the call.
+ if (!S->getType()->isRecordType()) {
+ transferInlineCall(S, ConstructorDecl);
+ return;
+ }
+
+ RecordStorageLocation &Loc = Env.getResultObjectLocation(*S);
----------------
martinboehme wrote:
A `CXXConstructExpr` is always a prvalue, and any prvalue of record type has a result object location. This is simply the precondition of `getResultObjectLocation()`, so I'm not sure adding an extra comment here would have value?
https://github.com/llvm/llvm-project/pull/87320
More information about the cfe-commits
mailing list