Skip to content

Commit 5bfadb6

Browse files
committed
fix an issue in update_mc_script that the error case is not handle
properly
1 parent 92663de commit 5bfadb6

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
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/update_mc_test_checks.py

Lines changed: 42 additions & 9 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, prefix_not, 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,20 @@ 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+
# if not is used in runline, the command might or might not
36+
# return non-zero code on a single line run
37+
try:
38+
out = subprocess.check_output(cmd, shell=True, stderr=subprocess.DEVNULL)
39+
except:
40+
if prefix_not:
41+
cmd = 'echo "' + testline + '" | ' + "not " + exe + " " + args
42+
if verbose:
43+
print("Command: ", cmd)
44+
out = subprocess.check_output(cmd, shell=True, stderr=subprocess.DEVNULL)
45+
else:
46+
raise Exception("Command '{}' return non-zero value".format(cmd))
47+
3648
# Fix line endings to unix CR style.
3749
return out.decode().replace("\r\n", "\n")
3850

@@ -97,8 +109,16 @@ def getStdCheckLine(prefix, output, mc_mode):
97109
return o
98110

99111

100-
def getErrCheckLine(prefix, output, mc_mode):
101-
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+
)
102122

103123

104124
def main():
@@ -151,11 +171,16 @@ def main():
151171
assert len(commands) >= 2
152172
mc_cmd = " | ".join(commands[:-1])
153173
filecheck_cmd = commands[-1]
154-
mc_tool = mc_cmd.split(" ")[0]
155174

156175
# special handling for negating exit status
157-
if mc_tool == "not":
158-
mc_tool = mc_tool + " " + mc_cmd.split(" ")[1]
176+
prefix_not = ""
177+
mc_cmd_args = mc_cmd.split(" ")
178+
if mc_cmd_args[0] == "not":
179+
prefix_not = mc_cmd_args[0]
180+
mc_tool = mc_cmd_args[1]
181+
mc_cmd = mc_cmd[len(mc_cmd_args[0]) :].strip()
182+
else:
183+
mc_tool = mc_cmd_args[0]
159184

160185
triple_in_cmd = None
161186
m = common.TRIPLE_ARG_RE.search(mc_cmd)
@@ -188,6 +213,7 @@ def main():
188213
(
189214
check_prefixes,
190215
mc_tool,
216+
prefix_not,
191217
mc_cmd_args,
192218
triple_in_cmd,
193219
march_in_cmd,
@@ -204,6 +230,7 @@ def main():
204230
for (
205231
prefixes,
206232
mc_tool,
233+
prefix_not,
207234
mc_args,
208235
triple_in_cmd,
209236
march_in_cmd,
@@ -222,6 +249,7 @@ def main():
222249
# get output for each testline
223250
out = invoke_tool(
224251
ti.args.llvm_mc_binary or mc_tool,
252+
prefix_not,
225253
mc_args,
226254
line,
227255
verbose=ti.args.verbose,
@@ -278,6 +306,9 @@ def main():
278306
# each run_id can only be used once
279307
gen_prefix = ""
280308
used_runid = set()
309+
310+
# line number diff between generated prefix and testline
311+
line_offset = 1
281312
for prefix, tup in p_dict_sorted.items():
282313
o, run_ids = tup
283314

@@ -294,10 +325,12 @@ def main():
294325
used_prefixes.add(prefix)
295326

296327
if hasErr(o):
297-
gen_prefix += getErrCheckLine(prefix, o, mc_mode)
328+
gen_prefix += getErrCheckLine(prefix, o, mc_mode, line_offset)
298329
else:
299330
gen_prefix += getStdCheckLine(prefix, o, mc_mode)
300331

332+
line_offset += 1
333+
301334
generated_prefixes.append(gen_prefix.rstrip("\n"))
302335

303336
# write output

0 commit comments

Comments
 (0)