================
@@ -236,7 +236,8 @@ SVal ExprEngine::computeObjectUnderConstruction(
         QualType ReturnTy = RetE->getType();
         QualType RegionTy = ACtx.getPointerType(ReturnTy);
         return SVB.conjureSymbolVal(&TopLevelSymRegionTag, getCFGElementRef(),
-                                    SF, RegionTy, getNumVisitedCurrent());
+                                    getCurrStackFrame(), RegionTy,
+                                    getNumVisitedCurrent());
----------------
steakhal wrote:

I think I need a bit more context. I read the PR summary like 2 times, and the 
tests too.
I feel like there is something missing here.

So `SF` was passed into this function. And I suppose, `SF` was essentially the 
top-most frame of the StackFrames - thus the analysis entry point.
That was done because ideally, it would be the imaginary stack frame of the 
caller of the entry point - but since we don't have that, the next best thing 
is the entry point itself - argued the old code.

Now, we are swapping this for the current stack frame - which is super 
arbitrary, and makes me worried.
Consider this scenario:
https://godbolt.org/z/jKP7z3Gd4
```c++
Obj inner() {
    Obj o;
    return o;
}

// Two possible sources: a prvalue from inner() (guaranteed elision in C++17),
// or a named local (NRVO).
Obj middle(bool deep) {
    if (deep) return inner();
    Obj o;
    return o;
}

// The slot of 'r' is also entrypoint's return slot (NRVO). Because the
// conditional operator yields a prvalue, 'r' is initialized directly by
// whichever callee runs, so the slot is handed to inner() or middle().
Obj entrypoint(bool useMiddle) {
    Obj r = useMiddle ? middle(true) : inner();
    return r;
}

int main() {
    for (int i = 0; i < 2; ++i) {
        Obj x = entrypoint(i);
    }
}
```

Here `x` is reused across loop iterations, thus its address is fixed. Sometimes 
its' NRVO initialized from `inner` sometimes from `middle`, and I think we 
should differentiate them - don't we?

So I think ultimately, the current implementation is right and changing it 
would be a mistake.

https://github.com/llvm/llvm-project/pull/244444
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to