Skip to content

Commit ef53ebd

Browse files
Fix ClangTidy default hash type in codechecker_report_converter (#4661)
* Fix ClangTidy default hash type in codechecker_report_converter Due to backward compatibility, the CodeChecker analyzer uses hash type PATH_SENSITIVE for ClangTidy by default. Meanwhile, the report-converter defaults to CONTEXT_FREE hash type. This creates inconsistencies when running the analysis with the --makefile option, since it uses report-converter after executing clang-tidy. To fix this issue, the report-converter now defaults to PATH_SENSITIVE hash type when processing ClangTidy results. * Change clang_tidy_yaml report hashes
1 parent d71aaf2 commit ef53ebd

13 files changed

Lines changed: 33 additions & 18 deletions

File tree

analyzer/codechecker_analyzer/analyzers/clangtidy/result_handler.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def postprocess_result(
5858
# automatically when using this option we introduced a new choice for
5959
# --report-hash option ('context-free-v2') and we still do not use
6060
# context free hash for 'context-free' choice.
61+
62+
# When changing the default hash_type for ClangTidy, ensure
63+
# it is updated in codechecker_report_converter as well!
6164
hash_type = HashType.PATH_SENSITIVE
6265
if self.report_hash_type == 'context-free-v2':
6366
hash_type = HashType.CONTEXT_FREE

tools/report-converter/codechecker_report_converter/analyzers/clang_tidy/analyzer_result.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import List
1010

1111
from codechecker_report_converter.report import Report
12+
from codechecker_report_converter.report.hash import get_report_hash, HashType
1213

1314
from ..analyzer_result import AnalyzerResultBase
1415
from .parser import Parser
@@ -24,3 +25,8 @@ class AnalyzerResult(AnalyzerResultBase):
2425
def get_reports(self, file_path: str) -> List[Report]:
2526
""" Get reports from the given analyzer result. """
2627
return Parser().get_reports(file_path)
28+
29+
def _add_report_hash(self, report: Report):
30+
# Due to backward compatibility, the CodeChecker analyzer
31+
# uses hash type PATH_SENSITIVE for ClangTidy by default.
32+
report.report_hash = get_report_hash(report, HashType.PATH_SENSITIVE)

tools/report-converter/codechecker_report_converter/analyzers/clang_tidy_yaml/analyzer_result.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import List
1010

1111
from codechecker_report_converter.report import Report
12+
from codechecker_report_converter.report.hash import get_report_hash, HashType
1213

1314
from ..analyzer_result import AnalyzerResultBase
1415
from .parser import Parser
@@ -24,3 +25,8 @@ class AnalyzerResult(AnalyzerResultBase):
2425
def get_reports(self, file_path: str) -> List[Report]:
2526
""" Get reports from the given analyzer result. """
2627
return Parser().get_reports(file_path)
28+
29+
def _add_report_hash(self, report: Report):
30+
# Due to backward compatibility, the CodeChecker analyzer
31+
# uses hash type PATH_SENSITIVE for ClangTidy by default.
32+
report.report_hash = get_report_hash(report, HashType.PATH_SENSITIVE)

tools/report-converter/tests/unit/analyzers/tidy_output_test_files/tidy1.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<key>description</key>
1313
<string>Division by zero</string>
1414
<key>issue_hash_content_of_line_in_context</key>
15-
<string>b8ef906124c39571d9689250d028d16d</string>
15+
<string>79cc349883cacbd7d2a4301ddb79bc68</string>
1616
<key>location</key>
1717
<dict>
1818
<key>col</key>
@@ -70,7 +70,7 @@
7070
<key>description</key>
7171
<string>remainder by zero is undefined</string>
7272
<key>issue_hash_content_of_line_in_context</key>
73-
<string>5a0fa223fabaf319bc0ec3731e27d45a</string>
73+
<string>9785900b66c87f89edcc9daaab59647a</string>
7474
<key>location</key>
7575
<dict>
7676
<key>col</key>

tools/report-converter/tests/unit/analyzers/tidy_output_test_files/tidy2.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<key>description</key>
1313
<string>unused variable 'y'</string>
1414
<key>issue_hash_content_of_line_in_context</key>
15-
<string>9f5469099db1a2765912c8254b32e90b</string>
15+
<string>0afd6d1f5bf7f1856d9f01e4ac92534e</string>
1616
<key>location</key>
1717
<dict>
1818
<key>col</key>
@@ -53,7 +53,7 @@
5353
<key>description</key>
5454
<string>Division by zero</string>
5555
<key>issue_hash_content_of_line_in_context</key>
56-
<string>602f6604275a08320db132be28d3eaf7</string>
56+
<string>1ef143e61c82bfb7af1209b9a0cc629f</string>
5757
<key>location</key>
5858
<dict>
5959
<key>col</key>
@@ -239,7 +239,7 @@
239239
<key>description</key>
240240
<string>remainder by zero is undefined</string>
241241
<key>issue_hash_content_of_line_in_context</key>
242-
<string>0758808c01c22b4a346799d1156c13a5</string>
242+
<string>cac9b3630bea66ab98dfefacc2a8f6d0</string>
243243
<key>location</key>
244244
<dict>
245245
<key>col</key>

tools/report-converter/tests/unit/analyzers/tidy_output_test_files/tidy3_cpp.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<key>description</key>
1313
<string>use nullptr</string>
1414
<key>issue_hash_content_of_line_in_context</key>
15-
<string>fed12e2201409b4f0b225382f92ac4f3</string>
15+
<string>881bd0b5111814b3eaab59f4229eccba</string>
1616
<key>location</key>
1717
<dict>
1818
<key>col</key>

tools/report-converter/tests/unit/analyzers/tidy_output_test_files/tidy3_hh.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<key>description</key>
1313
<string>Dereference of null pointer (loaded from variable 'x')</string>
1414
<key>issue_hash_content_of_line_in_context</key>
15-
<string>056941efdc49d4520272e9b9c6152f3c</string>
15+
<string>0a6cacbf28c3f076a87efdbabdb779e6</string>
1616
<key>location</key>
1717
<dict>
1818
<key>col</key>

tools/report-converter/tests/unit/analyzers/tidy_output_test_files/tidy7.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<key>description</key>
1313
<string>use nullptr</string>
1414
<key>issue_hash_content_of_line_in_context</key>
15-
<string>5385d8fae5f3551df1dcb8e0456b204f</string>
15+
<string>eddcf362e7943111bd32bc42374dbdd8</string>
1616
<key>location</key>
1717
<dict>
1818
<key>col</key>
@@ -69,7 +69,7 @@
6969
<key>description</key>
7070
<string>array index 10 is past the end of the array (that has type 'int[5]')</string>
7171
<key>issue_hash_content_of_line_in_context</key>
72-
<string>f5dfd26909c583aeeeb8f0920b5c0366</string>
72+
<string>1ebc38c3c566592b0a5ee568c7d1d29b</string>
7373
<key>location</key>
7474
<dict>
7575
<key>col</key>
@@ -174,7 +174,7 @@
174174
<key>description</key>
175175
<string>expected ';' at end of declaration</string>
176176
<key>issue_hash_content_of_line_in_context</key>
177-
<string>d1e2722d18925ba9b4f6c1f9bbec1a22</string>
177+
<string>aae82361e0407349e455ca1bd831ff86</string>
178178
<key>location</key>
179179
<dict>
180180
<key>col</key>

tools/report-converter/tests/unit/analyzers/tidy_yaml_output_test_files/tidy1.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<key>description</key>
1313
<string>remainder by zero is undefined</string>
1414
<key>issue_hash_content_of_line_in_context</key>
15-
<string>5a0fa223fabaf319bc0ec3731e27d45a</string>
15+
<string>9785900b66c87f89edcc9daaab59647a</string>
1616
<key>location</key>
1717
<dict>
1818
<key>col</key>

tools/report-converter/tests/unit/analyzers/tidy_yaml_output_test_files/tidy2.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<key>description</key>
1313
<string>unused variable 'y'</string>
1414
<key>issue_hash_content_of_line_in_context</key>
15-
<string>9f5469099db1a2765912c8254b32e90b</string>
15+
<string>0afd6d1f5bf7f1856d9f01e4ac92534e</string>
1616
<key>location</key>
1717
<dict>
1818
<key>col</key>
@@ -53,7 +53,7 @@
5353
<key>description</key>
5454
<string>remainder by zero is undefined</string>
5555
<key>issue_hash_content_of_line_in_context</key>
56-
<string>0758808c01c22b4a346799d1156c13a5</string>
56+
<string>cac9b3630bea66ab98dfefacc2a8f6d0</string>
5757
<key>location</key>
5858
<dict>
5959
<key>col</key>

0 commit comments

Comments
 (0)