@@ -104,7 +104,6 @@ package compiler
104
104
// scheduler, which runs in the background scheduling all coroutines.
105
105
106
106
import (
107
- "errors"
108
107
"fmt"
109
108
"strings"
110
109
@@ -283,7 +282,7 @@ func (c *Compiler) markAsyncFunctions() (needsScheduler bool, err error) {
283
282
if use .IsConstant () && use .Opcode () == llvm .PtrToInt {
284
283
for _ , call := range getUses (use ) {
285
284
if call .IsACallInst ().IsNil () || call .CalledValue ().Name () != "runtime.makeGoroutine" {
286
- return false , errors . New ( "async function " + f . Name () + " incorrectly used in ptrtoint, expected runtime.makeGoroutine" )
285
+ return false , errorAt ( call , "async function incorrectly used in ptrtoint, expected runtime.makeGoroutine" )
287
286
}
288
287
}
289
288
// This is a go statement. Do not mark the parent as async, as
@@ -303,12 +302,19 @@ func (c *Compiler) markAsyncFunctions() (needsScheduler bool, err error) {
303
302
// Not a call instruction. Maybe a store to a global? In any
304
303
// case, this requires support for async calls across function
305
304
// pointers which is not yet supported.
306
- return false , errors .New ("async function " + f .Name () + " used as function pointer" )
305
+ at := use
306
+ if use .IsAInstruction ().IsNil () {
307
+ // The use might not be an instruction (for example, in the
308
+ // case of a const bitcast). Fall back to reporting the
309
+ // location of the function instead.
310
+ at = f
311
+ }
312
+ return false , errorAt (at , "async function " + f .Name ()+ " used as function pointer" )
307
313
}
308
314
parent := use .InstructionParent ().Parent ()
309
315
for i := 0 ; i < use .OperandsCount ()- 1 ; i ++ {
310
316
if use .Operand (i ) == f {
311
- return false , errors . New ( "async function " + f .Name () + " used as function pointer in " + parent . Name () )
317
+ return false , errorAt ( use , "async function " + f .Name ()+ " used as function pointer" )
312
318
}
313
319
}
314
320
worklist = append (worklist , parent )
@@ -906,12 +912,12 @@ func (c *Compiler) lowerMakeGoroutineCalls(sched bool) error {
906
912
origFunc := ptrtointIn .Operand (0 )
907
913
uses := getUses (goroutine )
908
914
if len (uses ) != 1 || uses [0 ].IsAIntToPtrInst ().IsNil () {
909
- return errors . New ( "expected exactly 1 inttoptr use of runtime.makeGoroutine" )
915
+ return errorAt ( makeGoroutine , "expected exactly 1 inttoptr use of runtime.makeGoroutine" )
910
916
}
911
917
inttoptrOut := uses [0 ]
912
918
uses = getUses (inttoptrOut )
913
919
if len (uses ) != 1 || uses [0 ].IsACallInst ().IsNil () {
914
- return errors . New ( "expected exactly 1 call use of runtime.makeGoroutine bitcast" )
920
+ return errorAt ( inttoptrOut , "expected exactly 1 call use of runtime.makeGoroutine bitcast" )
915
921
}
916
922
realCall := uses [0 ]
917
923
0 commit comments