llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Analyzer crashes on temporaries life-extended via members

Open llvmbot opened this issue 12 years ago • 5 comments

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?).

llvmbot avatar Apr 24 '14 05:04 llvmbot

Should be fixed in r288263.

haoNoQ avatar Nov 30 '16 21:11 haoNoQ

This is still causing a crash on ToT.

devincoughlin avatar Nov 06 '16 20:11 devincoughlin

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.

llvmbot avatar Jul 28 '14 14:07 llvmbot

Ah, I forgot that's how lifetime extension works. Yes, we should fix this.

belkadan avatar May 01 '14 05:05 belkadan

assigned to @devincoughlin

llvmbot avatar Apr 24 '14 05:04 llvmbot