Skip to content

Commit 6800538

Browse files
committed
Auto merge of #26984 - nham:errorck-ignore-long-diag, r=brson
Currently errorck yields bogus `duplicate error code` messages when an error code occurs inside of a long diagnostic message (see #26982), because errorck just goes line by line checking for error codes and recording them all. A simplistic approach to fixing this is just to detect the beginning of a long diagnostic raw string literal (`r##"`) and skip lines until the end of the raw string literal is encountered. I'm not completely confident in this approach, but I think a more robust approach would be more complicated and I wanted to get feedback before pursuing that.
2 parents 0fbceba + 4630fc7 commit 6800538

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/etc/errorck.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
errcode_map = {}
2424
error_re = re.compile("(E\d\d\d\d)")
2525

26+
# In the register_long_diagnostics! macro, entries look like this:
27+
#
28+
# EXXXX: r##"
29+
# <Long diagnostic message>
30+
# "##,
31+
#
32+
# These two variables are for detecting the beginning and end of diagnostic
33+
# messages so that duplicate error codes are not reported when a code occurs
34+
# inside a diagnostic message
35+
long_diag_begin = "r##\""
36+
long_diag_end = "\"##"
37+
2638
for (dirpath, dirnames, filenames) in os.walk(src_dir):
2739
if "src/test" in dirpath or "src/llvm" in dirpath:
2840
# Short circuit for fast
@@ -35,7 +47,14 @@
3547
path = os.path.join(dirpath, filename)
3648

3749
with open(path, 'r') as f:
50+
inside_long_diag = False
3851
for line_num, line in enumerate(f, start=1):
52+
if inside_long_diag:
53+
# Skip duplicate error code checking for this line
54+
if long_diag_end in line:
55+
inside_long_diag = False
56+
continue
57+
3958
match = error_re.search(line)
4059
if match:
4160
errcode = match.group(1)
@@ -47,6 +66,9 @@
4766
else:
4867
errcode_map[errcode] = new_record
4968

69+
if long_diag_begin in line:
70+
inside_long_diag = True
71+
5072
errors = False
5173
all_errors = []
5274

0 commit comments

Comments
 (0)