Skip to content

Commit 5219703

Browse files
cardigan1008bongjunj
authored andcommitted
fix: pass ignored options to run_opt and run_tv
1 parent 4b300c3 commit 5219703

1 file changed

Lines changed: 66 additions & 10 deletions

File tree

tools/tv.py

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,30 @@
3030
parser.add_argument('--cont', action='store_true', help='continue TV even if the first miscompilation is found')
3131

3232
# Placeholder removed as args parsing is moved under __main__
33-
def run_opt(d: Path, timeout: str = '2s', passes: str = 'instcombine', save_result: bool = True, cwd: Path = None):
34-
opt_args = ['timeout', timeout, 'opt', '-S', f'-passes={passes}']
33+
def run_opt(
34+
d: Path,
35+
opt_bin: str,
36+
timeout: str = '2s',
37+
passes: str = 'instcombine',
38+
save_result: bool = True,
39+
):
40+
opt_args = ['timeout', timeout, opt_bin, '-S', f'-passes={passes}']
3541
opt_result = d.with_suffix('.opt.ll') if save_result else Path('/dev/null')
3642
opt_args.extend(['-o', opt_result.absolute().as_posix(), str(d)])
3743
opt_p = sp.run(opt_args)
3844
if opt_p.returncode == 0:
3945
return opt_result if save_result else None
4046
return None
4147

42-
def run_tv(before: Path, after: Path, timeout: str = '2m', no_undef: bool = False, no_poison: bool = False):
43-
tv_args = ['timeout', timeout, 'alive-tv', before.absolute().as_posix(), after.absolute().as_posix()]
48+
def run_tv(
49+
before: Path,
50+
after: Path,
51+
tv_bin: str,
52+
timeout: str = '2m',
53+
no_undef: bool = False,
54+
no_poison: bool = False,
55+
):
56+
tv_args = ['timeout', timeout, tv_bin, before.absolute().as_posix(), after.absolute().as_posix()]
4457
if no_undef:
4558
tv_args.append('--disable-undef-input')
4659
if no_poison:
@@ -74,11 +87,25 @@ def unique_sorted_files(files: list[Path]):
7487

7588
return files
7689

77-
def process_file(target: Path, crash_dir: Path):
78-
opt_result = run_opt(target)
90+
def process_file(
91+
target: Path,
92+
crash_dir: Path,
93+
opt_bin: str,
94+
tv_bin: str,
95+
passes: str,
96+
no_undef: bool,
97+
no_poison: bool,
98+
):
99+
opt_result = run_opt(target, opt_bin=opt_bin, passes=passes)
79100
if not opt_result:
80101
return False
81-
tv_result = run_tv(target, opt_result)
102+
tv_result = run_tv(
103+
target,
104+
opt_result,
105+
tv_bin=tv_bin,
106+
no_undef=no_undef,
107+
no_poison=no_poison,
108+
)
82109
if tv_result == "incorrect":
83110
shutil.copy(opt_result, crash_dir / target.name)
84111

@@ -87,7 +114,18 @@ def process_file(target: Path, crash_dir: Path):
87114
return tv_result == "pass"
88115

89116

90-
def postmortem(covers_dir: Path, crash_dir: Path, jobs: int, cont: bool = False):
117+
def postmortem(
118+
covers_dir: Path,
119+
crash_dir: Path,
120+
jobs: int,
121+
cont: bool = False,
122+
*,
123+
opt_bin: str,
124+
tv_bin: str,
125+
passes: str,
126+
no_undef: bool,
127+
no_poison: bool,
128+
):
91129
files = [d.absolute() for d in covers_dir.iterdir() if d.suffix == '.ll' and 'opt.ll' not in d.name]
92130
files = unique_sorted_files(files)
93131
print(f"Found {len(files)} files to process", file=sys.stderr)
@@ -100,7 +138,15 @@ def postmortem(covers_dir: Path, crash_dir: Path, jobs: int, cont: bool = False)
100138
def worker(file: Path):
101139
if stop_event.is_set(): # Check if stop signal is set
102140
return
103-
passed = process_file(file, crash_dir)
141+
passed = process_file(
142+
file,
143+
crash_dir,
144+
opt_bin=opt_bin,
145+
tv_bin=tv_bin,
146+
passes=passes,
147+
no_undef=no_undef,
148+
no_poison=no_poison,
149+
)
104150
with progress_lock: # Safely update the progress bar
105151
pbar.update(1)
106152
if not passed: # Miscompilation found
@@ -141,7 +187,17 @@ def worker(file: Path):
141187
print('opt: ', args.opt_bin, file=sys.stderr)
142188
print('alive-tv: ', tv_bin, file=sys.stderr)
143189

144-
postmortem(covers_dir, crash_dir, args.jobs, args.cont)
190+
postmortem(
191+
covers_dir,
192+
crash_dir,
193+
args.jobs,
194+
args.cont,
195+
opt_bin=opt_bin,
196+
tv_bin=tv_bin,
197+
passes=args.passes,
198+
no_undef=args.no_undef,
199+
no_poison=args.no_poison,
200+
)
145201

146202
miscompilations = len(list(crash_dir.iterdir()))
147203
if miscompilations > 0:

0 commit comments

Comments
 (0)