Consumed Analysis: The 'consumable' attribute now takes a identifier specifying the default assumed state for objects of this class
This information is used for return states and pass-by-value parameter
states.
Patch by Chris Wailes.
Review by DeLesley Hutchins and Aaron Ballman.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190116 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/SemaCXX/warn-consumed-analysis-strict.cpp b/test/SemaCXX/warn-consumed-analysis-strict.cpp
index 1bc604d..98d6894 100644
--- a/test/SemaCXX/warn-consumed-analysis-strict.cpp
+++ b/test/SemaCXX/warn-consumed-analysis-strict.cpp
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed-strict -std=c++11 %s
#define CALLABLE_WHEN_UNCONSUMED __attribute__ ((callable_when_unconsumed))
-#define CONSUMABLE __attribute__ ((consumable))
+#define CONSUMABLE(state) __attribute__ ((consumable(state)))
#define CONSUMES __attribute__ ((consumes))
-#define RETURN_TYPESTATE(State) __attribute__ ((return_typestate(State)))
+#define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
#define TESTS_UNCONSUMED __attribute__ ((tests_unconsumed))
#define TEST_VAR(Var) Var.isValid()
@@ -11,15 +11,15 @@
typedef decltype(nullptr) nullptr_t;
template <typename T>
-class CONSUMABLE ConsumableClass {
+class CONSUMABLE(unconsumed) ConsumableClass {
T var;
public:
ConsumableClass();
ConsumableClass(nullptr_t p) RETURN_TYPESTATE(consumed);
- ConsumableClass(T val) RETURN_TYPESTATE(unconsumed);
- ConsumableClass(ConsumableClass<T> &other) RETURN_TYPESTATE(unconsumed);
- ConsumableClass(ConsumableClass<T> &&other) RETURN_TYPESTATE(unconsumed);
+ ConsumableClass(T val);
+ ConsumableClass(ConsumableClass<T> &other);
+ ConsumableClass(ConsumableClass<T> &&other);
ConsumableClass<T>& operator=(ConsumableClass<T> &other);
ConsumableClass<T>& operator=(ConsumableClass<T> &&other);
@@ -187,6 +187,10 @@
*var;
}
+void testFunctionParam0(ConsumableClass<int> ¶m) {
+ *param; // expected-warning {{invocation of method 'operator*' on object 'param' while it is in an unknown state}}
+}
+
void testNoWarnTestFromMacroExpansion() {
ConsumableClass<int> var(42);
@@ -195,10 +199,6 @@
}
}
-void testFunctionParam(ConsumableClass<int> param) {
- *param; // expected-warning {{invocation of method 'operator*' on object 'param' while it is in an unknown state}}
-}
-
void testSimpleForLoop() {
ConsumableClass<int> var;
diff --git a/test/SemaCXX/warn-consumed-analysis.cpp b/test/SemaCXX/warn-consumed-analysis.cpp
index 53a29b1..8d4bff7 100644
--- a/test/SemaCXX/warn-consumed-analysis.cpp
+++ b/test/SemaCXX/warn-consumed-analysis.cpp
@@ -1,23 +1,23 @@
// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s
#define CALLABLE_WHEN_UNCONSUMED __attribute__ ((callable_when_unconsumed))
-#define CONSUMABLE __attribute__ ((consumable))
+#define CONSUMABLE(state) __attribute__ ((consumable(state)))
#define CONSUMES __attribute__ ((consumes))
-#define RETURN_TYPESTATE(State) __attribute__ ((return_typestate(State)))
+#define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
#define TESTS_UNCONSUMED __attribute__ ((tests_unconsumed))
typedef decltype(nullptr) nullptr_t;
template <typename T>
-class CONSUMABLE ConsumableClass {
+class CONSUMABLE(unconsumed) ConsumableClass {
T var;
public:
ConsumableClass();
ConsumableClass(nullptr_t p) RETURN_TYPESTATE(consumed);
ConsumableClass(T val) RETURN_TYPESTATE(unconsumed);
- ConsumableClass(ConsumableClass<T> &other) RETURN_TYPESTATE(unconsumed);
- ConsumableClass(ConsumableClass<T> &&other) RETURN_TYPESTATE(unconsumed);
+ ConsumableClass(ConsumableClass<T> &other);
+ ConsumableClass(ConsumableClass<T> &&other);
ConsumableClass<T>& operator=(ConsumableClass<T> &other);
ConsumableClass<T>& operator=(ConsumableClass<T> &&other);
@@ -49,7 +49,6 @@
void baf3(ConsumableClass<int> &&var);
-ConsumableClass<int> returnsUnconsumed() RETURN_TYPESTATE(unconsumed);
ConsumableClass<int> returnsUnconsumed() {
return ConsumableClass<int>(); // expected-warning {{return value not in expected state; expected 'unconsumed', observed 'consumed'}}
}
@@ -241,7 +240,7 @@
if (param.isValid()) {
*param;
} else {
- *param; // expected-warning {{invocation of method 'operator*' on object 'param' while it is in the 'consumed' state}}
+ *param;
}
param = nullptr;
diff --git a/test/SemaCXX/warn-consumed-parsing.cpp b/test/SemaCXX/warn-consumed-parsing.cpp
index 4408dfc..001fb86 100644
--- a/test/SemaCXX/warn-consumed-parsing.cpp
+++ b/test/SemaCXX/warn-consumed-parsing.cpp
@@ -1,9 +1,9 @@
// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -std=c++11 %s
#define CALLABLE_WHEN_UNCONSUMED __attribute__ ((callable_when_unconsumed))
-#define CONSUMABLE __attribute__ ((consumable))
+#define CONSUMABLE(state) __attribute__ ((consumable(state)))
#define CONSUMES __attribute__ ((consumes))
-#define RETURN_TYPESTATE(State) __attribute__ ((return_typestate(State)))
+#define RETURN_TYPESTATE(state) __attribute__ ((return_typestate(state)))
#define TESTS_UNCONSUMED __attribute__ ((tests_unconsumed))
// FIXME: This test is here because the warning is issued by the Consumed
@@ -25,15 +25,15 @@
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 var2 CALLABLE_WHEN_UNCONSUMED; // expected-warning {{'callable_when_unconsumed' attribute only applies to methods}}
-int var3 CONSUMABLE; // expected-warning {{'consumable' attribute only applies to classes}}
+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 function2() CALLABLE_WHEN_UNCONSUMED; // expected-warning {{'callable_when_unconsumed' attribute only applies to methods}}
-void function3() CONSUMABLE; // expected-warning {{'consumable' attribute only applies to classes}}
+void function3() CONSUMABLE(consumed); // expected-warning {{'consumable' attribute only applies to classes}}
-class CONSUMABLE AttrTester1 {
+class CONSUMABLE(unknown) AttrTester1 {
void callableWhenUnconsumed() CALLABLE_WHEN_UNCONSUMED;
void consumes() CONSUMES;
bool testsUnconsumed() TESTS_UNCONSUMED;
@@ -47,3 +47,5 @@
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}}
};
+
+class CONSUMABLE(42) AttrTester3; // expected-error {{'consumable' attribute requires an identifier}}