diff options
author | Cherry Zhang <cherryyz@google.com> | 2016-06-30 06:36:31 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2016-07-01 01:12:24 +0000 |
commit | 29f0984a3558ef6e3e58a621791473a71b510365 (patch) | |
tree | 072bdd9f482bbf45a018d33b60bbb9d8c2c2e064 | |
parent | b5aae1a2845f157a2565b856fb2d7773a0f7af25 (diff) | |
download | go-29f0984a3558ef6e3e58a621791473a71b510365.tar.gz go-29f0984a3558ef6e3e58a621791473a71b510365.zip |
cmd/compile: don't set line number to 0 when building SSA
The frontend may emit node with line number missing. In this case,
use the parent line number. Instead of changing every call site of
pushLine, do it in pushLine itself.
Fixes #16214.
Change-Id: I80390550b56e4d690fc770b01ff725b892ffd6dc
Reviewed-on: https://go-review.googlesource.com/24641
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r-- | src/cmd/compile/internal/gc/asm_test.go | 35 | ||||
-rw-r--r-- | src/cmd/compile/internal/gc/ssa.go | 8 |
2 files changed, 43 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/gc/asm_test.go b/src/cmd/compile/internal/gc/asm_test.go index b44bf77c5d..21b5910ecc 100644 --- a/src/cmd/compile/internal/gc/asm_test.go +++ b/src/cmd/compile/internal/gc/asm_test.go @@ -122,3 +122,38 @@ NextVar: } return out } + +// TestLineNumber checks to make sure the generated assembly has line numbers +// see issue #16214 +func TestLineNumber(t *testing.T) { + testenv.MustHaveGoBuild(t) + dir, err := ioutil.TempDir("", "TestLineNumber") + if err != nil { + t.Fatalf("could not create directory: %v", err) + } + defer os.RemoveAll(dir) + + src := filepath.Join(dir, "x.go") + err = ioutil.WriteFile(src, []byte(issue16214src), 0644) + if err != nil { + t.Fatalf("could not write file: %v", err) + } + + cmd := exec.Command("go", "tool", "compile", "-S", "-o", filepath.Join(dir, "out.o"), src) + out, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("fail to run go tool compile: %v", err) + } + + if strings.Contains(string(out), "unknown line number") { + t.Errorf("line number missing in assembly:\n%s", out) + } +} + +var issue16214src = ` +package main + +func Mod32(x uint32) uint32 { + return x % 3 // frontend rewrites it as HMUL with 2863311531, the LITERAL node has Lineno 0 +} +` diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 7f55da621c..62ea44f776 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -384,6 +384,14 @@ func (s *state) endBlock() *ssa.Block { // pushLine pushes a line number on the line number stack. func (s *state) pushLine(line int32) { + if line == 0 { + // the frontend may emit node with line number missing, + // use the parent line number in this case. + line = s.peekLine() + if Debug['K'] != 0 { + Warn("buildssa: line 0") + } + } s.line = append(s.line, line) } |