]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: hard fail if n.Opt() is not nil in walkCheckPtrArithmetic
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 21 Oct 2019 16:25:32 +0000 (23:25 +0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 29 Oct 2019 05:39:25 +0000 (05:39 +0000)
n.Opt() is used in walkCheckPtrArithmetic to prevent infinite loops. The
fact that it's used today because n.Opt() is not used for OCONVNOP
during walk.go. If that changes, then it's not safe to repalce it
anymore. So doing hard fail if that case happens, the author of new
changes will be noticed and must change the usage of n.Opt() inside
walkCheckPtrArithmetic, too.

Change-Id: Ic7094baa1759c647fc10e82457c19026099a0d47
Reviewed-on: https://go-review.googlesource.com/c/go/+/202497
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/walk.go

index 0e780bad6c38611eeba6f7ded53cc362c0da75e8..2ec279bf37dda32b63230dc2fbfa47fbd5ea9891 100644 (file)
@@ -3965,8 +3965,12 @@ func walkCheckPtrArithmetic(n *Node, init *Nodes) *Node {
        // Calling cheapexpr(n, init) below leads to a recursive call
        // to walkexpr, which leads us back here again. Use n.Opt to
        // prevent infinite loops.
-       if n.Opt() == &walkCheckPtrArithmeticMarker {
+       if opt := n.Opt(); opt == &walkCheckPtrArithmeticMarker {
                return n
+       } else if opt != nil {
+               // We use n.Opt() here because today it's not used for OCONVNOP. If that changes,
+               // there's no guarantee that temporarily replacing it is safe, so just hard fail here.
+               Fatalf("unexpected Opt: %v", opt)
        }
        n.SetOpt(&walkCheckPtrArithmeticMarker)
        defer n.SetOpt(nil)