r189612 - Consumed analysis: non-const methods no longer transfer an object into an
DeLesley Hutchins
delesley at google.com
Thu Aug 29 14:17:25 PDT 2013
Author: delesley
Date: Thu Aug 29 16:17:25 2013
New Revision: 189612
URL: http://llvm.org/viewvc/llvm-project?rev=189612&view=rev
Log:
Consumed analysis: non-const methods no longer transfer an object into an
unknown state. Patch by chris.wailes at gmail.com.
Modified:
cfe/trunk/lib/Analysis/Consumed.cpp
cfe/trunk/test/SemaCXX/warn-consumed-analysis-strict.cpp
cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp
Modified: cfe/trunk/lib/Analysis/Consumed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/Consumed.cpp?rev=189612&r1=189611&r2=189612&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/Consumed.cpp (original)
+++ cfe/trunk/lib/Analysis/Consumed.cpp Thu Aug 29 16:17:25 2013
@@ -530,8 +530,6 @@ void ConsumedStmtVisitor::VisitCXXMember
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::VisitCXXOperat
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);
- }
}
}
}
Modified: cfe/trunk/test/SemaCXX/warn-consumed-analysis-strict.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-consumed-analysis-strict.cpp?rev=189612&r1=189611&r2=189612&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-consumed-analysis-strict.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-consumed-analysis-strict.cpp Thu Aug 29 16:17:25 2013
@@ -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() {
Modified: cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp?rev=189612&r1=189611&r2=189612&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-consumed-analysis.cpp Thu Aug 29 16:17:25 2013
@@ -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() {
More information about the cfe-commits
mailing list