]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile: fix libfuzzer instrumentation line number
authorKeith Randall <khr@golang.org>
Fri, 8 Jul 2022 21:52:23 +0000 (14:52 -0700)
committerKeith Randall <khr@google.com>
Fri, 8 Jul 2022 23:41:37 +0000 (23:41 +0000)
Set a reasonable starting line number before processing the body of
the function in the order pass.

We update base.Pos each time we process a node, but some of the
libfuzzer instrumentation is added before we process any node, so the
base.Pos used is junk.

Fixes #53688

Change-Id: I3654b805eabb8866a9a1574845ef4ff062797319
Reviewed-on: https://go-review.googlesource.com/c/go/+/416654
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/walk/order.go

index 8d1089dcc1f51d72d51f256382e8df2d1f4be9ad..2d1e88238ccfc986c19d4048896a51ee6d90cf7c 100644 (file)
@@ -63,7 +63,7 @@ func order(fn *ir.Func) {
                s := fmt.Sprintf("\nbefore order %v", fn.Sym())
                ir.DumpList(s, fn.Body)
        }
-
+       ir.SetPos(fn) // Set reasonable position for instrumenting code. See issue 53688.
        orderBlock(&fn.Body, map[string][]*ir.Name{})
 }
 
@@ -477,6 +477,12 @@ func (o *orderState) edge() {
 // and then replaces the old slice in n with the new slice.
 // free is a map that can be used to obtain temporary variables by type.
 func orderBlock(n *ir.Nodes, free map[string][]*ir.Name) {
+       if len(*n) != 0 {
+               // Set reasonable position for instrumenting code. See issue 53688.
+               // It would be nice if ir.Nodes had a position (the opening {, probably),
+               // but it doesn't. So we use the first statement's position instead.
+               ir.SetPos((*n)[0])
+       }
        var order orderState
        order.free = free
        mark := order.markTemp()