2013-01-25 07:15:30 +08:00
|
|
|
// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify -w %s
|
2012-08-29 09:11:59 +08:00
|
|
|
|
2013-02-22 07:57:17 +08:00
|
|
|
extern bool clang_analyzer_eval(bool);
|
|
|
|
|
2012-08-29 09:11:59 +08:00
|
|
|
struct Trivial {
|
|
|
|
Trivial(int x) : value(x) {}
|
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NonTrivial : public Trivial {
|
|
|
|
NonTrivial(int x) : Trivial(x) {}
|
|
|
|
~NonTrivial();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Trivial getTrivial() {
|
|
|
|
return Trivial(42); // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
const Trivial &getTrivialRef() {
|
2013-02-26 09:21:21 +08:00
|
|
|
return Trivial(42); // expected-warning {{Address of stack memory associated with temporary object of type 'Trivial' returned to caller}}
|
2012-08-29 09:11:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NonTrivial getNonTrivial() {
|
|
|
|
return NonTrivial(42); // no-warning
|
|
|
|
}
|
|
|
|
|
|
|
|
const NonTrivial &getNonTrivialRef() {
|
2013-02-26 09:21:21 +08:00
|
|
|
return NonTrivial(42); // expected-warning {{Address of stack memory associated with temporary object of type 'NonTrivial' returned to caller}}
|
2012-08-29 09:11:59 +08:00
|
|
|
}
|
|
|
|
|
2013-02-22 07:57:17 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-22 09:51:15 +08:00
|
|
|
void testImmediate() {
|
2013-02-22 07:57:17 +08:00
|
|
|
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}}
|
|
|
|
}
|
2013-02-22 09:51:15 +08:00
|
|
|
|
|
|
|
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}}
|
|
|
|
}
|
2013-02-22 07:57:17 +08:00
|
|
|
}
|
|
|
|
|