@@ -455,24 +455,16 @@ func (r *runner) collectCtxRef(f *ssa.Function, isHttpHandler bool) (refMap map[
455
455
}
456
456
457
457
for instr := range storeInstrs {
458
- if ! instr .Pos ().IsValid () {
459
- continue
460
- }
461
-
462
458
if ! checkedRefMap [instr .Val ] {
463
- r .pass . Reportf (instr . Pos () , "Non-inherited new context, use function like `context.WithXXX` instead" )
459
+ r .Reportf (instr , "Non-inherited new context, use function like `context.WithXXX` instead" )
464
460
ok = false
465
461
}
466
462
}
467
463
468
464
for instr := range phiInstrs {
469
- if ! instr .Pos ().IsValid () {
470
- continue
471
- }
472
-
473
465
for _ , v := range instr .Edges {
474
466
if ! checkedRefMap [v ] {
475
- r .pass . Reportf (instr . Pos () , "Non-inherited new context, use function like `context.WithXXX` instead" )
467
+ r .Reportf (instr , "Non-inherited new context, use function like `context.WithXXX` instead" )
476
468
ok = false
477
469
}
478
470
}
@@ -559,10 +551,6 @@ func (r *runner) checkFuncWithCtx(f *ssa.Function, tp entryType) {
559
551
560
552
for _ , b := range f .Blocks {
561
553
for _ , instr := range b .Instrs {
562
- if ! instr .Pos ().IsValid () {
563
- continue
564
- }
565
-
566
554
tp , ok := r .getCtxType (instr )
567
555
if ! ok {
568
556
continue
@@ -576,9 +564,9 @@ func (r *runner) checkFuncWithCtx(f *ssa.Function, tp entryType) {
576
564
if tp & CtxIn != 0 {
577
565
if ! refMap [instr ] {
578
566
if isHttpHandler {
579
- r .pass . Reportf (instr . Pos () , "Non-inherited new context, use function like `context.WithXXX` or `r.Context` instead" )
567
+ r .Reportf (instr , "Non-inherited new context, use function like `context.WithXXX` or `r.Context` instead" )
580
568
} else {
581
- r .pass . Reportf (instr . Pos () , "Non-inherited new context, use function like `context.WithXXX` instead" )
569
+ r .Reportf (instr , "Non-inherited new context, use function like `context.WithXXX` instead" )
582
570
}
583
571
}
584
572
}
@@ -592,13 +580,26 @@ func (r *runner) checkFuncWithCtx(f *ssa.Function, tp entryType) {
592
580
res , ok := r .getValue (key , ff )
593
581
if ok {
594
582
if ! res .Valid {
595
- r .pass . Reportf (instr . Pos () , "Function `%s` should pass the context parameter" , strings .Join (reverse (res .Funcs ), "->" ))
583
+ r .Reportf (instr , "Function `%s` should pass the context parameter" , strings .Join (reverse (res .Funcs ), "->" ))
596
584
}
597
585
}
598
586
}
599
587
}
600
588
}
601
589
590
+ func (r * runner ) Reportf (instr ssa.Instruction , format string , args ... interface {}) {
591
+ pos := instr .Pos ()
592
+ if ! pos .IsValid () && instr .Parent () != nil {
593
+ pos = instr .Parent ().Pos ()
594
+ }
595
+
596
+ if ! pos .IsValid () {
597
+ return
598
+ }
599
+
600
+ r .pass .Reportf (pos , format , args ... )
601
+ }
602
+
602
603
func (r * runner ) checkFuncWithoutCtx (f * ssa.Function , checkingMap map [string ]bool ) (ret bool ) {
603
604
ret = true
604
605
orgKey := f .RelString (nil )
0 commit comments