From eeb1e141ba36b5470c9ac5bc2d433b7936f241af Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 24 May 2020 16:53:27 +0200 Subject: [PATCH] Add some assertions to cranelift_frontend --- cranelift/frontend/src/frontend.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cranelift/frontend/src/frontend.rs b/cranelift/frontend/src/frontend.rs index bfc0fd2329..b45166b383 100644 --- a/cranelift/frontend/src/frontend.rs +++ b/cranelift/frontend/src/frontend.rs @@ -272,6 +272,12 @@ impl<'a> FunctionBuilder<'a> { /// In order to use a variable in a `use_var`, you need to declare its type with this method. pub fn declare_var(&mut self, var: Variable, ty: Type) { + debug_assert_eq!( + self.func_ctx.types[var], + types::INVALID, + "variable {:?} is declared twice", + var + ); self.func_ctx.types[var] = ty; } @@ -285,6 +291,12 @@ impl<'a> FunctionBuilder<'a> { var ) }); + debug_assert_ne!( + ty, + types::INVALID, + "variable {:?} is used but its type has not been declared", + var + ); self.func_ctx .ssa .use_var(self.func, var, ty, self.position.unwrap())