Skip to content

Commit 15bfd28

Browse files
authored
fix fwd test case (#116)
* fix fwd test case * simplify
1 parent 5747648 commit 15bfd28

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,10 @@ unsafe fn create_call<'a>(tgt: &'a Value, src: &'a Value, rev_mode: bool,
860860
LLVMRustEraseInstBefore(bb, last_inst);
861861

862862
let f_return_type = LLVMGetReturnType(LLVMGlobalGetValueType(src));
863+
let f_is_struct = llvm::LLVMRustIsStructType(f_return_type);
863864
let void_type = LLVMVoidTypeInContext(llcx);
864865
// Now unwrap the struct_ret if it's actually a struct
865-
if f_return_type != void_type {
866+
if f_is_struct {
866867
let num_elem_in_ret_struct = LLVMCountStructElementTypes(f_return_type);
867868
if num_elem_in_ret_struct == 1 {
868869
let inner_grad_name = "foo".to_string();

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,7 @@ extern "C" {
10351035
pub fn LLVMRustEraseInstFromParent(V: &Value);
10361036
pub fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
10371037
pub fn LLVMGetReturnType(T: &Type) -> &Type;
1038+
pub fn LLVMRustIsStructType(T: &Type) -> bool;
10381039
pub fn LLVMDumpModule(M: &Module);
10391040
pub fn LLVMCountStructElementTypes(T: &Type) -> c_uint;
10401041
pub fn LLVMDeleteFunction(V: &Value);

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ extern "C" void LLVMRustAddFunctionAttributes(LLVMValueRef Fn, unsigned Index,
300300
AddAttributes(F, Index, Attrs, AttrsLen);
301301
}
302302

303+
extern "C" bool LLVMRustIsStructType(LLVMTypeRef Ty) {
304+
return unwrap(Ty)->isStructTy();
305+
}
306+
303307
extern "C" void LLVMRustAddCallSiteAttributes(LLVMValueRef Instr,
304308
unsigned Index,
305309
LLVMAttributeRef *Attrs,

0 commit comments

Comments
 (0)