Skip to content

Commit 45daa56

Browse files
committed
[sil-bug-reducer] Make the output more explicit about the final file, passes, and given a full command line to reproduce.
1 parent 288ec33 commit 45daa56

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

utils/bug_reducer/bug_reducer/bug_reducer_utils.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def maybe_abspath(x):
6666
return x
6767
return os.path.abspath(x)
6868

69+
6970
class SILOptInvoker(object):
7071

7172
def __init__(self, args, tools, early_passes, extra_args):
@@ -89,15 +90,15 @@ def __init__(self, args, tools, early_passes, extra_args):
8990

9091
# First emit an initial *.sib file. This ensures no matter if we have a
9192
# *.swiftmodule, *.sil, or *.sib file, we are always using *.sib.
92-
self._invoke(args.input_file, self.get_suffixed_filename('initial'),
93-
[])
93+
self._invoke(args.input_file, [],
94+
self.get_suffixed_filename('initial'))
9495
self.input_file = self.get_suffixed_filename('initial+early')
9596

9697
# Finally, run the initial sil-opt invocation running the
9798
# early-passes. We will not run them again.
9899
self._invoke(self.get_suffixed_filename('initial'),
99-
self.input_file,
100-
early_passes)
100+
early_passes,
101+
self.input_file)
101102

102103
def get_suffixed_filename(self, suffix):
103104
basename = self.base_input_file_stem + '_' + suffix
@@ -119,17 +120,22 @@ def base_args(self):
119120
x.append("-module-name=%s" % self.module_name)
120121
return x
121122

122-
def _invoke(self, input_file, output_file, passes):
123+
def _cmdline(self, input_file, passes, output_file='-'):
123124
base_args = self.base_args
124-
base_args.extend([
125-
input_file,
126-
'-o', output_file])
125+
base_args.extend([input_file, '-o', output_file])
127126
base_args.extend(self.extra_args)
128127
base_args.extend(passes)
129-
return br_call(base_args)
128+
return base_args
129+
130+
def _invoke(self, input_file, passes, output_filename):
131+
cmdline = self._cmdline(input_file, passes, output_filename)
132+
return br_call(cmdline)
133+
134+
def invoke_with_passlist(self, passes, output_filename):
135+
return self._invoke(self.input_file, passes, output_filename)
130136

131-
def invoke_with_passlist(self, output_filename, passes):
132-
return self._invoke(self.input_file, output_filename, passes)
137+
def cmdline_with_passlist(self, passes):
138+
return self._cmdline(self.input_file, passes)
133139

134140

135141
def get_silopt_invoker(args):

utils/bug_reducer/bug_reducer/opt_bug_reducer.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def run_test(self, prefix, suffix):
2525
print("Checking to see if '%s' compiles correctly" % suffix_joined)
2626

2727
result = self.invoker.invoke_with_passlist(
28-
self.invoker.get_suffixed_filename(suffix_hash),
29-
suffix)
28+
suffix,
29+
self.invoker.get_suffixed_filename(suffix_hash))
3030

3131
# Found a miscompile! Keep the suffix
3232
if result != 0:
@@ -51,8 +51,8 @@ def run_test(self, prefix, suffix):
5151
# passes.
5252
prefix_path = self.invoker.get_suffixed_filename(prefix_hash)
5353
result = self.invoker.invoke_with_passlist(
54-
prefix_path,
55-
prefix)
54+
prefix,
55+
prefix_path)
5656
if result != 0:
5757
print("Prefix maintains the predicate by itself. Returning keep "
5858
"prefix")
@@ -71,8 +71,8 @@ def run_test(self, prefix, suffix):
7171
print("Checking to see if '%s' compiles correctly after the '%s' "
7272
"passes" % (suffix_joined, prefix_joined))
7373
result = self.invoker.invoke_with_passlist(
74-
self.invoker.get_suffixed_filename(suffix_hash),
75-
suffix)
74+
suffix,
75+
self.invoker.get_suffixed_filename(suffix_hash))
7676

7777
# If we failed at this point, then the prefix is our new
7878
# baseline. Return keep suffix.
@@ -117,7 +117,7 @@ def pass_bug_reducer(args):
117117

118118
# Make sure that the base case /does/ crash.
119119
filename = sil_opt_invoker.get_suffixed_filename('base_case')
120-
result = sil_opt_invoker.invoke_with_passlist(filename, passes)
120+
result = sil_opt_invoker.invoke_with_passlist(passes, filename)
121121
# If we succeed, there is no further work to do.
122122
if result == 0:
123123
print("Success with PassList: %s" % (' '.join(passes)))
@@ -127,7 +127,11 @@ def pass_bug_reducer(args):
127127
r = ReduceMiscompilingPasses(passes, sil_opt_invoker)
128128
if not r.reduce_list():
129129
print("Failed to find miscompiling pass list!")
130-
print("Found miscompiling passes: %s" % (' '.join(r.target_list)))
130+
cmdline = sil_opt_invoker.cmdline_with_passlist(r.target_list)
131+
print("*** Found miscompiling passes!")
132+
print("*** Final File: %s" % sil_opt_invoker.input_file)
133+
print("*** Final Passes: %s" % (' '.join(r.target_list)))
134+
print("*** Repro command line: %s" % (' '.join(cmdline)))
131135

132136

133137
def add_parser_arguments(parser):

utils/bug_reducer/bug_reducer/random_bug_finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def random_bug_finder(args):
3838
print("Running round %i/%i" % (count, max_count))
3939
random.shuffle(passes)
4040
filename = sil_opt_invoker.get_suffixed_filename(str(count))
41-
result = sil_opt_invoker.invoke_with_passlist(filename, passes)
41+
result = sil_opt_invoker.invoke_with_passlist(passes, filename)
4242
if result == 0:
4343
print("Success with PassList: %s" % (' '.join(passes)))
4444
else:

utils/bug_reducer/tests/test_optbugreducer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ def test_basic(self):
9696
]
9797
args.extend(self.passes)
9898
output = subprocess.check_output(args).split("\n")
99-
success_message = 'Found miscompiling passes: --bug-reducer-tester'
100-
self.assertTrue(success_message in output)
99+
success_messages = ['*** Found miscompiling passes!',
100+
'*** Final Passes: --bug-reducer-tester']
101+
for msg in success_messages:
102+
self.assertTrue(msg in output)
101103

102104
if __name__ == '__main__':
103105
unittest.main()

0 commit comments

Comments
 (0)