Skip to content

Commit 03c775c

Browse files
committed
Auto merge of #88482 - athei:add-import-test, r=the8472
Add regression test for a spurious import This PR adds a test that verifies that the bug described in the linked issue does not creep back into the code. In essence it checks that compiling some specific code (that uses 128 bit multiplication) with a specific set of compiler options does not lead to a spurious import of a panic function. I noticed that other wasm tests use `# only-wasm32-bare` in their `Makefile`. This will skip the test for me. I did not find out how to run this test locally. Maybe someone can help. closes #78744 r? `@jyn514`
2 parents b7404c8 + 14cbb4b commit 03c775c

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
# only-wasm32-bare
4+
5+
all:
6+
$(RUSTC) main.rs -C overflow-checks=yes -C panic=abort -C lto -C opt-level=z --target wasm32-unknown-unknown
7+
$(NODE) verify.js $(TMPDIR)/main.wasm
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![crate_type = "cdylib"]
2+
#![no_std]
3+
4+
#[panic_handler]
5+
fn my_panic(_info: &core::panic::PanicInfo) -> ! {
6+
loop {}
7+
}
8+
9+
#[no_mangle]
10+
pub fn multer(a: i128, b: i128) -> i128 {
11+
// Trigger usage of the __multi3 compiler intrinsic which then leads to an imported
12+
// panic function in case of a bug. We verify that no imports exist in our verifier.
13+
a * b
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const fs = require('fs');
2+
const process = require('process');
3+
const assert = require('assert');
4+
const buffer = fs.readFileSync(process.argv[2]);
5+
6+
let m = new WebAssembly.Module(buffer);
7+
let imports = WebAssembly.Module.imports(m);
8+
console.log('imports', imports);
9+
assert.strictEqual(imports.length, 0);

0 commit comments

Comments
 (0)