@@ -32,7 +32,9 @@ use crate::ir::derive::{
32
32
} ;
33
33
use crate :: ir:: dot;
34
34
use crate :: ir:: enum_ty:: { Enum , EnumVariant , EnumVariantValue } ;
35
- use crate :: ir:: function:: { Abi , Function , FunctionKind , FunctionSig , Linkage } ;
35
+ use crate :: ir:: function:: {
36
+ Abi , ClangAbi , Function , FunctionKind , FunctionSig , Linkage ,
37
+ } ;
36
38
use crate :: ir:: int:: IntKind ;
37
39
use crate :: ir:: item:: { IsOpaque , Item , ItemCanonicalName , ItemCanonicalPath } ;
38
40
use crate :: ir:: item_kind:: ItemKind ;
@@ -2475,9 +2477,13 @@ impl MethodCodegen for Method {
2475
2477
_ => panic ! ( "How in the world?" ) ,
2476
2478
} ;
2477
2479
2478
- let supported_abi = match signature. abi ( ) {
2479
- Abi :: ThisCall => ctx. options ( ) . rust_features ( ) . thiscall_abi ,
2480
- Abi :: Vectorcall => ctx. options ( ) . rust_features ( ) . vectorcall_abi ,
2480
+ let supported_abi = match signature. abi ( ctx, Some ( & * name) ) {
2481
+ ClangAbi :: Known ( Abi :: ThisCall ) => {
2482
+ ctx. options ( ) . rust_features ( ) . thiscall_abi
2483
+ }
2484
+ ClangAbi :: Known ( Abi :: Vectorcall ) => {
2485
+ ctx. options ( ) . rust_features ( ) . vectorcall_abi
2486
+ }
2481
2487
_ => true ,
2482
2488
} ;
2483
2489
@@ -3791,7 +3797,8 @@ impl TryToRustTy for Type {
3791
3797
// sizeof(NonZero<_>) optimization with opaque blobs (because
3792
3798
// they aren't NonZero), so don't *ever* use an or_opaque
3793
3799
// variant here.
3794
- let ty = fs. try_to_rust_ty ( ctx, & ( ) ) ?;
3800
+ let ty = fs
3801
+ . try_to_rust_ty ( ctx, & self . name ( ) . map ( |x| x. to_string ( ) ) ) ?;
3795
3802
3796
3803
let prefix = ctx. trait_prefix ( ) ;
3797
3804
Ok ( quote ! {
@@ -3981,24 +3988,26 @@ impl TryToRustTy for TemplateInstantiation {
3981
3988
}
3982
3989
3983
3990
impl TryToRustTy for FunctionSig {
3984
- type Extra = ( ) ;
3991
+ type Extra = Option < String > ;
3985
3992
3986
3993
fn try_to_rust_ty (
3987
3994
& self ,
3988
3995
ctx : & BindgenContext ,
3989
- _ : & ( ) ,
3996
+ name : & Option < String > ,
3990
3997
) -> error:: Result < proc_macro2:: TokenStream > {
3991
3998
// TODO: we might want to consider ignoring the reference return value.
3992
3999
let ret = utils:: fnsig_return_ty ( ctx, self ) ;
3993
4000
let arguments = utils:: fnsig_arguments ( ctx, self ) ;
3994
- let abi = self . abi ( ) ;
4001
+ let abi = self . abi ( ctx , name . as_deref ( ) ) ;
3995
4002
3996
4003
match abi {
3997
- Abi :: ThisCall if !ctx. options ( ) . rust_features ( ) . thiscall_abi => {
4004
+ ClangAbi :: Known ( Abi :: ThisCall )
4005
+ if !ctx. options ( ) . rust_features ( ) . thiscall_abi =>
4006
+ {
3998
4007
warn ! ( "Skipping function with thiscall ABI that isn't supported by the configured Rust target" ) ;
3999
4008
Ok ( proc_macro2:: TokenStream :: new ( ) )
4000
4009
}
4001
- Abi :: Vectorcall
4010
+ ClangAbi :: Known ( Abi :: Vectorcall )
4002
4011
if !ctx. options ( ) . rust_features ( ) . vectorcall_abi =>
4003
4012
{
4004
4013
warn ! ( "Skipping function with vectorcall ABI that isn't supported by the configured Rust target" ) ;
@@ -4102,22 +4111,24 @@ impl CodeGenerator for Function {
4102
4111
attributes. push ( attributes:: doc ( comment) ) ;
4103
4112
}
4104
4113
4105
- let abi = match signature. abi ( ) {
4106
- Abi :: ThisCall if !ctx. options ( ) . rust_features ( ) . thiscall_abi => {
4114
+ let abi = match signature. abi ( ctx, Some ( name) ) {
4115
+ ClangAbi :: Known ( Abi :: ThisCall )
4116
+ if !ctx. options ( ) . rust_features ( ) . thiscall_abi =>
4117
+ {
4107
4118
warn ! ( "Skipping function with thiscall ABI that isn't supported by the configured Rust target" ) ;
4108
4119
return None ;
4109
4120
}
4110
- Abi :: Vectorcall
4121
+ ClangAbi :: Known ( Abi :: Vectorcall )
4111
4122
if !ctx. options ( ) . rust_features ( ) . vectorcall_abi =>
4112
4123
{
4113
4124
warn ! ( "Skipping function with vectorcall ABI that isn't supported by the configured Rust target" ) ;
4114
4125
return None ;
4115
4126
}
4116
- Abi :: Win64 if signature. is_variadic ( ) => {
4127
+ ClangAbi :: Known ( Abi :: Win64 ) if signature. is_variadic ( ) => {
4117
4128
warn ! ( "Skipping variadic function with Win64 ABI that isn't supported" ) ;
4118
4129
return None ;
4119
4130
}
4120
- Abi :: Unknown ( unknown_abi) => {
4131
+ ClangAbi :: Unknown ( unknown_abi) => {
4121
4132
panic ! (
4122
4133
"Invalid or unknown abi {:?} for function {:?} ({:?})" ,
4123
4134
unknown_abi, canonical_name, self
@@ -4515,7 +4526,7 @@ pub(crate) fn codegen(
4515
4526
pub mod utils {
4516
4527
use super :: { error, ToRustTyOrOpaque } ;
4517
4528
use crate :: ir:: context:: BindgenContext ;
4518
- use crate :: ir:: function:: { Abi , FunctionSig } ;
4529
+ use crate :: ir:: function:: { Abi , ClangAbi , FunctionSig } ;
4519
4530
use crate :: ir:: item:: { Item , ItemCanonicalPath } ;
4520
4531
use crate :: ir:: ty:: TypeKind ;
4521
4532
use proc_macro2;
@@ -4976,10 +4987,10 @@ pub mod utils {
4976
4987
// Returns true if `canonical_name` will end up as `mangled_name` at the
4977
4988
// machine code level, i.e. after LLVM has applied any target specific
4978
4989
// mangling.
4979
- pub fn names_will_be_identical_after_mangling (
4990
+ pub ( crate ) fn names_will_be_identical_after_mangling (
4980
4991
canonical_name : & str ,
4981
4992
mangled_name : & str ,
4982
- call_conv : Option < Abi > ,
4993
+ call_conv : Option < ClangAbi > ,
4983
4994
) -> bool {
4984
4995
// If the mangled name and the canonical name are the same then no
4985
4996
// mangling can have happened between the two versions.
@@ -4992,13 +5003,13 @@ pub mod utils {
4992
5003
let mangled_name = mangled_name. as_bytes ( ) ;
4993
5004
4994
5005
let ( mangling_prefix, expect_suffix) = match call_conv {
4995
- Some ( Abi :: C ) |
5006
+ Some ( ClangAbi :: Known ( Abi :: C ) ) |
4996
5007
// None is the case for global variables
4997
5008
None => {
4998
5009
( b'_' , false )
4999
5010
}
5000
- Some ( Abi :: Stdcall ) => ( b'_' , true ) ,
5001
- Some ( Abi :: Fastcall ) => ( b'@' , true ) ,
5011
+ Some ( ClangAbi :: Known ( Abi :: Stdcall ) ) => ( b'_' , true ) ,
5012
+ Some ( ClangAbi :: Known ( Abi :: Fastcall ) ) => ( b'@' , true ) ,
5002
5013
5003
5014
// This is something we don't recognize, stay on the safe side
5004
5015
// by emitting the `#[link_name]` attribute
0 commit comments