[PATCH] D38728: [analyzer] Use the signature of the primary template for issue hash calculation
Phabricator via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 30 05:16:48 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316900: [analyzer] Use the signature of the primary template for issue hash calculation (authored by xazax).
Changed prior to commit:
https://reviews.llvm.org/D38728?vs=118788&id=120804#toc
Repository:
rL LLVM
https://reviews.llvm.org/D38728
Files:
cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
cfe/trunk/test/Analysis/bug_hash_test.cpp
cfe/trunk/test/Analysis/edges-new.mm
Index: cfe/trunk/test/Analysis/bug_hash_test.cpp
===================================================================
--- cfe/trunk/test/Analysis/bug_hash_test.cpp
+++ cfe/trunk/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 at -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 at -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;
Index: cfe/trunk/test/Analysis/edges-new.mm
===================================================================
--- cfe/trunk/test/Analysis/edges-new.mm
+++ cfe/trunk/test/Analysis/edges-new.mm
@@ -20288,7 +20288,7 @@
// 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>
Index: cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/IssueHash.cpp
@@ -33,6 +33,13 @@
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(" ");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38728.120804.patch
Type: text/x-patch
Size: 3571 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171030/353519db/attachment.bin>
More information about the cfe-commits
mailing list