forked from OSchip/llvm-project
[analyzer] Handle inlined constructors for rvalue temporaries correctly.
Previously the analyzer treated all inlined constructors like lvalues, setting the value of the CXXConstructExpr to the newly-constructed region. However, some CXXConstructExprs behave like rvalues -- in particular, the implicit copy constructor into a pass-by-value argument. In this case, we want only the /contents/ of a temporary object to be passed, so that we can use the same "copy each argument into the parameter region" algorithm that we use for scalar arguments. This may change when we start modeling destructors of temporaries, but for now this is the last part of <rdar://problem/12137950>. llvm-svn: 164830
This commit is contained in:
parent
b559f18584
commit
19ed6748ea
|
@ -160,7 +160,14 @@ void ExprEngine::processCallExit(ExplodedNode *CEBNode) {
|
|||
svalBuilder.getCXXThis(CCE->getConstructor()->getParent(), calleeCtx);
|
||||
SVal ThisV = state->getSVal(This);
|
||||
|
||||
// Always bind the region to the CXXConstructExpr.
|
||||
// If the constructed object is a prvalue, get its bindings.
|
||||
// Note that we have to be careful here because constructors embedded
|
||||
// in DeclStmts are not marked as lvalues.
|
||||
if (!CCE->isGLValue())
|
||||
if (const MemRegion *MR = ThisV.getAsRegion())
|
||||
if (isa<CXXTempObjectRegion>(MR))
|
||||
ThisV = state->getSVal(cast<Loc>(ThisV));
|
||||
|
||||
state = state->BindExpr(CCE, callerCtx, ThisV);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,12 +61,6 @@ int getAssignedField(struct S s) {
|
|||
|
||||
void testArgument() {
|
||||
clang_analyzer_eval(getConstrainedField(getS()) == 42); // expected-warning{{TRUE}}
|
||||
#if __cplusplus
|
||||
// FIXME: Passing the struct by value seems to be confusing C++.
|
||||
// Possibly related to <rdar://problem/12137950>.
|
||||
// expected-warning@-4{{UNKNOWN}}
|
||||
#endif
|
||||
|
||||
clang_analyzer_eval(getAssignedField(getS()) == 42); // expected-warning{{TRUE}}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,3 +103,17 @@ namespace TemporaryConstructor {
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace ConstructorUsedAsRValue {
|
||||
using TemporaryConstructor::BoolWrapper;
|
||||
|
||||
bool extractValue(BoolWrapper b) {
|
||||
return b.value;
|
||||
}
|
||||
|
||||
void test() {
|
||||
bool result = extractValue(BoolWrapper());
|
||||
clang_analyzer_eval(result); // expected-warning{{TRUE}}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue