Skip to content

Commit

Permalink
clang-tidy report converter now supports clang17 fixit format
Browse files Browse the repository at this point in the history
clang-tidy version 17 introduced a new fixit diagnostic formatting.
The report converter is now prepared to parse this new format.
It also still supports the old format.
  • Loading branch information
dkrupp committed Oct 20, 2023
1 parent fa41e4e commit a7fcd4a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ def __init__(self):
# Checker message.
r'(?P<message>.*)')

# Matches pre clang 17 fix-its
# " fixit-text"
self.fixit_old_re = re.compile(
r'^\s+(?P<message>\S.*)')

# Matches post clang 17 fix-its
# " 28 | fixit-text"
self.fixit_new_re = re.compile(
r'^\s*\d*\s*\|\s*(?P<message>\S.*)')

def _parse_line(
self,
it: Iterator[str],
Expand Down Expand Up @@ -137,15 +147,26 @@ def _parse_fixits(

while self.message_line_re.match(line) is None and \
self.note_line_re.match(line) is None:
message_text = line.strip()

match = self.fixit_new_re.match(line)
old_format = False
if not match:
match = self.fixit_old_re.match(line)
old_format = True
message_text = match.group("message")
if message_text != '':
if old_format:
# Until clang-tidy 16 the fixit
# line starts with white spaces
col = line.find(message_text) + 1
else:
# In later versions we have white spaces the
# optionally a line number and then a | character
col = line.find(message_text) - line.find("|") - 1
report.bug_path_events.append(BugPathEvent(
f"{message_text} (fixit)",
report.file,
report.line,
line.find(message_text) + 1))

col))
line = next(it)
return line

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,8 @@ def test_tidy3(self):
self.__check_analyzer_result('tidy3.out', 'test3.hh_clang-tidy.plist',
['files/test3.cpp', 'files/test3.hh'],
'tidy3_hh.plist')

self.__check_analyzer_result('tidy3-clang17.out',
'test3.hh_clang-tidy.plist',
['files/test3.cpp', 'files/test3.hh'],
'tidy3_hh.plist')
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
files/test3.hh:6:6: warning: Dereference of null pointer (loaded from variable 'x') [clang-analyzer-core.NullDereference]
6 | *x = 42;
| ^
files/test3.cpp:4:3: note: 'x' initialized to a null pointer value
4 | int* x = 0;
| ^~~~~~
files/test3.cpp:6:11: note: Assuming 'argc' is > 3
6 | if (foo(argc > 3)) {
| ^~~~~~~~
files/test3.cpp:6:3: note: Taking true branch
6 | if (foo(argc > 3)) {
| ^
files/test3.cpp:7:9: note: Passing null pointer value via 1st parameter 'x'
7 | bar(x);
| ^
files/test3.cpp:7:5: note: Calling 'bar'
7 | bar(x);
| ^~~~~~
files/test3.hh:6:6: note: Dereference of null pointer (loaded from variable 'x')
6 | *x = 42;
| ~ ^
files/test3.cpp:4:12: warning: use nullptr [modernize-use-nullptr]
4 | int* x = 0;
| ^
| nullptr

0 comments on commit a7fcd4a

Please sign in to comment.