diff options
| author | DeLesley Hutchins <delesley@google.com> | 2013-10-17 22:53:04 +0000 |
|---|---|---|
| committer | DeLesley Hutchins <delesley@google.com> | 2013-10-17 22:53:04 +0000 |
| commit | 36ea1dd4fc5e193d0eb7f6bf69f15d3779b6da24 (patch) | |
| tree | 1995fb9ee35a51717ef613dfd7b3280928716ebc /clang/test | |
| parent | c1d547129185cabebc2d0857eea6a03d5bdf8b81 (diff) | |
| download | bcm5719-llvm-36ea1dd4fc5e193d0eb7f6bf69f15d3779b6da24.tar.gz bcm5719-llvm-36ea1dd4fc5e193d0eb7f6bf69f15d3779b6da24.zip | |
Consumed Analysis: Allow parameters that are passed by non-const reference
to be treated as return values, and marked with the "returned_typestate"
attribute. Patch by chris.wailes@gmail.com; reviewed by delesley@google.com.
llvm-svn: 192932
Diffstat (limited to 'clang/test')
| -rw-r--r-- | clang/test/SemaCXX/warn-consumed-analysis.cpp | 18 | ||||
| -rw-r--r-- | clang/test/SemaCXX/warn-consumed-parsing.cpp | 2 |
2 files changed, 20 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/warn-consumed-analysis.cpp b/clang/test/SemaCXX/warn-consumed-analysis.cpp index 264d27af5e7..dd1bb2312d8 100644 --- a/clang/test/SemaCXX/warn-consumed-analysis.cpp +++ b/clang/test/SemaCXX/warn-consumed-analysis.cpp @@ -388,6 +388,24 @@ void testFunctionParam(ConsumableClass<int> param) { *param; // expected-warning {{invocation of method 'operator*' on object 'param' while it is in the 'consumed' state}} } +void testParamReturnTypestateCallee(bool cond, ConsumableClass<int> &Param RETURN_TYPESTATE(unconsumed)) { // expected-warning {{parameter 'Param' not in expected state when the function returns: expected 'unconsumed', observed 'consumed'}} + + if (cond) { + Param.consume(); + return; // expected-warning {{parameter 'Param' not in expected state when the function returns: expected 'unconsumed', observed 'consumed'}} + } + + Param.consume(); +} + +void testParamReturnTypestateCaller() { + ConsumableClass<int> var; + + testParamReturnTypestateCallee(true, var); + + *var; +} + void testCallingConventions() { ConsumableClass<int> var(42); diff --git a/clang/test/SemaCXX/warn-consumed-parsing.cpp b/clang/test/SemaCXX/warn-consumed-parsing.cpp index 80021020ca6..c1bc1078733 100644 --- a/clang/test/SemaCXX/warn-consumed-parsing.cpp +++ b/clang/test/SemaCXX/warn-consumed-parsing.cpp @@ -44,6 +44,8 @@ class CONSUMABLE(unknown) AttrTester1 { AttrTester1 returnTypestateTester0() RETURN_TYPESTATE(not_a_state); // expected-warning {{'return_typestate' attribute argument not supported: 'not_a_state'}} AttrTester1 returnTypestateTester1() RETURN_TYPESTATE(42); // expected-error {{'return_typestate' attribute requires an identifier}} +void returnTypestateTester2(AttrTester1 &Param RETURN_TYPESTATE(unconsumed)); + 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() SET_TYPESTATE(consumed); // expected-warning {{consumed analysis attribute is attached to member of class 'AttrTester2' which isn't marked as consumable}} |

