@@ -1527,13 +1527,16 @@ impl CodeGenerator for CompInfo {
15271527 } ) ;
15281528 }
15291529
1530+ let mut explicit_align = None ;
15301531 if is_opaque {
15311532 // Opaque item should not have generated methods, fields.
15321533 debug_assert ! ( fields. is_empty( ) ) ;
15331534 debug_assert ! ( methods. is_empty( ) ) ;
15341535
15351536 match layout {
15361537 Some ( l) => {
1538+ explicit_align = Some ( l. align ) ;
1539+
15371540 let ty = helpers:: blob ( l) ;
15381541 fields. push ( quote ! {
15391542 pub _bindgen_opaque_blob: #ty ,
@@ -1555,6 +1558,7 @@ impl CodeGenerator for CompInfo {
15551558 if layout. align == 1 {
15561559 packed = true ;
15571560 } else {
1561+ explicit_align = Some ( layout. align ) ;
15581562 let ty = helpers:: blob ( Layout :: new ( 0 , layout. align ) ) ;
15591563 fields. push ( quote ! {
15601564 pub __bindgen_align: #ty ,
@@ -1637,6 +1641,18 @@ impl CodeGenerator for CompInfo {
16371641 attributes. push ( attributes:: repr ( "C" ) ) ;
16381642 }
16391643
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+
16401656 let mut derives = vec ! [ ] ;
16411657 if item. can_derive_debug ( ctx) {
16421658 derives. push ( "Debug" ) ;
@@ -1655,7 +1671,7 @@ impl CodeGenerator for CompInfo {
16551671 if item. can_derive_copy ( ctx) && !item. annotations ( ) . disallow_copy ( ) {
16561672 derives. push ( "Copy" ) ;
16571673
1658- if ctx. options ( ) . rust_features ( ) . builtin_clone_impls ( ) ||
1674+ if ctx. options ( ) . rust_features ( ) . builtin_clone_impls ||
16591675 used_template_params. is_some ( )
16601676 {
16611677 // FIXME: This requires extra logic if you have a big array in a
@@ -1996,7 +2012,7 @@ impl MethodCodegen for Method {
19962012 _ => panic ! ( "How in the world?" ) ,
19972013 } ;
19982014
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 ) {
20002016 return ;
20012017 }
20022018
@@ -3167,7 +3183,7 @@ impl TryToRustTy for FunctionSig {
31673183 let abi = self . abi ( ) ;
31683184
31693185 match abi {
3170- Abi :: ThisCall if !ctx. options ( ) . rust_features ( ) . thiscall_abi ( ) => {
3186+ Abi :: ThisCall if !ctx. options ( ) . rust_features ( ) . thiscall_abi => {
31713187 warn ! ( "Skipping function with thiscall ABI that isn't supported by the configured Rust target" ) ;
31723188 Ok ( quote:: Tokens :: new ( ) )
31733189 }
@@ -3264,7 +3280,7 @@ impl CodeGenerator for Function {
32643280 }
32653281
32663282 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 => {
32683284 warn ! ( "Skipping function with thiscall ABI that isn't supported by the configured Rust target" ) ;
32693285 return ;
32703286 }
0 commit comments