Skip to content

Commit

Permalink
fix: add noinline to mstore builtin (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Aug 8, 2024
1 parent 352d558 commit 9eb9614
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
23 changes: 20 additions & 3 deletions crates/revmc/src/compiler/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ type SwitchTargets<B> = Vec<(u64, <B as BackendTypes>::BasicBlock)>;

#[derive(Clone, Copy, PartialEq, Eq)]
enum ResumeKind {
/// Use `indirectbr`.
Blocks,
/// Use a switch over `0..N`.
Indexes,
}

Expand Down Expand Up @@ -486,7 +488,7 @@ impl<'a, B: Backend> FunctionCx<'a, B> {
ensure!(is_eof_enabled, "EOF bytecode in non-EOF spec");
}

// self.call_printf(format_printf!("{}\n", data.to_op_in(self.bytecode)), &[]);
// self.call_printf(format_printf!("{}\n", self.op_block_name("")), &[]);

let branch_to_next_opcode = |this: &mut Self| {
debug_assert!(
Expand Down Expand Up @@ -1692,7 +1694,10 @@ impl<'a, B: Backend> FunctionCx<'a, B> {
#[must_use]
fn call_builtin(&mut self, builtin: Builtin, args: &[B::Value]) -> Option<B::Value> {
let function = self.builtin_function(builtin);
// self.call_printf(format_printf!("calling {}\n", builtin.name()), &[]);
// self.call_printf(
// format_printf!("{} - calling {}\n", self.op_block_name(""), builtin.name()),
// &[],
// );
self.bcx.call(function, args)
}

Expand Down Expand Up @@ -1934,8 +1939,20 @@ impl<'a, B: Backend> FunctionCx<'a, B> {
self.build_check_instruction_result(ret);
}

/// Builds:
/// - `Load` => `fn mload(offset: u256, out: ptr, ecx: ptr) -> InstructionResult`
/// - `Store` => `fn mstore(offset: u256, value: u256, ecx: ptr) -> InstructionResult`
/// - `Store8` => `fn mstore(offset: u256, value: u8, ecx: ptr) -> InstructionResult`
fn build_mem_op(&mut self, kind: MemOpKind) {
let is_load = matches!(kind, MemOpKind::Load);
// TODO: If `store` is inlined it can cause segfaults. https://github.com/paradigmxyz/revmc/issues/61
if !is_load {
self.bcx.add_function_attribute(
None,
Attribute::NoInline,
FunctionAttributeLocation::Function,
);
}
let ptr_args = if is_load { &[1, 2][..] } else { &[2][..] };
for &ptr_arg in ptr_args {
for attr in default_attrs::for_ref() {
Expand Down Expand Up @@ -2224,7 +2241,7 @@ impl<'a, B: Backend> FunctionCx<'a, B> {
let prefix = "__revmc_ir_builtin_";
let name = &format!("{prefix}{name}")[..];

// self.call_printf(format_printf!("calling {name}\n"), &[]);
// self.call_printf(format_printf!("{} - calling {name}\n", self.op_block_name("")), &[]);

debug_assert_eq!(args.len(), arg_types.len());
let linkage = revmc_backend::Linkage::Private;
Expand Down
10 changes: 10 additions & 0 deletions crates/revmc/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ tests! {
expected_stack: &[2_U256, 1_U256],
expected_gas: 3 + 3 + 3,
}),
swap2(@raw {
bytecode: &[op::PUSH1, 1, op::PUSH1, 2, op::PUSH1, 3, op::SWAP2],
expected_stack: &[3_U256, 2_U256, 1_U256],
expected_gas: 3 + 3 + 3 + 3,
}),
swap3(@raw {
bytecode: &[op::PUSH1, 1, op::PUSH1, 2, op::PUSH1, 3, op::PUSH1, 4, op::SWAP3],
expected_stack: &[4_U256, 2_U256, 3_U256, 1_U256],
expected_gas: 3 + 3 + 3 + 3 + 3,
}),
swapn(@raw {
bytecode: &eof(&[op::PUSH1, 1, op::PUSH1, 2, op::SWAPN, 0, op::STOP]),
spec_id: SpecId::PRAGUE_EOF,
Expand Down

0 comments on commit 9eb9614

Please sign in to comment.