[analyzer] Use the signature of the primary template for issue hash calculation
Now when a template is instantiated more times and there is a bug found in the
instantiations the issue hash will be different for each instantiation even if
every other property of the bug (path, message, location) is the same.
This patch aims to resolve this issue. Note that explicit specializations still
generate different hashes but that is intended.
Differential Revision: https://reviews.llvm.org/D38728
llvm-svn: 316900
diff --git a/clang/test/Analysis/bug_hash_test.cpp b/clang/test/Analysis/bug_hash_test.cpp
index f1fbb59..f397d18 100644
--- a/clang/test/Analysis/bug_hash_test.cpp
+++ b/clang/test/Analysis/bug_hash_test.cpp
@@ -71,15 +71,13 @@
template <typename T>
void f(T) {
- clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void f(double)$27$clang_analyzer_hashDump(5);$Category}}
- // expected-warning@-1{{debug.ExprInspection$void f(int)$27$clang_analyzer_hashDump(5);$Category}}
+ clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void f(T)$27$clang_analyzer_hashDump(5);$Category}}
}
template <typename T>
struct TX {
void f(T) {
- clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TX<double>::f(double)$29$clang_analyzer_hashDump(5);$Category}}
- // expected-warning@-1{{debug.ExprInspection$void TX<int>::f(int)$29$clang_analyzer_hashDump(5);$Category}}
+ clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TX::f(T)$29$clang_analyzer_hashDump(5);$Category}}
}
};
@@ -99,11 +97,17 @@
struct TTX {
template<typename S>
void f(T, S) {
- clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TTX<int>::f(int, int)$29$clang_analyzer_hashDump(5);$Category}}
+ clang_analyzer_hashDump(5); // expected-warning {{debug.ExprInspection$void TTX::f(T, S)$29$clang_analyzer_hashDump(5);$Category}}
}
};
void g() {
+ // TX<int> and TX<double> is instantiated from the same code with the same
+ // source locations. The same error happining in both of the instantiations
+ // should share the common hash. This means we should not include the
+ // template argument for these types in the function signature.
+ // Note that, we still want the hash to be different for explicit
+ // specializations.
TX<int> x;
TX<double> y;
TX<long> xl;