@@ -450,8 +450,6 @@ func (c *Compiler) markAsyncFunctions() (needsScheduler bool, err error) {
450
450
}
451
451
coroDebugPrintln ("scanning" , f .Name ())
452
452
453
- var retAlloc llvm.Value
454
-
455
453
// Rewrite async calls
456
454
for bb := f .EntryBasicBlock (); ! bb .IsNil (); bb = llvm .NextBasicBlock (bb ) {
457
455
for inst := bb .FirstInstruction (); ! inst .IsNil (); inst = llvm .NextInstruction (inst ) {
@@ -511,9 +509,9 @@ func (c *Compiler) markAsyncFunctions() (needsScheduler bool, err error) {
511
509
// pass parent handle directly into function
512
510
inst .SetOperand (inst .OperandsCount ()- 2 , parentHandle )
513
511
514
- if inst .Type ().TypeKind () != llvm .VoidTypeKind {
512
+ if callee .Type (). ElementType (). ReturnType ().TypeKind () != llvm .VoidTypeKind {
515
513
// delete return value
516
- uses [0 ].SetOperand (0 , llvm .Undef (inst .Type ()))
514
+ uses [0 ].SetOperand (0 , llvm .Undef (callee .Type (). ElementType (). ReturnType ()))
517
515
}
518
516
519
517
c .builder .SetInsertPointBefore (next )
@@ -534,15 +532,9 @@ func (c *Compiler) markAsyncFunctions() (needsScheduler bool, err error) {
534
532
535
533
// Allocate space for the return value.
536
534
var retvalAlloca llvm.Value
537
- if inst .Type ().TypeKind () != llvm .VoidTypeKind {
538
- if retAlloc .IsNil () {
539
- // insert at start of function
540
- c .builder .SetInsertPointBefore (f .EntryBasicBlock ().FirstInstruction ())
541
-
542
- // allocate return value buffer
543
- retAlloc = c .builder .CreateAlloca (inst .Type (), "coro.retvalAlloca" )
544
- }
545
- retvalAlloca = retAlloc
535
+ if callee .Type ().ElementType ().ReturnType ().TypeKind () != llvm .VoidTypeKind {
536
+ // allocate return value buffer
537
+ retvalAlloca = c .createInstructionAlloca (callee .Type ().ElementType ().ReturnType (), inst , "coro.retvalAlloca" )
546
538
547
539
// call before function
548
540
c .builder .SetInsertPointBefore (inst )
@@ -672,7 +664,7 @@ func (c *Compiler) markAsyncFunctions() (needsScheduler bool, err error) {
672
664
c .builder .CreateStore (inst .Operand (0 ), retPtr )
673
665
674
666
// delete return value
675
- inst .SetOperand (0 , llvm .Undef (inst .Type ()))
667
+ inst .SetOperand (0 , llvm .Undef (f .Type (). ElementType (). ReturnType ()))
676
668
}
677
669
678
670
// insert reactivation call
0 commit comments