Consumed analysis: switch from tests_consumed/unconsumed to a general
tests_typestate attribute.  Patch by chris.wailes@gmail.com.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192513 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaCXX/warn-consumed-analysis-strict.cpp b/test/SemaCXX/warn-consumed-analysis-strict.cpp
deleted file mode 100644
index 8ef3e88..0000000
--- a/test/SemaCXX/warn-consumed-analysis-strict.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed-strict -std=c++11 %s
-
-#define CALLABLE_WHEN(...)      __attribute__ ((callable_when(__VA_ARGS__)))
-#define CONSUMABLE(state)       __attribute__ ((consumable(state)))
-#define CONSUMES                __attribute__ ((consumes))
-#define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
-#define TESTS_UNCONSUMED        __attribute__ ((tests_unconsumed))
-
-#define TEST_VAR(Var) Var.isValid()
-
-typedef decltype(nullptr) nullptr_t;
-
-template <typename T>
-class CONSUMABLE(unconsumed) ConsumableClass {
-  T var;
-  
-  public:
-  ConsumableClass();
-  ConsumableClass(nullptr_t p) RETURN_TYPESTATE(consumed);
-  ConsumableClass(T val);
-  ConsumableClass(ConsumableClass<T> &other);
-  ConsumableClass(ConsumableClass<T> &&other);
-  
-  ConsumableClass<T>& operator=(ConsumableClass<T>  &other);
-  ConsumableClass<T>& operator=(ConsumableClass<T> &&other);
-  ConsumableClass<T>& operator=(nullptr_t) CONSUMES;
-  
-  template <typename U>
-  ConsumableClass<T>& operator=(ConsumableClass<U>  &other);
-  
-  template <typename U>
-  ConsumableClass<T>& operator=(ConsumableClass<U> &&other);
-  
-  void operator()(int a) CONSUMES;
-  void operator*() const CALLABLE_WHEN("unconsumed");
-  void unconsumedCall() const CALLABLE_WHEN("unconsumed");
-  
-  bool isValid() const TESTS_UNCONSUMED;
-  operator bool() const TESTS_UNCONSUMED;
-  bool operator!=(nullptr_t) const TESTS_UNCONSUMED;
-  
-  void constCall() const;
-  void nonconstCall();
-  
-  void consume() CONSUMES;
-};
-
-void testIfStmt() {
-  ConsumableClass<int> var;
-  
-  if (var.isValid()) { // expected-warning {{unnecessary test. Variable 'var' is known to be in the 'consumed' state}}
-    
-    // Empty
-    
-  } else {
-    // Empty
-  }
-}
-
-void testNoWarnTestFromMacroExpansion() {
-  ConsumableClass<int> var(42);
-  
-  if (TEST_VAR(var)) {
-    *var;
-  }
-}
diff --git a/test/SemaCXX/warn-consumed-analysis.cpp b/test/SemaCXX/warn-consumed-analysis.cpp
index 28b7794..b11a74f 100644
--- a/test/SemaCXX/warn-consumed-analysis.cpp
+++ b/test/SemaCXX/warn-consumed-analysis.cpp
@@ -6,7 +6,7 @@
 #define CONSUMABLE(state)       __attribute__ ((consumable(state)))
 #define CONSUMES                __attribute__ ((consumes))
 #define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
-#define TESTS_UNCONSUMED        __attribute__ ((tests_unconsumed))
+#define TESTS_TYPESTATE(state)  __attribute__ ((tests_typestate(state)))
 
 typedef decltype(nullptr) nullptr_t;
 
@@ -36,9 +36,10 @@
   void unconsumedCall() const CALLABLE_WHEN("unconsumed");
   void callableWhenUnknown() const CALLABLE_WHEN("unconsumed", "unknown");
   
-  bool isValid() const TESTS_UNCONSUMED;
-  operator bool() const TESTS_UNCONSUMED;
-  bool operator!=(nullptr_t) const TESTS_UNCONSUMED;
+  bool isValid() const TESTS_TYPESTATE(unconsumed);
+  operator bool() const TESTS_TYPESTATE(unconsumed);
+  bool operator!=(nullptr_t) const TESTS_TYPESTATE(unconsumed);
+  bool operator==(nullptr_t) const TESTS_TYPESTATE(consumed);
   
   void constCall() const;
   void nonconstCall();
@@ -146,6 +147,12 @@
   } else {
     *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
   }
+  
+  if (var == nullptr) {
+    *var; // expected-warning {{invalid invocation of method 'operator*' on object 'var' while it is in the 'consumed' state}}
+  } else {
+    // Empty
+  }
 }
 
 void testComplexConditionals0() {
diff --git a/test/SemaCXX/warn-consumed-parsing.cpp b/test/SemaCXX/warn-consumed-parsing.cpp
index 153c3b7..0cc8579 100644
--- a/test/SemaCXX/warn-consumed-parsing.cpp
+++ b/test/SemaCXX/warn-consumed-parsing.cpp
@@ -4,7 +4,7 @@
 #define CONSUMABLE(state)        __attribute__ ((consumable(state)))
 #define CONSUMES                 __attribute__ ((consumes))
 #define RETURN_TYPESTATE(state)  __attribute__ ((return_typestate(state)))
-#define TESTS_UNCONSUMED         __attribute__ ((tests_unconsumed))
+#define TESTS_TYPESTATE(state)   __attribute__ ((tests_typestate(state)))
 
 // FIXME: This test is here because the warning is issued by the Consumed
 //        analysis, not SemaDeclAttr.  The analysis won't run after an error
@@ -18,18 +18,18 @@
 
 class AttrTester0 {
   void consumes()        __attribute__ ((consumes(42))); // expected-error {{attribute takes no arguments}}
-  bool testsUnconsumed() __attribute__ ((tests_unconsumed(42))); // expected-error {{attribute takes no arguments}}
+  bool testsUnconsumed() __attribute__ ((tests_typestate())); // expected-error {{attribute takes one argument}}
   void callableWhen()    __attribute__ ((callable_when())); // expected-error {{attribute takes at least 1 argument}}
 };
 
 int var0 CONSUMES; // expected-warning {{'consumes' attribute only applies to methods}}
-int var1 TESTS_UNCONSUMED; // expected-warning {{'tests_unconsumed' attribute only applies to methods}}
+int var1 TESTS_TYPESTATE(consumed); // expected-warning {{'tests_typestate' attribute only applies to methods}}
 int var2 CALLABLE_WHEN(42); // expected-warning {{'callable_when' attribute only applies to methods}}
 int var3 CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
 int var4 RETURN_TYPESTATE(consumed); // expected-warning {{'return_typestate' attribute only applies to functions}}
 
 void function0() CONSUMES; // expected-warning {{'consumes' attribute only applies to methods}}
-void function1() TESTS_UNCONSUMED; // expected-warning {{'tests_unconsumed' attribute only applies to methods}}
+void function1() TESTS_TYPESTATE(consumed); // expected-warning {{'tests_typestate' attribute only applies to methods}}
 void function2() CALLABLE_WHEN(42); // expected-warning {{'callable_when' attribute only applies to methods}}
 void function3() CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
 
@@ -38,7 +38,7 @@
   void callableWhen1()   CALLABLE_WHEN(42); // expected-error {{'callable_when' attribute requires a string}}
   void callableWhen2()   CALLABLE_WHEN("foo"); // expected-warning {{'callable_when' attribute argument not supported: foo}}
   void consumes()        CONSUMES;
-  bool testsUnconsumed() TESTS_UNCONSUMED;
+  bool testsUnconsumed() TESTS_TYPESTATE(consumed);
 };
 
 AttrTester1 returnTypestateTester0() RETURN_TYPESTATE(not_a_state); // expected-warning {{'return_typestate' attribute argument not supported: 'not_a_state'}}
@@ -47,7 +47,7 @@
 class AttrTester2 {
   void callableWhen()    CALLABLE_WHEN("unconsumed"); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
   void consumes()        CONSUMES; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
-  bool testsUnconsumed() TESTS_UNCONSUMED; // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
+  bool testsUnconsumed() TESTS_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}}
 };
 
 class CONSUMABLE(42) AttrTester3; // expected-error {{'consumable' attribute requires an identifier}}