Check signature compatibility in declare_function (fixes #427)

This commit is contained in:
bjorn3
2018-07-29 17:58:53 +02:00
committed by Dan Gohman
parent a8ded3a6f1
commit 5389b7784e
2 changed files with 28 additions and 2 deletions

View File

@@ -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)
}