Skip to content

Commit 4f4812f

Browse files
committed
Don't assume get_fn is only called from codegen_mir in cg_gcc
1 parent 209d94a commit 4f4812f

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
514514
type CodegenCx = CodegenCx<'gcc, 'tcx>;
515515

516516
fn build(cx: &'a CodegenCx<'gcc, 'tcx>, block: Block<'gcc>) -> Builder<'a, 'gcc, 'tcx> {
517+
*cx.current_func.borrow_mut() = Some(block.get_function());
517518
Builder::with_cx(cx, block)
518519
}
519520

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
391391
}
392392

393393
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)
397395
}
398396

399397
fn get_fn_addr(&self, instance: Instance<'tcx>) -> RValue<'gcc> {

compiler/rustc_codegen_gcc/src/declare.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
100100
let return_type = self.type_i32();
101101
let variadic = false;
102102
self.linkage.set(FunctionType::Exported);
103-
let func = declare_raw_fn(
103+
declare_raw_fn(
104104
self,
105105
name,
106106
callconv,
107107
return_type,
108108
&[self.type_i32(), const_string],
109109
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+
)
115111
}
116112

117113
pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> Function<'gcc> {

0 commit comments

Comments
 (0)