Check signature compatibility in declare_function (fixes #427)
This commit is contained in:
22
cranelift/tests/moduletests.rs
Normal file
22
cranelift/tests/moduletests.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
extern crate cranelift_codegen;
|
||||
extern crate cranelift_module;
|
||||
extern crate cranelift_simplejit;
|
||||
|
||||
use cranelift_codegen::settings::*;
|
||||
use cranelift_codegen::ir::*;
|
||||
use cranelift_module::*;
|
||||
use cranelift_simplejit::*;
|
||||
|
||||
#[test]
|
||||
fn error_on_incompatible_sig_in_declare_function() {
|
||||
let mut module: Module<SimpleJITBackend> = Module::new(SimpleJITBuilder::new());
|
||||
let mut sig = Signature {
|
||||
params: vec![AbiParam::new(types::I64)],
|
||||
returns: vec![],
|
||||
call_conv: CallConv::SystemV,
|
||||
argument_bytes: None,
|
||||
};
|
||||
module.declare_function("abc", Linkage::Local, &sig).unwrap();
|
||||
sig.params[0] = AbiParam::new(types::I32);
|
||||
module.declare_function("abc", Linkage::Local, &sig).err().unwrap(); // Make sure this is an error
|
||||
}
|
||||
@@ -159,8 +159,12 @@ impl<B> ModuleFunction<B>
|
||||
where
|
||||
B: Backend,
|
||||
{
|
||||
fn merge(&mut self, linkage: Linkage) {
|
||||
fn merge(&mut self, linkage: Linkage, sig: &ir::Signature) -> Result<(), ModuleError> {
|
||||
self.decl.linkage = Linkage::merge(self.decl.linkage, linkage);
|
||||
if &self.decl.signature != sig {
|
||||
return Err(ModuleError::IncompatibleDeclaration(self.decl.name.clone()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,7 +361,7 @@ where
|
||||
Occupied(entry) => match *entry.get() {
|
||||
FuncOrDataId::Func(id) => {
|
||||
let existing = &mut self.contents.functions[id];
|
||||
existing.merge(linkage);
|
||||
existing.merge(linkage, signature)?;
|
||||
self.backend.declare_function(name, existing.decl.linkage);
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user