File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
tests/pass/function_calls Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ //@ aux-build: weak_definition_a.rs
2
+
3
+ #![ feature( linkage) ]
4
+
5
+ use weak_definition_a as _;
6
+
7
+ // FIXME move this module to a separate crate once aux-build is allowed
8
+ // This currently depends on the fact that miri skips the codegen check
9
+ // that denies multiple symbols with the same name.
10
+ mod first {
11
+ #[ no_mangle]
12
+ #[ linkage = "weak" ]
13
+ extern "C" fn foo ( ) -> i32 {
14
+ 1
15
+ }
16
+
17
+ #[ no_mangle]
18
+ #[ linkage = "weak" ]
19
+ extern "C" fn bar ( ) -> i32 {
20
+ 2
21
+ }
22
+ }
23
+
24
+ mod second {
25
+ #[ no_mangle]
26
+ extern "C" fn bar ( ) -> i32 {
27
+ 3
28
+ }
29
+ }
30
+
31
+ extern "C" {
32
+ fn foo ( ) -> i32 ;
33
+ fn bar ( ) -> i32 ;
34
+ }
35
+
36
+ fn main ( ) {
37
+ unsafe {
38
+ // If there is no non-weak definition, the weak definition will be used.
39
+ assert_eq ! ( foo( ) , 1 ) ;
40
+ // Non-weak definition takes presedence.
41
+ assert_eq ! ( bar( ) , 3 ) ;
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments