Browse Source

cranelift: Fix early exit tests

Signed-off-by: Afonso Bordado <afonsobordado@az8.co>
Signed-off-by: Quentin Monnet <quentin@isovalent.com>
Afonso Bordado 2 năm trước cách đây
mục cha
commit
19e5ecaeaa
2 tập tin đã thay đổi với 21 bổ sung2 xóa
  1. 10 2
      src/cranelift.rs
  2. 11 0
      tests/cranelift.rs

+ 10 - 2
src/cranelift.rs

@@ -890,6 +890,14 @@ impl CraneliftCompiler {
                     let ret = bcx.use_var(self.registers[0]);
                     bcx.ins().return_(&[ret]);
                     self.filled_blocks.insert(bcx.current_block().unwrap());
+
+                    // If we have multiple consecutive exit instructions we need to switch blocks.
+                    let next_pc = (insn_ptr + 1) as u32;
+                    let next_block = *self
+                        .insn_blocks
+                        .entry(next_pc)
+                        .or_insert_with(|| bcx.create_block());
+                    self.insn_blocks.insert(next_pc, next_block);
                 }
                 _ => unimplemented!("inst: {:?}", insn),
             }
@@ -932,7 +940,7 @@ impl CraneliftCompiler {
     }
 
     fn reg_load(&mut self, bcx: &mut FunctionBuilder, ty: Type, base: Value, offset: i16) -> Value {
-        // self.insert_bounds_check(bcx, ty, base, offset);
+        self.insert_bounds_check(bcx, ty, base, offset);
 
         let mut flags = MemFlags::new();
         flags.set_endianness(Endianness::Little);
@@ -947,7 +955,7 @@ impl CraneliftCompiler {
         offset: i16,
         val: Value,
     ) {
-        // self.insert_bounds_check(bcx, ty, base, offset);
+        self.insert_bounds_check(bcx, ty, base, offset);
 
         let mut flags = MemFlags::new();
         flags.set_endianness(Endianness::Little);

+ 11 - 0
tests/cranelift.rs

@@ -364,6 +364,17 @@ test_cranelift!(
     0x300000000
 );
 
+test_cranelift!(
+    test_cranelift_early_exit,
+    "
+    mov r0, 3
+    exit
+    mov r0, 4
+    exit
+    ",
+    0x3
+);
+
 test_cranelift!(
     test_cranelift_div64_by_zero_imm,
     "