diff --git a/tests/output/c-backend/fallthrough.c b/tests/output/c-backend/fallthrough.c index 5072c66..06b7a44 100644 --- a/tests/output/c-backend/fallthrough.c +++ b/tests/output/c-backend/fallthrough.c @@ -10,12 +10,12 @@ int func(int arg) #line 9 "/home/novikov/work/cif/tests/input/c-backend/fallthrough.c" case 2:; ret += 20; - goto ldv_1320; + goto ldv_1; default:; - goto ldv_1320; + goto ldv_1; } #line 16 "/home/novikov/work/cif/tests/input/c-backend/fallthrough.c" - ldv_1320:; + ldv_1:; #line 16 "/home/novikov/work/cif/tests/input/c-backend/fallthrough.c" return ret; } diff --git a/tests/test_c_backend.py b/tests/test_c_backend.py index ec6fe55..0075156 100644 --- a/tests/test_c_backend.py +++ b/tests/test_c_backend.py @@ -138,6 +138,7 @@ def test_may_alias(self): def test_fallthrough(self): self.cif.run(cif_input='input/c-backend/fallthrough.c', stage='C-backend', cif_output='work/fallthrough.c') + self.replace_gotos('work/fallthrough.c') self.compare(output='work/fallthrough.c', expected='output/c-backend/fallthrough.c') def test___func__(self): diff --git a/tests/utils.py b/tests/utils.py index 521c2ef..f533718 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,4 +1,5 @@ import os +import re import subprocess import shutil import unittest @@ -93,6 +94,36 @@ def skip_os_specific_defines(self, output): if not line.startswith('/usr/include/stdc-predef.h'): fp.write(line) + def replace_gotos(self, output): + self.check_cif_status() + + with open(output) as fp: + lines = fp.readlines() + + goto_ids = dict() + counter = 1 + for line in lines: + m = re.search(r"goto ldv_(\d*);", line) + + if not m: + continue + + old_id = m.group(1) + + if old_id not in goto_ids: + goto_ids[old_id] = str(counter) + counter += 1 + + with open(output, 'w') as fp: + for line in lines: + m = re.search(r"ldv_(\d*)[;:]", line) + + if m: + old_id = m.group(1) + line = line.replace(old_id, goto_ids[old_id]) + + fp.write(line) + def make_relpath(self, output): with open(output) as fp: lines = fp.readlines()