librustc: Make sure to add argument attributes to extern fns from non-local crates.
This commit is contained in:
parent
e4414739a5
commit
589f447299
6 changed files with 109 additions and 25 deletions
8
src/test/run-make/extern-fn-with-union/Makefile
Normal file
8
src/test/run-make/extern-fn-with-union/Makefile
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
-include ../tools.mk
|
||||
|
||||
all:
|
||||
$(CC) -std=c99 test.c -c -o $(TMPDIR)/test.o
|
||||
$(AR) rcs $(TMPDIR)/libtest.a $(TMPDIR)/test.o
|
||||
$(RUSTC) testcrate.rs -L $(TMPDIR)
|
||||
$(RUSTC) test.rs -L $(TMPDIR)
|
||||
$(call RUN,test) || exit 1
|
||||
10
src/test/run-make/extern-fn-with-union/test.c
Normal file
10
src/test/run-make/extern-fn-with-union/test.c
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef union TestUnion {
|
||||
uint64_t bits;
|
||||
} TestUnion;
|
||||
|
||||
uint64_t give_back(TestUnion tu) {
|
||||
return tu.bits;
|
||||
}
|
||||
34
src/test/run-make/extern-fn-with-union/test.rs
Normal file
34
src/test/run-make/extern-fn-with-union/test.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
extern crate testcrate;
|
||||
|
||||
use std::mem;
|
||||
|
||||
#[link(name = "test", kind = "static")]
|
||||
extern {
|
||||
fn give_back(tu: testcrate::TestUnion) -> u64;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let magic: u64 = 0xDEADBEEF;
|
||||
|
||||
// Let's test calling it cross crate
|
||||
let back = unsafe {
|
||||
testcrate::give_back(mem::transmute(magic))
|
||||
};
|
||||
assert_eq!(magic, back);
|
||||
|
||||
// And just within this crate
|
||||
let back = unsafe {
|
||||
give_back(mem::transmute(magic))
|
||||
};
|
||||
assert_eq!(magic, back);
|
||||
}
|
||||
20
src/test/run-make/extern-fn-with-union/testcrate.rs
Normal file
20
src/test/run-make/extern-fn-with-union/testcrate.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![crate_type = "lib"]
|
||||
|
||||
pub struct TestUnion {
|
||||
val: u64
|
||||
}
|
||||
|
||||
#[link(name = "test", kind = "static")]
|
||||
extern {
|
||||
pub fn give_back(tu: TestUnion) -> u64;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue