MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / verify_global_values

Method verify_global_values

cranelift/codegen/src/verifier/mod.rs:331–418  ·  view source on GitHub ↗

Check for: - cycles in the global value declarations. - use of 'vmctx' when no special parameter declares it.

(&self, errors: &mut VerifierErrors)

Source from the content-addressed store, hash-verified

329 // - cycles in the global value declarations.
330 // - use of 'vmctx' when no special parameter declares it.
331 fn verify_global_values(&self, errors: &mut VerifierErrors) -> VerifierStepResult {
332 let mut cycle_seen = false;
333 let mut seen = SparseSet::new();
334
335 'gvs: for gv in self.func.global_values.keys() {
336 seen.clear();
337 seen.insert(gv);
338
339 let mut cur = gv;
340 loop {
341 match self.func.global_values[cur] {
342 ir::GlobalValueData::Load { base, .. }
343 | ir::GlobalValueData::IAddImm { base, .. } => {
344 if seen.insert(base).is_some() {
345 if !cycle_seen {
346 errors.report((
347 gv,
348 format!("global value cycle: {}", DisplayList(seen.as_slice())),
349 ));
350 // ensures we don't report the cycle multiple times
351 cycle_seen = true;
352 }
353 continue 'gvs;
354 }
355
356 cur = base;
357 }
358 _ => break,
359 }
360 }
361
362 match self.func.global_values[gv] {
363 ir::GlobalValueData::VMContext { .. } => {
364 if self
365 .func
366 .special_param(ir::ArgumentPurpose::VMContext)
367 .is_none()
368 {
369 errors.report((gv, format!("undeclared vmctx reference {gv}")));
370 }
371 }
372 ir::GlobalValueData::IAddImm {
373 base, global_type, ..
374 } => {
375 if !global_type.is_int() {
376 errors.report((
377 gv,
378 format!("iadd_imm global value with non-int type {global_type}"),
379 ));
380 } else if let Some(isa) = self.isa {
381 let base_type = self.func.global_values[base].global_type(isa);
382 if global_type != base_type {
383 errors.report((
384 gv,
385 format!(
386 "iadd_imm type {global_type} differs from operand type {base_type}"
387 ),
388 ));

Callers 1

runMethod · 0.80

Calls 14

OkFunction · 0.85
special_paramMethod · 0.80
global_typeMethod · 0.80
newFunction · 0.50
keysMethod · 0.45
clearMethod · 0.45
insertMethod · 0.45
is_someMethod · 0.45
reportMethod · 0.45
is_noneMethod · 0.45
is_intMethod · 0.45
pointer_typeMethod · 0.45

Tested by

no test coverage detected