@@ -137,18 +137,23 @@ pub(crate) fn codegen_const_value<'tcx>(
137137 let alloc_id = prov. alloc_id ( ) ;
138138 let base_addr = match fx. tcx . global_alloc ( alloc_id) {
139139 GlobalAlloc :: Memory ( alloc) => {
140- let data_id = data_id_for_alloc_id (
141- & mut fx. constants_cx ,
142- fx. module ,
143- alloc_id,
144- alloc. inner ( ) . mutability ,
145- ) ;
146- let local_data_id =
147- fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
148- if fx. clif_comments . enabled ( ) {
149- fx. add_comment ( local_data_id, format ! ( "{:?}" , alloc_id) ) ;
140+ if alloc. inner ( ) . len ( ) == 0 {
141+ assert_eq ! ( offset, Size :: ZERO ) ;
142+ fx. bcx . ins ( ) . iconst ( fx. pointer_type , alloc. inner ( ) . align . bytes ( ) as i64 )
143+ } else {
144+ let data_id = data_id_for_alloc_id (
145+ & mut fx. constants_cx ,
146+ fx. module ,
147+ alloc_id,
148+ alloc. inner ( ) . mutability ,
149+ ) ;
150+ let local_data_id =
151+ fx. module . declare_data_in_func ( data_id, & mut fx. bcx . func ) ;
152+ if fx. clif_comments . enabled ( ) {
153+ fx. add_comment ( local_data_id, format ! ( "{:?}" , alloc_id) ) ;
154+ }
155+ fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id)
150156 }
151- fx. bcx . ins ( ) . global_value ( fx. pointer_type , local_data_id)
152157 }
153158 GlobalAlloc :: Function ( instance) => {
154159 let func_id = crate :: abi:: import_function ( fx. tcx , fx. module , instance) ;
0 commit comments