Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / diagnostics / dtors.cpp
blob6a8349da9d78c14d73756760e6d02dd9e2681f1a
1 // RUN: %clang_analyze_cc1 -std=c++14 -w -analyzer-checker=core,cplusplus -analyzer-output=text -verify %s
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();
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 freed}}
23 // expected-note@-4{{Use of memory after it is freed}}
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'}}
31 } // namespace no_crash_on_delete_dtor