summaryrefslogtreecommitdiffstats
path: root/third_party/rust/wasmparser/tests/big-module.rs
blob: d5cf37f4a47b070168bc858c48c2220bc7fc95d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use wasm_encoder::*;
#[test]
fn big_type_indices() {
    const N: u32 = 100_000;
    let mut module = Module::new();
    let mut types = TypeSection::new();
    for _ in 0..N {
        types.function([], []);
    }
    module.section(&types);
    let mut funcs = FunctionSection::new();
    funcs.function(N - 1);
    module.section(&funcs);

    let mut elems = ElementSection::new();
    elems.declared(RefType::FUNCREF, Elements::Functions(&[0]));
    module.section(&elems);

    let mut code = CodeSection::new();
    let mut body = Function::new([]);
    body.instruction(&Instruction::RefFunc(0));
    body.instruction(&Instruction::Drop);
    body.instruction(&Instruction::End);
    code.function(&body);
    module.section(&code);

    let wasm = module.finish();

    wasmparser::Validator::default()
        .validate_all(&wasm)
        .unwrap();
}