@@ -15,10 +15,10 @@ use crate::kani_middle;
1515use cbmc:: goto_program:: { Expr , Location , Stmt , Symbol , Type } ;
1616use cbmc:: { InternString , InternedString } ;
1717use lazy_static:: lazy_static;
18- use rustc_middle:: ty:: Instance ;
1918use rustc_smir:: rustc_internal;
2019use rustc_target:: abi:: call:: Conv ;
21- use stable_mir:: mir:: mono:: Instance as InstanceStable ;
20+ use stable_mir:: mir:: mono:: Instance ;
21+ use stable_mir:: CrateDef ;
2222use tracing:: { debug, trace} ;
2323
2424lazy_static ! {
@@ -46,15 +46,16 @@ impl<'tcx> GotocCtx<'tcx> {
4646 ///
4747 /// For other foreign items, we declare a shim and add to the list of foreign shims to be
4848 /// handled later.
49- pub fn codegen_foreign_fn ( & mut self , instance : InstanceStable ) -> & Symbol {
49+ pub fn codegen_foreign_fn ( & mut self , instance : Instance ) -> & Symbol {
5050 debug ! ( ?instance, "codegen_foreign_function" ) ;
51- let instance = rustc_internal:: internal ( instance) ;
52- let fn_name = self . symbol_name ( instance) . intern ( ) ;
51+ let internal_instance = rustc_internal:: internal ( instance) ;
52+ let fn_name = self . symbol_name_stable ( instance) . intern ( ) ;
5353 if self . symbol_table . contains ( fn_name) {
5454 // Symbol has been added (either a built-in CBMC function or a Rust allocation function).
5555 self . symbol_table . lookup ( fn_name) . unwrap ( )
5656 } else if RUST_ALLOC_FNS . contains ( & fn_name)
57- || ( self . is_cffi_enabled ( ) && kani_middle:: fn_abi ( self . tcx , instance) . conv == Conv :: C )
57+ || ( self . is_cffi_enabled ( )
58+ && kani_middle:: fn_abi ( self . tcx , internal_instance) . conv == Conv :: C )
5859 {
5960 // Add a Rust alloc lib function as is declared by core.
6061 // When C-FFI feature is enabled, we just trust the rust declaration.
@@ -63,14 +64,8 @@ impl<'tcx> GotocCtx<'tcx> {
6364 // https://github.com/model-checking/kani/issues/2426
6465 self . ensure ( fn_name, |gcx, _| {
6566 let typ = gcx. codegen_ffi_type ( instance) ;
66- Symbol :: function (
67- fn_name,
68- typ,
69- None ,
70- gcx. readable_instance_name ( instance) ,
71- Location :: none ( ) ,
72- )
73- . with_is_extern ( true )
67+ Symbol :: function ( fn_name, typ, None , instance. name ( ) , Location :: none ( ) )
68+ . with_is_extern ( true )
7469 } )
7570 } else {
7671 let shim_name = format ! ( "{fn_name}_ffi_shim" ) ;
@@ -82,7 +77,7 @@ impl<'tcx> GotocCtx<'tcx> {
8277 & shim_name,
8378 typ,
8479 Some ( gcx. codegen_ffi_shim ( shim_name. as_str ( ) . into ( ) , instance) ) ,
85- gcx . readable_instance_name ( instance ) ,
80+ instance . name ( ) ,
8681 Location :: none ( ) ,
8782 )
8883 } )
@@ -96,19 +91,19 @@ impl<'tcx> GotocCtx<'tcx> {
9691 }
9792
9893 /// Generate code for a foreign function shim.
99- fn codegen_ffi_shim ( & mut self , shim_name : InternedString , instance : Instance < ' tcx > ) -> Stmt {
94+ fn codegen_ffi_shim ( & mut self , shim_name : InternedString , instance : Instance ) -> Stmt {
10095 debug ! ( ?shim_name, ?instance, sym=?self . symbol_table. lookup( shim_name) , "generate_foreign_shim" ) ;
10196
102- let loc = self . codegen_span ( & self . tcx . def_span ( instance . def_id ( ) ) ) ;
97+ let loc = self . codegen_span_stable ( instance . def . span ( ) ) ;
10398 let unsupported_check = self . codegen_ffi_unsupported ( instance, loc) ;
10499 Stmt :: block ( vec ! [ unsupported_check] , loc)
105100 }
106101
107102 /// Generate type for the given foreign instance.
108- fn codegen_ffi_type ( & mut self , instance : Instance < ' tcx > ) -> Type {
109- let fn_name = self . symbol_name ( instance) ;
110- let fn_abi = kani_middle:: fn_abi ( self . tcx , instance) ;
111- let loc = self . codegen_span ( & self . tcx . def_span ( instance . def_id ( ) ) ) ;
103+ fn codegen_ffi_type ( & mut self , instance : Instance ) -> Type {
104+ let fn_name = self . symbol_name_stable ( instance) ;
105+ let fn_abi = kani_middle:: fn_abi ( self . tcx , rustc_internal :: internal ( instance) ) ;
106+ let loc = self . codegen_span_stable ( instance . def . span ( ) ) ;
112107 let params = fn_abi
113108 . args
114109 . iter ( )
@@ -137,15 +132,15 @@ impl<'tcx> GotocCtx<'tcx> {
137132 ///
138133 /// This will behave like `codegen_unimplemented_stmt` but print a message that includes
139134 /// the name of the function not supported and the calling convention.
140- fn codegen_ffi_unsupported ( & mut self , instance : Instance < ' tcx > , loc : Location ) -> Stmt {
141- let fn_name = & self . symbol_name ( instance) ;
135+ fn codegen_ffi_unsupported ( & mut self , instance : Instance , loc : Location ) -> Stmt {
136+ let fn_name = & self . symbol_name_stable ( instance) ;
142137 debug ! ( ?fn_name, ?loc, "codegen_ffi_unsupported" ) ;
143138
144139 // Save this occurrence so we can emit a warning in the compilation report.
145140 let entry = self . unsupported_constructs . entry ( "foreign function" . into ( ) ) . or_default ( ) ;
146141 entry. push ( loc) ;
147142
148- let call_conv = kani_middle:: fn_abi ( self . tcx , instance) . conv ;
143+ let call_conv = kani_middle:: fn_abi ( self . tcx , rustc_internal :: internal ( instance) ) . conv ;
149144 let msg = format ! ( "call to foreign \" {call_conv:?}\" function `{fn_name}`" ) ;
150145 let url = if call_conv == Conv :: C {
151146 "https://github.com/model-checking/kani/issues/2423"
0 commit comments