Analyzer crashes on temporaries life-extended via members
| Bugzilla Link | 19539 |
| Resolution | FIXED |
| Resolved on | Nov 30, 2016 13:09 |
| Version | unspecified |
| OS | Linux |
| Reporter | LLVM Bugzilla Contributor |
| CC | @belkadan,@haoNoQ |
Extended Description
struct S { ~S(){} }; struct A { int i; S s; }; void f() { const int& i = A().i; }
When analyzing the code above, static analyzer crashes with the assertion in lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:317: "RecordDecl && "Only CXXRecordDecls should have destructors"".
The reason is that ExprEngine::ProcessAutomaticObjDtor tries to get destructor of the type of the variable. Instead, it should determine all life-extended temporaries from the variable initializer expression (probably, by getting all CXXBindTemporaryExpr nodes in the initializer expression?).
Should be fixed in r288263.
This is still causing a crash on ToT.
It's not as simple as getting all CXXBindTemporaryExpr's.
From the C++ standard, 12.2-5: """The second context is when a reference is bound to a temporary. The temporary to which the reference is bound or the temporary that is the complete object of a subobject to which the reference is bound persists for the lifetime of the reference except: [...]"""
So we'll need to find the exact temporary that is the complete object of a subobject to which the reference is bound. E.g. I believe that in the example:
struct A { A(); A(int); int i; }; void f() { const int& i = A(A().i).i; }
only the outermost temporary object is lifetime extended.
Also note that there might not be CXXBindTemporaryExpr (those are only in the AST when there is a non-trivial destructor involved iiuc). But I think the MaterializeTemporaryExpr together with the concept of the complete object of a subobject (which I'd assume is modeled somewhere in the static analyzer already) should be enough.
Ah, I forgot that's how lifetime extension works. Yes, we should fix this.
assigned to @devincoughlin