File tree Expand file tree Collapse file tree 2 files changed +70
-14
lines changed
tests/run-make/extern-fn-explicit-align Expand file tree Collapse file tree 2 files changed +70
-14
lines changed Original file line number Diff line number Diff line change 3
3
#include <stdint.h>
4
4
#include <string.h>
5
5
6
+ struct BoolAndU32
7
+ {
8
+ bool a ;
9
+ uint32_t b ;
10
+ };
11
+
6
12
#ifdef _MSC_VER
7
13
__declspec(align (16 ))
8
14
struct TwoU64s
@@ -18,12 +24,28 @@ struct __attribute__((aligned(16))) TwoU64s
18
24
};
19
25
#endif
20
26
21
- struct BoolAndU32
27
+ struct WrappedU64s
22
28
{
23
- bool a ;
24
- uint32_t b ;
29
+ struct TwoU64s a ;
25
30
};
26
31
32
+ #ifdef _MSC_VER
33
+ __declspec(align (1 ))
34
+ struct LowerAlign
35
+ {
36
+ uint64_t a ;
37
+ uint64_t b ;
38
+ } ;
39
+ #else
40
+ struct __attribute__((aligned (1 ))) LowerAlign
41
+ {
42
+ uint64_t a ;
43
+ uint64_t b ;
44
+ };
45
+ #endif
46
+
47
+
48
+
27
49
int32_t many_args (
28
50
void * a ,
29
51
void * b ,
@@ -34,11 +56,27 @@ int32_t many_args(
34
56
void * g ,
35
57
struct TwoU64s h ,
36
58
void * i ,
37
- void * j ,
59
+ struct WrappedU64s j ,
38
60
void * k ,
39
- void * l ,
61
+ struct LowerAlign l ,
40
62
const char * m )
41
63
{
64
+ assert (!a );
65
+ assert (!b );
66
+ assert (!c );
67
+ assert (d == 42 );
68
+ assert (e );
69
+ assert (f .a );
70
+ assert (f .b == 1337 );
71
+ assert (!g );
72
+ assert (h .a == 1 );
73
+ assert (h .b == 2 );
74
+ assert (!i );
75
+ assert (j .a .a == 3 );
76
+ assert (j .a .b == 4 );
77
+ assert (!k );
78
+ assert (l .a == 5 );
79
+ assert (l .b == 6 );
42
80
assert (strcmp (m , "Hello world" ) == 0 );
43
81
return 0 ;
44
82
}
Original file line number Diff line number Diff line change 3
3
use std:: ffi:: { CStr , c_char} ;
4
4
use std:: ptr:: null_mut;
5
5
6
+ #[ derive( Copy , Clone ) ]
7
+ #[ repr( C ) ]
8
+ pub struct BoolAndU32 {
9
+ pub a : bool ,
10
+ pub b : u32 ,
11
+ }
12
+
6
13
#[ derive( Copy , Clone ) ]
7
14
#[ repr( C ) ]
8
15
#[ repr( align( 16 ) ) ]
@@ -11,11 +18,20 @@ pub struct TwoU64s {
11
18
pub b : u64 ,
12
19
}
13
20
21
+ #[ derive( Copy , Clone ) ]
14
22
#[ repr( C ) ]
23
+ pub struct WrappedU64s {
24
+ pub a : TwoU64s
25
+ }
26
+
15
27
#[ derive( Copy , Clone ) ]
16
- pub struct BoolAndU32 {
17
- pub a : bool ,
18
- pub b : u32 ,
28
+ #[ repr( C ) ]
29
+ // Even though requesting align 1 can never change the alignment, it still affects the ABI
30
+ // on some platforms like i686-windows.
31
+ #[ repr( align( 1 ) ) ]
32
+ pub struct LowerAlign {
33
+ pub a : u64 ,
34
+ pub b : u64 ,
19
35
}
20
36
21
37
#[ link( name = "test" , kind = "static" ) ]
@@ -30,33 +46,35 @@ extern "C" {
30
46
g : * mut ( ) ,
31
47
h : TwoU64s ,
32
48
i : * mut ( ) ,
33
- j : * mut ( ) ,
49
+ j : WrappedU64s ,
34
50
k : * mut ( ) ,
35
- l : * mut ( ) ,
51
+ l : LowerAlign ,
36
52
m : * const c_char ,
37
53
) -> i32 ;
38
54
}
39
55
40
56
const STRING : & CStr = unsafe { CStr :: from_bytes_with_nul_unchecked ( b"Hello world\0 " ) } ;
41
57
42
58
fn main ( ) {
59
+ let bool_and_u32 = BoolAndU32 { a : true , b : 1337 } ;
43
60
let two_u64s = TwoU64s { a : 1 , b : 2 } ;
44
- let bool_and_u32 = BoolAndU32 { a : true , b : 3 } ;
61
+ let wrapped = WrappedU64s { a : TwoU64s { a : 3 , b : 4 } } ;
62
+ let lower = LowerAlign { a : 5 , b : 6 } ;
45
63
let string = STRING ;
46
64
unsafe {
47
65
many_args (
48
66
null_mut ( ) ,
49
67
null_mut ( ) ,
50
68
null_mut ( ) ,
51
- 4 ,
69
+ 42 ,
52
70
true ,
53
71
bool_and_u32,
54
72
null_mut ( ) ,
55
73
two_u64s,
56
74
null_mut ( ) ,
75
+ wrapped,
57
76
null_mut ( ) ,
58
- null_mut ( ) ,
59
- null_mut ( ) ,
77
+ lower,
60
78
string. as_ptr ( ) ,
61
79
) ;
62
80
}
You can’t perform that action at this time.
0 commit comments