[PATCH] [patch] Adding Consumed Analysis to Clang
Christian Wailes
chriswailes at google.com
Mon Jul 29 18:55:56 PDT 2013
Changed the code to correctly test for UO_LNot instead of UO_Not, and removed a leftover print statement. Added a test cast for the negation of a test.
Hi dblaikie,
http://llvm-reviews.chandlerc.com/D1233
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1233?vs=3059&id=3062#toc
Files:
lib/Analysis/Consumed.cpp
test/SemaCXX/warn-consumed-analysis.cpp
Index: lib/Analysis/Consumed.cpp
===================================================================
--- lib/Analysis/Consumed.cpp
+++ lib/Analysis/Consumed.cpp
@@ -328,7 +328,7 @@
}
bool TestedVarsVisitor::VisitUnaryOperator(UnaryOperator *UnaryOp) {
- if (UnaryOp->getOpcode() == UO_Not) {
+ if (UnaryOp->getOpcode() == UO_LNot) {
Invert = true;
TraverseStmt(UnaryOp->getSubExpr());
@@ -417,8 +417,6 @@
Map.insert(PairType(OtherPair.first, Unknown));
}
}
-
- llvm::errs() << "\n";
}
void ConsumedStateMap::setState(const VarDecl *Var, ConsumedState State) {
Index: test/SemaCXX/warn-consumed-analysis.cpp
===================================================================
--- test/SemaCXX/warn-consumed-analysis.cpp
+++ test/SemaCXX/warn-consumed-analysis.cpp
@@ -20,7 +20,7 @@
bool isValid(void) TESTS_UNCONSUMED;
};
-void testInitializationAndIfStmt(void) {
+void testInitialization(void) {
Bar var0;
Bar var1 = Bar();
@@ -39,6 +39,25 @@
}
}
+void testIfStmt(void) {
+ Bar var;
+
+ if (var.isValid()) { // \
+ \\ expected-warning {{Unnecessary test. Variable 'var' is known to be in the 'consumed' state}}
+ *var;
+
+ } else {
+ *var; // expected-warning {{Invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
+ }
+
+ if (!var.isValid()) {
+ *var; // expected-warning {{Invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
+
+ } else {
+ *var;
+ }
+}
+
void testSimpleRValueRefs(void) {
Bar var0;
Bar var1 = Bar(42);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1233.2.patch
Type: text/x-patch
Size: 1597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130729/ab21172a/attachment.bin>
More information about the cfe-commits
mailing list