Don't assume get_fn is only called from codegen_mir in cg_gcc · rust-lang/rust@4f4812f (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -514,6 +514,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
514 514 type CodegenCx = CodegenCx<'gcc, 'tcx>;
515 515
516 516 fn build(cx: &'a CodegenCx<'gcc, 'tcx>, block: Block<'gcc>) -> Builder<'a, 'gcc, 'tcx> {
517 +*cx.current_func.borrow_mut() = Some(block.get_function());
517 518 Builder::with_cx(cx, block)
518 519 }
519 520
Original file line number Diff line number Diff line change
@@ -391,9 +391,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
391 391 }
392 392
393 393 fn get_fn(&self, instance: Instance<'tcx>) -> Function<'gcc> {
394 -let func = get_fn(self, instance);
395 -*self.current_func.borrow_mut() = Some(func);
396 - func
394 +get_fn(self, instance)
397 395 }
398 396
399 397 fn get_fn_addr(&self, instance: Instance<'tcx>) -> RValue<'gcc> {
Original file line number Diff line number Diff line change
@@ -100,18 +100,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
100 100 let return_type = self.type_i32();
101 101 let variadic = false;
102 102 self.linkage.set(FunctionType::Exported);
103 -let func = declare_raw_fn(
103 +declare_raw_fn(
104 104 self,
105 105 name,
106 106 callconv,
107 107 return_type,
108 108 &[self.type_i32(), const_string],
109 109 variadic,
110 -);
111 -// NOTE: it is needed to set the current_func here as well, because get_fn() is not called
112 -// for the main function.
113 -*self.current_func.borrow_mut() = Some(func);
114 - func
110 +)
115 111 }
116 112
117 113 pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Function<'gcc> {