Skip to content

Commit 9d28bd2

Browse files
committed
fix illegal usage of parameter of kernel function in main function
1 parent d60482e commit 9d28bd2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

compiler/rustc_codegen_llvm/src/builder/gpu_offload.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ fn gen_call_handling<'ll>(
366366
let arg_name = format!("{name}.addr");
367367
let alloca = builder.direct_alloca(in_ty, Align::EIGHT, &arg_name);
368368

369-
builder.store(p, alloca, Align::EIGHT);
369+
let v = unsafe { llvm::LLVMGetOperand(kernel_call, index as u32).unwrap() };
370+
builder.store(v, alloca, Align::EIGHT);
370371
let val = builder.load(in_ty, alloca, Align::EIGHT);
371372
let gep = builder.inbounds_gep(cx.type_f32(), val, &[i32_0]);
372373
vals.push(val);
@@ -510,7 +511,9 @@ fn gen_call_handling<'ll>(
510511
let next = llvm::LLVMGetNextInstruction(offload_success).unwrap();
511512
dbg!(&next);
512513
llvm::LLVMRustPositionAfter(builder.llbuilder, next);
514+
let called_kernel = llvm::LLVMGetCalledValue(next).unwrap();
513515
llvm::LLVMInstructionEraseFromParent(next);
516+
dbg!(&called_kernel);
514517
}
515518

516519
// Step 4)
@@ -521,6 +524,10 @@ fn gen_call_handling<'ll>(
521524

522525
builder.call(mapper_fn_ty, unregister_lib_decl, &[tgt_bin_desc_alloca], None);
523526

527+
drop(builder);
528+
unsafe { llvm::LLVMDeleteFunction(called) };
529+
dbg!("survived");
530+
524531
// With this we generated the following begin and end mappers. We could easily generate the
525532
// update mapper in an update.
526533
// call void @__tgt_target_data_begin_mapper(ptr @1, i64 -1, i32 3, ptr %27, ptr %28, ptr %29, ptr @.offload_maptypes, ptr null, ptr null)

0 commit comments

Comments
 (0)