aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile
diff options
context:
space:
mode:
authorCuong Manh Le <cuong.manhle.vn@gmail.com>2021-09-01 10:13:41 +0700
committerCuong Manh Le <cuong.manhle.vn@gmail.com>2021-09-01 19:51:25 +0000
commit711e1c8224f033ec1d95cdf84465b57b052e8948 (patch)
tree10bd5da46407428a05ceb1c4e7d654e6380f522e /src/cmd/compile
parent592ee433f5378e4b08f1fd8860be61b9bf20ca19 (diff)
downloadgo-711e1c8224f033ec1d95cdf84465b57b052e8948.tar.xz
cmd/compile: fix irgen mis-handling invalid function declaration
In -G=3 mode, irgen use its own generated IR, which is mis-handling of bodyless function and declared function with //go:noescape pragma. Fix this by adopting the same logic in noder.funcDecl, which minor change in linkname detection. Fixes #48097 Change-Id: Ibef921c1f75e071ca61685e0cb4543f2ee5efc7f Reviewed-on: https://go-review.googlesource.com/c/go/+/346470 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Trust: Dan Scales <danscales@google.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dan Scales <danscales@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile')
-rw-r--r--src/cmd/compile/internal/noder/decl.go4
-rw-r--r--src/cmd/compile/internal/noder/irgen.go22
-rw-r--r--src/cmd/compile/internal/types2/stdlib_test.go2
3 files changed, 22 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/noder/decl.go b/src/cmd/compile/internal/noder/decl.go
index 87a8667003..de481fb5fc 100644
--- a/src/cmd/compile/internal/noder/decl.go
+++ b/src/cmd/compile/internal/noder/decl.go
@@ -113,6 +113,10 @@ func (g *irgen) funcDecl(out *ir.Nodes, decl *syntax.FuncDecl) {
}
}
+ if decl.Body != nil && fn.Pragma&ir.Noescape != 0 {
+ base.ErrorfAt(fn.Pos(), "can only use //go:noescape with external func implementations")
+ }
+
if decl.Name.Value == "init" && decl.Recv == nil {
g.target.Inits = append(g.target.Inits, fn)
}
diff --git a/src/cmd/compile/internal/noder/irgen.go b/src/cmd/compile/internal/noder/irgen.go
index d53c254001..70f7991a8e 100644
--- a/src/cmd/compile/internal/noder/irgen.go
+++ b/src/cmd/compile/internal/noder/irgen.go
@@ -272,12 +272,6 @@ Outer:
}
}
- // Check for unusual case where noder2 encounters a type error that types2
- // doesn't check for (e.g. notinheap incompatibility).
- base.ExitIfErrors()
-
- typecheck.DeclareUniverse()
-
for _, p := range noders {
// Process linkname and cgo pragmas.
p.processPragmas()
@@ -290,6 +284,22 @@ Outer:
})
}
+ if base.Flag.Complete {
+ for _, n := range g.target.Decls {
+ if fn, ok := n.(*ir.Func); ok {
+ if fn.Body == nil && fn.Nname.Sym().Linkname == "" {
+ base.ErrorfAt(fn.Pos(), "missing function body")
+ }
+ }
+ }
+ }
+
+ // Check for unusual case where noder2 encounters a type error that types2
+ // doesn't check for (e.g. notinheap incompatibility).
+ base.ExitIfErrors()
+
+ typecheck.DeclareUniverse()
+
// Create any needed stencils of generic functions
g.stencil()
diff --git a/src/cmd/compile/internal/types2/stdlib_test.go b/src/cmd/compile/internal/types2/stdlib_test.go
index cde35c17b6..5bf2982418 100644
--- a/src/cmd/compile/internal/types2/stdlib_test.go
+++ b/src/cmd/compile/internal/types2/stdlib_test.go
@@ -192,6 +192,8 @@ func TestStdFixed(t *testing.T) {
"issue20780.go", // types2 does not have constraints on stack size
"issue42058a.go", // types2 does not have constraints on channel element size
"issue42058b.go", // types2 does not have constraints on channel element size
+ "issue48097.go", // go/types doesn't check validity of //go:xxx directives, and non-init bodyless function
+
)
}