@@ -234,13 +234,34 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
234
234
g : DropGlueKind < ' tcx > ) -> ValueRef {
235
235
let g = g. map_ty ( |t| get_drop_glue_type ( ccx. tcx ( ) , t) ) ;
236
236
match ccx. drop_glues ( ) . borrow ( ) . get ( & g) {
237
- Some ( & ( glue, _) ) => glue,
238
- None => { bug ! ( "Could not find drop glue for {:?} -- {} -- {}. \
239
- It should have be instantiated during the pre-definition phase",
240
- g,
241
- TransItem :: DropGlue ( g) . to_raw_string( ) ,
242
- ccx. codegen_unit( ) . name) }
237
+ Some ( & ( glue, _) ) => return glue,
238
+ None => {
239
+ debug ! ( "Could not find drop glue for {:?} -- {} -- {}. \
240
+ Falling back to on-demand instantiation.",
241
+ g,
242
+ TransItem :: DropGlue ( g) . to_raw_string( ) ,
243
+ ccx. codegen_unit( ) . name) ;
244
+
245
+ ccx. stats ( ) . n_fallback_instantiations . set ( ccx. stats ( )
246
+ . n_fallback_instantiations
247
+ . get ( ) + 1 ) ;
248
+ }
243
249
}
250
+
251
+ // FIXME: #34151
252
+ // Normally, getting here would indicate a bug in trans::collector,
253
+ // since it seems to have missed a translation item. When we are
254
+ // translating with non-MIR-based trans, however, the results of the
255
+ // collector are not entirely reliable since it bases its analysis
256
+ // on MIR. Thus, we'll instantiate the missing function on demand in
257
+ // this codegen unit, so that things keep working.
258
+
259
+ TransItem :: DropGlue ( g) . predefine ( ccx, llvm:: LinkOnceODRLinkage ) ;
260
+ TransItem :: DropGlue ( g) . define ( ccx) ;
261
+
262
+ // Now that we made sure that the glue function is in ccx.drop_glues,
263
+ // give it another try
264
+ get_drop_glue_core ( ccx, g)
244
265
}
245
266
246
267
pub fn implement_drop_glue < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
0 commit comments