@@ -1405,6 +1405,20 @@ def wasm_has_duplicate_tags(wasm):
1405
1405
return binary .count (b'jstag' ) >= 2 or binary .count (b'wasmtag' ) >= 2
1406
1406
1407
1407
1408
+ # Detect whether there is a trap reported before an export call in the output.
1409
+ def traps_in_instantiation (output ):
1410
+ trap_index = output .find (TRAP_PREFIX )
1411
+ if trap_index == - 1 :
1412
+ # In "fixed" output, traps are replaced with *exception*.
1413
+ trap_index = output .find ('*exception*' )
1414
+ if trap_index == - 1 :
1415
+ return False
1416
+ call_index = output .find (FUZZ_EXEC_CALL_PREFIX )
1417
+ if call_index == - 1 :
1418
+ return True
1419
+ return trap_index < call_index
1420
+
1421
+
1408
1422
# Tests wasm-merge
1409
1423
class Merge (TestCaseHandler ):
1410
1424
frequency = 0.15
@@ -1455,7 +1469,7 @@ def handle(self, wasm):
1455
1469
merged = abspath ('merged.wasm' )
1456
1470
run ([in_bin ('wasm-merge' ), wasm , 'first' ,
1457
1471
abspath ('second.wasm' ), 'second' , '-o' , merged ,
1458
- '--skip-export-conflicts' ] + FEATURE_OPTS + [ '-all' ])
1472
+ '--skip-export-conflicts' , '-all' ])
1459
1473
1460
1474
if wasm_has_duplicate_tags (merged ):
1461
1475
note_ignored_vm_run ('dupe_tags' )
@@ -1464,14 +1478,32 @@ def handle(self, wasm):
1464
1478
# sometimes also optimize the merged module
1465
1479
if random .random () < 0.5 :
1466
1480
opts = get_random_opts ()
1467
- run ([in_bin ('wasm-opt' ), merged , '-o' , merged , '-all' ] + FEATURE_OPTS + opts )
1481
+ run ([in_bin ('wasm-opt' ), merged , '-o' , merged , '-all' ] + opts )
1468
1482
1469
1483
# verify that merging in the second module did not alter the output.
1470
1484
output = run_bynterp (wasm , ['--fuzz-exec-before' , '-all' ])
1471
1485
output = fix_output (output )
1486
+ second_output = run_bynterp (second_wasm , ['--fuzz-exec-before' , '-all' ])
1487
+ second_output = fix_output (second_output )
1472
1488
merged_output = run_bynterp (merged , ['--fuzz-exec-before' , '-all' ])
1473
1489
merged_output = fix_output (merged_output )
1474
1490
1491
+ # If the second module traps in instantiation, then the merged module
1492
+ # must do so as well, regardless of what the first module does. (In
1493
+ # contrast, if the first module traps in instantiation, then the normal
1494
+ # checks below will ensure the merged module does as well.)
1495
+ if traps_in_instantiation (second_output ) and \
1496
+ not traps_in_instantiation (output ):
1497
+ # The merged module should also trap in instantiation, but the
1498
+ # exports will not be called, so there's nothing else to compare.
1499
+ if not traps_in_instantiation (merged_output ):
1500
+ raise Exception ('expected merged module to trap during ' +
1501
+ 'instantiation because second module traps ' +
1502
+ 'during instantiation' )
1503
+ compare (merged_output , second_output , 'Merge: second module traps' +
1504
+ ' in instantiation' )
1505
+ return
1506
+
1475
1507
# a complication is that the second module's exports are appended, so we
1476
1508
# have extra output. to handle that, just prune the tail, so that we
1477
1509
# only compare the original exports from the first module.
0 commit comments