2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
|
2018-06-13 03:07:41 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist-multi-file %s -o %t.plist
|
2019-06-11 22:21:32 +08:00
|
|
|
// RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/method-call-path-notes.cpp.plist -
|
2012-08-04 07:08:49 +08:00
|
|
|
|
|
|
|
// Test warning about null or uninitialized pointer values used as instance member
|
|
|
|
// calls.
|
|
|
|
class TestInstanceCall {
|
|
|
|
public:
|
|
|
|
void foo() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_ic() {
|
2013-02-27 03:44:38 +08:00
|
|
|
TestInstanceCall *p; // expected-note {{'p' declared without an initial value}}
|
2012-08-04 07:08:49 +08:00
|
|
|
p->foo(); // expected-warning {{Called C++ object pointer is uninitialized}} expected-note {{Called C++ object pointer is uninitialized}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_ic_null() {
|
2013-02-27 03:44:38 +08:00
|
|
|
TestInstanceCall *p = 0; // expected-note {{'p' initialized to a null pointer value}}
|
2012-08-04 07:08:49 +08:00
|
|
|
p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_ic_set_to_null() {
|
|
|
|
TestInstanceCall *p;
|
|
|
|
p = 0; // expected-note {{Null pointer value stored to 'p'}}
|
|
|
|
p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_ic_null(TestInstanceCall *p) {
|
2012-10-26 06:07:10 +08:00
|
|
|
if (!p) // expected-note {{Assuming 'p' is null}} expected-note {{Taking true branch}}
|
2012-08-04 07:08:49 +08:00
|
|
|
p->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_ic_member_ptr() {
|
2013-02-27 03:44:38 +08:00
|
|
|
TestInstanceCall *p = 0; // expected-note {{'p' initialized to a null pointer value}}
|
2012-08-04 07:08:49 +08:00
|
|
|
typedef void (TestInstanceCall::*IC_Ptr)();
|
|
|
|
IC_Ptr bar = &TestInstanceCall::foo;
|
|
|
|
(p->*bar)(); // expected-warning {{Called C++ object pointer is null}} expected-note{{Called C++ object pointer is null}}
|
|
|
|
}
|
2012-08-07 05:28:14 +08:00
|
|
|
|
2012-08-16 08:03:33 +08:00
|
|
|
void test_cast(const TestInstanceCall *p) {
|
2012-10-26 06:07:10 +08:00
|
|
|
if (!p) // expected-note {{Assuming 'p' is null}} expected-note {{Taking true branch}}
|
2012-08-16 08:03:33 +08:00
|
|
|
const_cast<TestInstanceCall *>(p)->foo(); // expected-warning {{Called C++ object pointer is null}} expected-note {{Called C++ object pointer is null}}
|
|
|
|
}
|
|
|
|
|