From 2f9e8fb6b8195fddf0452dadf6a9b6d824bee23c Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Thu, 10 Jan 2019 23:44:44 +0000 Subject: [PATCH] [analyzer] pr38838, pr39976: Fix crash on diagnosing before implicit destructor. We need to be able to emit the diagnostic at PreImplicitCall, and the patch implements this functionality. However, for now the need for emitting such diagnostics is not all that great: it is only necessary to not crash when emitting a false positive due to an unrelated issue of having dead symbol collection not working properly. Coming up with a non-false-positive test seems impossible with the current set of checkers, though it is likely to be needed for good things as well in the future. Differential Revision: https://reviews.llvm.org/D56042 rdar://problem/46911462 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350907 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 2 ++ test/Analysis/diagnostics/dtors.cpp | 25 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 test/Analysis/diagnostics/dtors.cpp diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index 691176dfc1..3e93bb6a7c 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -723,6 +723,8 @@ PathDiagnosticLocation::create(const ProgramPoint& P, } else if (Optional PIP = P.getAs()) { return PathDiagnosticLocation(PIP->getInitializer()->getSourceLocation(), SMng); + } else if (Optional PIC = P.getAs()) { + return PathDiagnosticLocation(PIC->getLocation(), SMng); } else if (Optional PIE = P.getAs()) { return PathDiagnosticLocation(PIE->getLocation(), SMng); } else if (Optional CE = P.getAs()) { diff --git a/test/Analysis/diagnostics/dtors.cpp b/test/Analysis/diagnostics/dtors.cpp new file mode 100644 index 0000000000..094917e432 --- /dev/null +++ b/test/Analysis/diagnostics/dtors.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,cplusplus -verify %s + +// expected-no-diagnostics + +namespace no_crash_on_delete_dtor { +// We were crashing when producing diagnostics for this code. +struct S { + void foo(); + ~S(); +}; + +struct smart_ptr { + int x; + S *s; + smart_ptr(S *); + S *get() { + return (x || 0) ? nullptr : s; + } +}; + +void bar(smart_ptr p) { + delete p.get(); + p.get()->foo(); +} +} // namespace no_crash_on_delete_dtor -- 2.50.1