@@ -7,8 +7,12 @@ use crate::GotocCtx;
7
7
use cbmc:: goto_program:: Symbol ;
8
8
use rustc_hir:: def_id:: DefId ;
9
9
use rustc_middle:: mir:: mono:: MonoItem ;
10
+ use rustc_middle:: ty:: { subst:: InternalSubsts , Instance } ;
10
11
use tracing:: debug;
11
12
13
+ /// Separator used to generate function static variable names (<function_name>::<variable_name>).
14
+ const SEPARATOR : & str = "::" ;
15
+
12
16
impl < ' tcx > GotocCtx < ' tcx > {
13
17
pub fn codegen_static ( & mut self , def_id : DefId , item : MonoItem < ' tcx > ) {
14
18
debug ! ( "codegen_static" ) ;
@@ -18,12 +22,21 @@ impl<'tcx> GotocCtx<'tcx> {
18
22
}
19
23
20
24
pub fn declare_static ( & mut self , def_id : DefId , item : MonoItem < ' tcx > ) {
21
- debug ! ( "declare_static {:?}" , def_id ) ;
25
+ // Unique mangled monomorphized name.
22
26
let symbol_name = item. symbol_name ( self . tcx ) . to_string ( ) ;
27
+ // Pretty name which may include function name.
28
+ let pretty_name = Instance :: new ( def_id, InternalSubsts :: empty ( ) ) . to_string ( ) ;
29
+ // Name of the variable in the local context.
30
+ let base_name =
31
+ pretty_name. rsplit_once ( SEPARATOR ) . map ( |names| names. 1 ) . unwrap_or ( pretty_name. as_str ( ) ) ;
32
+ debug ! ( ?symbol_name, ?pretty_name, ?base_name, "declare_static {}" , item) ;
33
+
23
34
let typ = self . codegen_ty ( self . tcx . type_of ( def_id) ) ;
24
35
let span = self . tcx . def_span ( def_id) ;
25
36
let location = self . codegen_span ( & span) ;
26
- let symbol = Symbol :: static_variable ( symbol_name. to_string ( ) , symbol_name, typ, location) ;
37
+ let symbol = Symbol :: static_variable ( symbol_name. to_string ( ) , base_name, typ, location)
38
+ . with_is_hidden ( false ) // Static items are always user defined.
39
+ . with_pretty_name ( pretty_name) ;
27
40
self . symbol_table . insert ( symbol) ;
28
41
}
29
42
}
0 commit comments