From aa4f48b751dbbfcb82e69d7622e7a9e9b8e48ee0 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Thu, 29 Oct 2020 12:47:15 -0700 Subject: [PATCH] cmd/compile: gracefully fail when devirtualization fails We should still be able to devirtualize here, but I need to understand the AST better. While I'm doing that, at least switch to a graceful failure case (i.e., skip the optimization and print a warning message) to fix the x/text builders. Updates #42279. Change-Id: Ie2b0b701fccf590d0cabfead703fc2fa999072cf Reviewed-on: https://go-review.googlesource.com/c/go/+/266359 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky Reviewed-by: David Chase TryBot-Result: Go Bot --- src/cmd/compile/internal/gc/inl.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go index c35691bfd2..6c69867789 100644 --- a/src/cmd/compile/internal/gc/inl.go +++ b/src/cmd/compile/internal/gc/inl.go @@ -1442,16 +1442,20 @@ func devirtualizeCall(call *Node) { return } - if Debug.m != 0 { - Warnl(call.Pos, "devirtualizing %v to %v", call.Left, typ) - } - x := nodl(call.Left.Pos, ODOTTYPE, call.Left.Left, nil) x.Type = typ x = nodlSym(call.Left.Pos, OXDOT, x, call.Left.Sym) x = typecheck(x, ctxExpr|ctxCallee) if x.Op != ODOTMETH { - Fatalf("devirtualization failed: %v", x) + // TODO(mdempsky): Figure out how to avoid this and + // turn back into a Fatalf. + if Debug.m != 0 { + Warnl(call.Pos, "failed to devirtualize %v", x) + } + return + } + if Debug.m != 0 { + Warnl(call.Pos, "devirtualizing %v to %v", call.Left, typ) } call.Op = OCALLMETH call.Left = x -- 2.48.1