| 1 |
// RUN: %clang_analyze_cc1 -std=c++14 -w -analyzer-checker=core,cplusplus -analyzer-output=text -verify %s |
| 2 |
|
| 3 |
namespace no_crash_on_delete_dtor { |
| 4 |
// We were crashing when producing diagnostics for this code, but not for the |
| 5 |
// report that it currently emits. Instead, Static Analyzer was thinking that |
| 6 |
// p.get()->foo() is a null dereference because it was dropping |
| 7 |
// constraints over x too early and took a different branch next time |
| 8 |
// we call .get(). |
| 9 |
struct S { |
| 10 |
void foo(); |
| 11 |
~S(); |
| 12 |
}; |
| 13 |
|
| 14 |
struct smart_ptr { |
| 15 |
int x; |
| 16 |
S *s; |
| 17 |
smart_ptr(S *); |
| 18 |
S *get() { |
| 19 |
return (x || 0) ? nullptr : s; // expected-note{{Field 'x' is 0}} |
| 20 |
// expected-note@-1{{Left side of '||' is false}} |
| 21 |
// expected-note@-2{{'?' condition is false}} |
| 22 |
// expected-warning@-3{{Use of memory after it is released}} |
| 23 |
// expected-note@-4{{Use of memory after it is released}} |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
void bar(smart_ptr p) { |
| 28 |
delete p.get(); // expected-note{{Memory is released}} |
| 29 |
p.get()->foo(); // expected-note{{Calling 'smart_ptr::get'}} |
| 30 |
} |
| 31 |
} // namespace no_crash_on_delete_dtor |