From 97bea970651f0df86e245b2b2596003a174fb5d7 Mon Sep 17 00:00:00 2001
From: Austin Clements <austin@google.com>
Date: Tue, 22 May 2018 11:07:43 -0400
Subject: [PATCH] cmd/compile: fix unsafe-point analysis with -N

Compiling without optimizations (-N) can result in write barrier
blocks that have been optimized away but not actually pruned from the
block set. Fix unsafe-point analysis to recognize and ignore these.

For #24543.

Change-Id: I2ca86fb1a0346214ec71d7d6c17b6a121857b01d
Reviewed-on: https://go-review.googlesource.com/114076
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
---
 src/cmd/compile/internal/gc/plive.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/cmd/compile/internal/gc/plive.go b/src/cmd/compile/internal/gc/plive.go
index 7a953546dc..f42094a0f5 100644
--- a/src/cmd/compile/internal/gc/plive.go
+++ b/src/cmd/compile/internal/gc/plive.go
@@ -493,6 +493,12 @@ func (lv *Liveness) markUnsafePoints() {
 
 	// Mark write barrier unsafe points.
 	for _, wbBlock := range lv.f.WBLoads {
+		if wbBlock.Kind == ssa.BlockPlain && len(wbBlock.Values) == 0 {
+			// The write barrier block was optimized away
+			// but we haven't done dead block elimination.
+			// (This can happen in -N mode.)
+			continue
+		}
 		// Check that we have the expected diamond shape.
 		if len(wbBlock.Succs) != 2 {
 			lv.f.Fatalf("expected branch at write barrier block %v", wbBlock)
-- 
2.30.9