summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorGabor Horvath <xazax.hun@gmail.com>2017-10-30 12:16:07 +0000
committerGabor Horvath <xazax.hun@gmail.com>2017-10-30 12:16:07 +0000
commit404fcd3069def112f95822bbd48e6e3e2b27f0df (patch)
tree2f9b816664f09ae590e471d6e89ddcda4a005bc6 /clang
parent3bd24f9440b62523577f790993c55f6bd8700fe0 (diff)
downloadbcm5719-llvm-404fcd3069def112f95822bbd48e6e3e2b27f0df.tar.gz
bcm5719-llvm-404fcd3069def112f95822bbd48e6e3e2b27f0df.zip
[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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/StaticAnalyzer/Core/IssueHash.cpp7
-rw-r--r--clang/test/Analysis/bug_hash_test.cpp14
-rw-r--r--clang/test/Analysis/edges-new.mm2
3 files changed, 17 insertions, 6 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
index abdea88b1db..274ebe7a941 100644
--- a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -33,6 +33,13 @@ static std::string GetSignature(const FunctionDecl *Target) {
return "";
std::string Signature;
+ // When a flow sensitive bug happens in templated code we should not generate
+ // distinct hash value for every instantiation. Use the signature from the
+ // primary template.
+ if (const FunctionDecl *InstantiatedFrom =
+ Target->getTemplateInstantiationPattern())
+ Target = InstantiatedFrom;
+
if (!isa<CXXConstructorDecl>(Target) && !isa<CXXDestructorDecl>(Target) &&
!isa<CXXConversionDecl>(Target))
Signature.append(Target->getReturnType().getAsString()).append(" ");
diff --git a/clang/test/Analysis/bug_hash_test.cpp b/clang/test/Analysis/bug_hash_test.cpp
index f1fbb59a6a4..f397d181e66 100644
--- a/clang/test/Analysis/bug_hash_test.cpp
+++ b/clang/test/Analysis/bug_hash_test.cpp
@@ -71,15 +71,13 @@ void testLambda() {
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 @@ template <typename T>
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;
diff --git a/clang/test/Analysis/edges-new.mm b/clang/test/Analysis/edges-new.mm
index 47a125ab090..f310f1bfa12 100644
--- a/clang/test/Analysis/edges-new.mm
+++ b/clang/test/Analysis/edges-new.mm
@@ -20288,7 +20288,7 @@ namespace rdar14960554 {
// CHECK-NEXT: <key>type</key><string>Bad deallocator</string>
// CHECK-NEXT: <key>check_name</key><string>unix.MismatchedDeallocator</string>
// CHECK-NEXT: <!-- This hash is experimental and going to change! -->
-// CHECK-NEXT: <key>issue_hash_content_of_line_in_context</key><string>d9dbbf68db41ab74e2158f4b131abe34</string>
+// CHECK-NEXT: <key>issue_hash_content_of_line_in_context</key><string>046c88d1c91ff46d6506dff5ff880756</string>
// CHECK-NEXT: <key>issue_hash_function_offset</key><string>0</string>
// CHECK-NEXT: <key>location</key>
// CHECK-NEXT: <dict>
OpenPOWER on IntegriCloud