Skip to content

Commit 9ced142

Browse files
committed
fix an issue in update_mc_script that the error case is not handle
properly
1 parent 6f66530 commit 9ced142

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
// RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
1+
// RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECKA %s
2+
// RUN: not llvm-mc -triple=amdgcn %s 2>&1 | FileCheck --check-prefixes=CHECKB %s
23

34
v_bfrev_b32 v5, v299
5+
6+
v_bfrev_b32 v5, v1
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
// NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
2-
// RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECK %s
1+
; NOTE: Assertions have been autogenerated by utils/update_mc_test_checks.py
2+
// RUN: not llvm-mc -triple=amdgcn -show-encoding %s 2>&1 | FileCheck --check-prefixes=CHECKA %s
3+
// RUN: not llvm-mc -triple=amdgcn %s 2>&1 | FileCheck --check-prefixes=CHECKB %s
34

45
v_bfrev_b32 v5, v299
5-
// CHECK: :[[@LINE-1]]:17: error: register index is out of range
6+
// CHECKA: :[[@LINE-1]]:17: error: register index is out of range
7+
// CHECKB: :[[@LINE-2]]:17: error: register index is out of range
8+
9+
v_bfrev_b32 v5, v1
10+
// CHECKA: v_bfrev_b32_e32 v5, v1 ; encoding: [0x01,0x71,0x0a,0x7e]
11+
// CHECKB: v_bfrev_b32_e32 v5, v1

llvm/utils/UpdateTestChecks/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,7 @@ def get_autogennote_suffix(parser, args):
24702470
"verbose",
24712471
"force_update",
24722472
"reset_variable_names",
2473+
"llvm_mc_binary",
24732474
):
24742475
continue
24752476
value = getattr(args, action.dest)

llvm/utils/update_mc_test_checks.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616

1717
mc_LIKE_TOOLS = [
1818
"llvm-mc",
19-
"not llvm-mc",
2019
]
2120
ERROR_RE = re.compile(r":\d+: (warning|error): .*")
2221
ERROR_CHECK_RE = re.compile(r"# COM: .*")
2322
OUTPUT_SKIPPED_RE = re.compile(r"(.text)")
2423
COMMENT = {"asm": "//", "dasm": "#"}
2524

2625

27-
def invoke_tool(exe, cmd_args, testline, verbose=False):
26+
def invoke_tool(exe, checkRC, cmd_args, testline, verbose=False):
2827
if isinstance(cmd_args, list):
2928
args = [applySubstitutions(a, substitutions) for a in cmd_args]
3029
else:
@@ -33,7 +32,15 @@ def invoke_tool(exe, cmd_args, testline, verbose=False):
3332
cmd = 'echo "' + testline + '" | ' + exe + " " + args
3433
if verbose:
3534
print("Command: ", cmd)
36-
out = subprocess.check_output(cmd, shell=True)
35+
36+
out = subprocess.run(
37+
cmd,
38+
shell=True,
39+
check=checkRC,
40+
stdout=subprocess.PIPE,
41+
stderr=subprocess.DEVNULL,
42+
).stdout
43+
3744
# Fix line endings to unix CR style.
3845
return out.decode().replace("\r\n", "\n")
3946

@@ -102,8 +109,16 @@ def getStdCheckLine(prefix, output, mc_mode):
102109
return o
103110

104111

105-
def getErrCheckLine(prefix, output, mc_mode):
106-
return COMMENT[mc_mode] + " " + prefix + ": " + ":[[@LINE-1]]" + output + "\n"
112+
def getErrCheckLine(prefix, output, mc_mode, line_offset=1):
113+
return (
114+
COMMENT[mc_mode]
115+
+ " "
116+
+ prefix
117+
+ ": "
118+
+ ":[[@LINE-{}]]".format(line_offset)
119+
+ output
120+
+ "\n"
121+
)
107122

108123

109124
def main():
@@ -174,11 +189,19 @@ def main():
174189
assert len(commands) >= 2
175190
mc_cmd = " | ".join(commands[:-1])
176191
filecheck_cmd = commands[-1]
177-
mc_tool = mc_cmd.split(" ")[0]
178192

179193
# special handling for negating exit status
180-
if mc_tool == "not":
181-
mc_tool = mc_tool + " " + mc_cmd.split(" ")[1]
194+
# if not is used in runline, disable rc check, since
195+
# the command might or might not
196+
# return non-zero code on a single line run
197+
checkRC = True
198+
mc_cmd_args = mc_cmd.strip().split()
199+
if mc_cmd_args[0] == "not":
200+
checkRC = False
201+
mc_tool = mc_cmd_args[1]
202+
mc_cmd = mc_cmd[len(mc_cmd_args[0]) :].strip()
203+
else:
204+
mc_tool = mc_cmd_args[0]
182205

183206
triple_in_cmd = None
184207
m = common.TRIPLE_ARG_RE.search(mc_cmd)
@@ -211,6 +234,7 @@ def main():
211234
(
212235
check_prefixes,
213236
mc_tool,
237+
checkRC,
214238
mc_cmd_args,
215239
triple_in_cmd,
216240
march_in_cmd,
@@ -231,6 +255,7 @@ def main():
231255
for (
232256
prefixes,
233257
mc_tool,
258+
checkRC,
234259
mc_args,
235260
triple_in_cmd,
236261
march_in_cmd,
@@ -249,6 +274,7 @@ def main():
249274
# get output for each testline
250275
out = invoke_tool(
251276
ti.args.llvm_mc_binary or mc_tool,
277+
checkRC,
252278
mc_args,
253279
line,
254280
verbose=ti.args.verbose,
@@ -305,6 +331,9 @@ def main():
305331
# each run_id can only be used once
306332
gen_prefix = ""
307333
used_runid = set()
334+
335+
# line number diff between generated prefix and testline
336+
line_offset = 1
308337
for prefix, tup in p_dict_sorted.items():
309338
o, run_ids = tup
310339

@@ -321,9 +350,13 @@ def main():
321350
used_prefixes.add(prefix)
322351

323352
if hasErr(o):
324-
gen_prefix += getErrCheckLine(prefix, o, mc_mode)
353+
newline = getErrCheckLine(prefix, o, mc_mode, line_offset)
325354
else:
326-
gen_prefix += getStdCheckLine(prefix, o, mc_mode)
355+
newline = getStdCheckLine(prefix, o, mc_mode)
356+
357+
if newline:
358+
gen_prefix += newline
359+
line_offset += 1
327360

328361
generated_prefixes[input_line] = gen_prefix.rstrip("\n")
329362

0 commit comments

Comments
 (0)