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
|
[analyzer][tests] Use normalize_plist in place of diff_plist (`cat` cases)
Summary:
The `%diff_plist` lit substitution invokes `diff` with a non-portable
`-I` option. The intended effect can be achieved by normalizing the
inputs to `diff` beforehand. Such normalization can be done with
`grep -Ev`, which is also used by other tests.
This patch applies the change (adjusted for review comments) described
in http://lists.llvm.org/pipermail/cfe-dev/2019-April/061904.html
mechanically to the cases where the output file is piped to
`%diff_plist` via `cat`.
The changes were applied via a script, except that
`clang/test/Analysis/NewDelete-path-notes.cpp` and
`clang/test/Analysis/plist-macros-with-expansion.cpp` were each adjusted
for the line-continuation on the relevant `RUN` step.
Reviewers: NoQ, sfertile, xingxue, jasonliu, daltenty
Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp, Charusso, jsji, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D62950
llvm-svn: 362996
2019-06-11 06:37:31 +08:00
|
|
|
// RUN: %normalize_plist <%t.plist | diff -u %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}}
|
|
|
|
}
|
|
|
|
|