@@ -1527,13 +1527,16 @@ impl CodeGenerator for CompInfo {
1527
1527
} ) ;
1528
1528
}
1529
1529
1530
+ let mut explicit_align = None ;
1530
1531
if is_opaque {
1531
1532
// Opaque item should not have generated methods, fields.
1532
1533
debug_assert ! ( fields. is_empty( ) ) ;
1533
1534
debug_assert ! ( methods. is_empty( ) ) ;
1534
1535
1535
1536
match layout {
1536
1537
Some ( l) => {
1538
+ explicit_align = Some ( l. align ) ;
1539
+
1537
1540
let ty = helpers:: blob ( l) ;
1538
1541
fields. push ( quote ! {
1539
1542
pub _bindgen_opaque_blob: #ty ,
@@ -1555,6 +1558,7 @@ impl CodeGenerator for CompInfo {
1555
1558
if layout. align == 1 {
1556
1559
packed = true ;
1557
1560
} else {
1561
+ explicit_align = Some ( layout. align ) ;
1558
1562
let ty = helpers:: blob ( Layout :: new ( 0 , layout. align ) ) ;
1559
1563
fields. push ( quote ! {
1560
1564
pub __bindgen_align: #ty ,
@@ -1637,6 +1641,18 @@ impl CodeGenerator for CompInfo {
1637
1641
attributes. push ( attributes:: repr ( "C" ) ) ;
1638
1642
}
1639
1643
1644
+ if ctx. options ( ) . rust_features ( ) . repr_align {
1645
+ if let Some ( explicit) = explicit_align {
1646
+ // Ensure that the struct has the correct alignment even in
1647
+ // presence of alignas.
1648
+ let explicit = helpers:: ast_ty:: int_expr ( explicit as i64 ) ;
1649
+ attributes. push ( quote ! {
1650
+ #[ repr( align( #explicit) ) ]
1651
+ } ) ;
1652
+ }
1653
+ }
1654
+
1655
+
1640
1656
let mut derives = vec ! [ ] ;
1641
1657
if item. can_derive_debug ( ctx) {
1642
1658
derives. push ( "Debug" ) ;
@@ -1655,7 +1671,7 @@ impl CodeGenerator for CompInfo {
1655
1671
if item. can_derive_copy ( ctx) && !item. annotations ( ) . disallow_copy ( ) {
1656
1672
derives. push ( "Copy" ) ;
1657
1673
1658
- if ctx. options ( ) . rust_features ( ) . builtin_clone_impls ( ) ||
1674
+ if ctx. options ( ) . rust_features ( ) . builtin_clone_impls ||
1659
1675
used_template_params. is_some ( )
1660
1676
{
1661
1677
// FIXME: This requires extra logic if you have a big array in a
@@ -1996,7 +2012,7 @@ impl MethodCodegen for Method {
1996
2012
_ => panic ! ( "How in the world?" ) ,
1997
2013
} ;
1998
2014
1999
- if let ( Abi :: ThisCall , false ) = ( signature. abi ( ) , ctx. options ( ) . rust_features ( ) . thiscall_abi ( ) ) {
2015
+ if let ( Abi :: ThisCall , false ) = ( signature. abi ( ) , ctx. options ( ) . rust_features ( ) . thiscall_abi ) {
2000
2016
return ;
2001
2017
}
2002
2018
@@ -3167,7 +3183,7 @@ impl TryToRustTy for FunctionSig {
3167
3183
let abi = self . abi ( ) ;
3168
3184
3169
3185
match abi {
3170
- Abi :: ThisCall if !ctx. options ( ) . rust_features ( ) . thiscall_abi ( ) => {
3186
+ Abi :: ThisCall if !ctx. options ( ) . rust_features ( ) . thiscall_abi => {
3171
3187
warn ! ( "Skipping function with thiscall ABI that isn't supported by the configured Rust target" ) ;
3172
3188
Ok ( quote:: Tokens :: new ( ) )
3173
3189
}
@@ -3264,7 +3280,7 @@ impl CodeGenerator for Function {
3264
3280
}
3265
3281
3266
3282
let abi = match signature. abi ( ) {
3267
- Abi :: ThisCall if !ctx. options ( ) . rust_features ( ) . thiscall_abi ( ) => {
3283
+ Abi :: ThisCall if !ctx. options ( ) . rust_features ( ) . thiscall_abi => {
3268
3284
warn ! ( "Skipping function with thiscall ABI that isn't supported by the configured Rust target" ) ;
3269
3285
return ;
3270
3286
}
0 commit comments