From 1745ba41b196d80d8a6739dffcbb6f613d371f29 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bal=C3=A1zs=20K=C3=A9ri?= <1.int32@gmail.com> Date: Thu, 30 Jul 2020 08:36:05 +0200 Subject: [PATCH] [Analyzer] Remove inclusion of uniqueing decl from diagnostic profile. The uniqueing decl in PathDiagnostic is the declaration with the uniqueing loc, as stated by documentation comments. It is enough to include the uniqueing loc in the profile. It is possible to have objects with different uniqueing decl but same location, at least with templates. These belong to the same class and should have same profile. Reviewed By: vsavchenko, NoQ Differential Revision: https://reviews.llvm.org/D84843 --- clang/lib/Analysis/PathDiagnostic.cpp | 1 - clang/test/Analysis/report-uniqueing.cpp | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 clang/test/Analysis/report-uniqueing.cpp diff --git a/clang/lib/Analysis/PathDiagnostic.cpp b/clang/lib/Analysis/PathDiagnostic.cpp index 9aa3386..f80b99b 100644 --- a/clang/lib/Analysis/PathDiagnostic.cpp +++ b/clang/lib/Analysis/PathDiagnostic.cpp @@ -1134,7 +1134,6 @@ void PathDiagnosticPopUpPiece::Profile(llvm::FoldingSetNodeID &ID) const { void PathDiagnostic::Profile(llvm::FoldingSetNodeID &ID) const { ID.Add(getLocation()); ID.Add(getUniqueingLoc()); - ID.AddPointer(getUniqueingLoc().isValid() ? getUniqueingDecl() : nullptr); ID.AddString(BugType); ID.AddString(VerboseDesc); ID.AddString(Category); diff --git a/clang/test/Analysis/report-uniqueing.cpp b/clang/test/Analysis/report-uniqueing.cpp new file mode 100644 index 0000000..0e4d50e --- /dev/null +++ b/clang/test/Analysis/report-uniqueing.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_analyze_cc1 -verify %s \ +// RUN: -analyzer-checker=security + +void bzero(void *, unsigned long); + +template void foo(T l) { + // The warning comes from multiple instances and with + // different declarations that have same source location. + // One instance should be shown. + bzero(l, 1); // expected-warning{{The bzero() function is obsoleted}} +} + +void p(int *p, unsigned *q) { + foo(p); + foo(q); +} -- 2.7.4