forked from OSchip/llvm-project
Consumed analysis: non-const methods no longer transfer an object into an
unknown state. Patch by chris.wailes@gmail.com. llvm-svn: 189612
This commit is contained in:
parent
c4dff6feea
commit
7fa60edb47
|
@ -530,8 +530,6 @@ void ConsumedStmtVisitor::VisitCXXMemberCallExpr(
|
|||
handleTestingFunctionCall(Call, PInfo.getVar());
|
||||
else if (MethodDecl->hasAttr<ConsumesAttr>())
|
||||
StateMap->setState(PInfo.getVar(), consumed::CS_Consumed);
|
||||
else if (!MethodDecl->isConst())
|
||||
StateMap->setState(PInfo.getVar(), consumed::CS_Unknown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -626,18 +624,10 @@ void ConsumedStmtVisitor::VisitCXXOperatorCallExpr(
|
|||
checkCallability(PInfo, FunDecl, Call);
|
||||
|
||||
if (PInfo.isVar()) {
|
||||
if (isTestingFunction(FunDecl)) {
|
||||
if (isTestingFunction(FunDecl))
|
||||
handleTestingFunctionCall(Call, PInfo.getVar());
|
||||
|
||||
} else if (FunDecl->hasAttr<ConsumesAttr>()) {
|
||||
else if (FunDecl->hasAttr<ConsumesAttr>())
|
||||
StateMap->setState(PInfo.getVar(), consumed::CS_Consumed);
|
||||
|
||||
} else if (const CXXMethodDecl *MethodDecl =
|
||||
dyn_cast_or_null<CXXMethodDecl>(FunDecl)) {
|
||||
|
||||
if (!MethodDecl->isConst())
|
||||
StateMap->setState(PInfo.getVar(), consumed::CS_Unknown);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class ConsumableClass {
|
|||
|
||||
ConsumableClass<T>& operator=(ConsumableClass<T> &other);
|
||||
ConsumableClass<T>& operator=(ConsumableClass<T> &&other);
|
||||
ConsumableClass<T>& operator=(nullptr_t);
|
||||
ConsumableClass<T>& operator=(nullptr_t) CONSUMES;
|
||||
|
||||
template <typename U>
|
||||
ConsumableClass<T>& operator=(ConsumableClass<U> &other);
|
||||
|
@ -174,13 +174,6 @@ void testCallingConventions() {
|
|||
*var; // expected-warning {{invocation of method 'operator*' on object 'var' while it is in an unknown state}}
|
||||
}
|
||||
|
||||
void testMoveAsignmentish() {
|
||||
ConsumableClass<int> var;
|
||||
|
||||
var = nullptr;
|
||||
*var; // expected-warning {{invocation of method 'operator*' on object 'var' while it is in an unknown state}}
|
||||
}
|
||||
|
||||
void testConstAndNonConstMemberFunctions() {
|
||||
ConsumableClass<int> var(42);
|
||||
|
||||
|
@ -188,7 +181,7 @@ void testConstAndNonConstMemberFunctions() {
|
|||
*var;
|
||||
|
||||
var.nonconstCall();
|
||||
*var; // expected-warning {{invocation of method 'operator*' on object 'var' while it is in an unknown state}}
|
||||
*var;
|
||||
}
|
||||
|
||||
void testNoWarnTestFromMacroExpansion() {
|
||||
|
|
|
@ -19,7 +19,7 @@ class ConsumableClass {
|
|||
|
||||
ConsumableClass<T>& operator=(ConsumableClass<T> &other);
|
||||
ConsumableClass<T>& operator=(ConsumableClass<T> &&other);
|
||||
ConsumableClass<T>& operator=(nullptr_t);
|
||||
ConsumableClass<T>& operator=(nullptr_t) CONSUMES;
|
||||
|
||||
template <typename U>
|
||||
ConsumableClass<T>& operator=(ConsumableClass<U> &other);
|
||||
|
@ -251,6 +251,10 @@ void testMoveAsignmentish() {
|
|||
|
||||
*var0;
|
||||
*var1; // expected-warning {{invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
|
||||
|
||||
var1 = ConsumableClass<long>(42);
|
||||
var1 = nullptr;
|
||||
*var1; // expected-warning {{invocation of method 'operator*' on object 'var1' while it is in the 'consumed' state}}
|
||||
}
|
||||
|
||||
void testConditionalMerge() {
|
||||
|
|
Loading…
Reference in New Issue