Skip to content

Commit cc376f0

Browse files
committed
fix an issue in update_mc_script that the error case is not handle
properly
1 parent e6ada71 commit cc376f0

File tree

4 files changed

+56
-13
lines changed

4 files changed

+56
-13
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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
; 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
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
@@ -2468,6 +2468,7 @@ def get_autogennote_suffix(parser, args):
24682468
"verbose",
24692469
"force_update",
24702470
"reset_variable_names",
2471+
"llvm_mc_binary",
24712472
):
24722473
continue
24732474
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
@@ -15,15 +15,14 @@
1515

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

2524

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

@@ -97,8 +104,16 @@ def getStdCheckLine(prefix, output, mc_mode):
97104
return o
98105

99106

100-
def getErrCheckLine(prefix, output, mc_mode):
101-
return COMMENT[mc_mode] + " " + prefix + ": " + ":[[@LINE-1]]" + output + "\n"
107+
def getErrCheckLine(prefix, output, mc_mode, line_offset=1):
108+
return (
109+
COMMENT[mc_mode]
110+
+ " "
111+
+ prefix
112+
+ ": "
113+
+ ":[[@LINE-{}]]".format(line_offset)
114+
+ output
115+
+ "\n"
116+
)
102117

103118

104119
def main():
@@ -151,11 +166,19 @@ def main():
151166
assert len(commands) >= 2
152167
mc_cmd = " | ".join(commands[:-1])
153168
filecheck_cmd = commands[-1]
154-
mc_tool = mc_cmd.split(" ")[0]
155169

156170
# special handling for negating exit status
157-
if mc_tool == "not":
158-
mc_tool = mc_tool + " " + mc_cmd.split(" ")[1]
171+
# if not is used in runline, disable rc check, since
172+
# the command might or might not
173+
# return non-zero code on a single line run
174+
checkRC = True
175+
mc_cmd_args = mc_cmd.strip().split()
176+
if mc_cmd_args[0] == "not":
177+
checkRC = False
178+
mc_tool = mc_cmd_args[1]
179+
mc_cmd = mc_cmd[len(mc_cmd_args[0]) :].strip()
180+
else:
181+
mc_tool = mc_cmd_args[0]
159182

160183
triple_in_cmd = None
161184
m = common.TRIPLE_ARG_RE.search(mc_cmd)
@@ -188,6 +211,7 @@ def main():
188211
(
189212
check_prefixes,
190213
mc_tool,
214+
checkRC,
191215
mc_cmd_args,
192216
triple_in_cmd,
193217
march_in_cmd,
@@ -204,6 +228,7 @@ def main():
204228
for (
205229
prefixes,
206230
mc_tool,
231+
checkRC,
207232
mc_args,
208233
triple_in_cmd,
209234
march_in_cmd,
@@ -222,6 +247,7 @@ def main():
222247
# get output for each testline
223248
out = invoke_tool(
224249
ti.args.llvm_mc_binary or mc_tool,
250+
checkRC,
225251
mc_args,
226252
line,
227253
verbose=ti.args.verbose,
@@ -278,6 +304,9 @@ def main():
278304
# each run_id can only be used once
279305
gen_prefix = ""
280306
used_runid = set()
307+
308+
# line number diff between generated prefix and testline
309+
line_offset = 1
281310
for prefix, tup in p_dict_sorted.items():
282311
o, run_ids = tup
283312

@@ -294,9 +323,13 @@ def main():
294323
used_prefixes.add(prefix)
295324

296325
if hasErr(o):
297-
gen_prefix += getErrCheckLine(prefix, o, mc_mode)
326+
newline = getErrCheckLine(prefix, o, mc_mode, line_offset)
298327
else:
299-
gen_prefix += getStdCheckLine(prefix, o, mc_mode)
328+
newline = getStdCheckLine(prefix, o, mc_mode)
329+
330+
if newline:
331+
gen_prefix += newline
332+
line_offset += 1
300333

301334
generated_prefixes.append(gen_prefix.rstrip("\n"))
302335

0 commit comments

Comments
 (0)