diff options
Diffstat (limited to 'test/Analysis/temporaries.cpp')
-rw-r--r-- | test/Analysis/temporaries.cpp | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/test/Analysis/temporaries.cpp b/test/Analysis/temporaries.cpp index df1ab5a..32a4d3b 100644 --- a/test/Analysis/temporaries.cpp +++ b/test/Analysis/temporaries.cpp @@ -1,4 +1,6 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -analyzer-ipa=inlining -verify -w %s +// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -w %s + +extern bool clang_analyzer_eval(bool); struct Trivial { Trivial(int x) : value(x) {} @@ -16,7 +18,7 @@ Trivial getTrivial() { } const Trivial &getTrivialRef() { - return Trivial(42); // expected-warning {{Address of stack memory associated with temporary object of type 'struct Trivial' returned to caller}} + return Trivial(42); // expected-warning {{Address of stack memory associated with temporary object of type 'Trivial' returned to caller}} } @@ -25,6 +27,52 @@ NonTrivial getNonTrivial() { } const NonTrivial &getNonTrivialRef() { - return NonTrivial(42); // expected-warning {{Address of stack memory associated with temporary object of type 'struct NonTrivial' returned to caller}} + return NonTrivial(42); // expected-warning {{Address of stack memory associated with temporary object of type 'NonTrivial' returned to caller}} +} + +namespace rdar13265460 { + struct TrivialSubclass : public Trivial { + TrivialSubclass(int x) : Trivial(x), anotherValue(-x) {} + int anotherValue; + }; + + TrivialSubclass getTrivialSub() { + TrivialSubclass obj(1); + obj.value = 42; + obj.anotherValue = -42; + return obj; + } + + void testImmediate() { + TrivialSubclass obj = getTrivialSub(); + + clang_analyzer_eval(obj.value == 42); // expected-warning{{TRUE}} + clang_analyzer_eval(obj.anotherValue == -42); // expected-warning{{TRUE}} + + clang_analyzer_eval(getTrivialSub().value == 42); // expected-warning{{TRUE}} + clang_analyzer_eval(getTrivialSub().anotherValue == -42); // expected-warning{{TRUE}} + } + + void testMaterializeTemporaryExpr() { + const TrivialSubclass &ref = getTrivialSub(); + clang_analyzer_eval(ref.value == 42); // expected-warning{{TRUE}} + + const Trivial &baseRef = getTrivialSub(); + clang_analyzer_eval(baseRef.value == 42); // expected-warning{{TRUE}} + } +} + +namespace rdar13281951 { + struct Derived : public Trivial { + Derived(int value) : Trivial(value), value2(-value) {} + int value2; + }; + + void test() { + Derived obj(1); + obj.value = 42; + const Trivial * const &pointerRef = &obj; + clang_analyzer_eval(pointerRef->value == 42); // expected-warning{{TRUE}} + } } |