Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gollvm: escape analysis internal error #56071

Closed
alexanius opened this issue Oct 6, 2022 · 4 comments
Closed

gollvm: escape analysis internal error #56071

alexanius opened this issue Oct 6, 2022 · 4 comments
Assignees
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@alexanius
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.18 gollvm LLVM 15.0.0git 20221003 (experimental) linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/amarkin/.cache/go-build"
GOENV="/home/amarkin/.config/go/env"
GOEXE=""
GOEXPERIMENT="fieldtrack,regabiwrappers"
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/amarkin/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/amarkin/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/amarkin/repos/gollvm_trunk/installed-debug"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/amarkin/repos/gollvm_trunk/installed-debug/tools"
GOVCS=""
GOVERSION="go1.18 gollvm LLVM 15.0.0git 20221003 (experimental)"
GCCGO="/home/amarkin/repos/gollvm_trunk/installed-debug/bin/llvm-goc"
GOAMD64="v1"
AR="ar"
CC="/usr/bin/cc"
CXX="/usr/bin/c++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2185844573=/tmp/go-build -gno-record-gcc-switches -funwind-tables"

What did you do?

$ cat t.go package main import "sync" import "runtime" import "strings" import "strconv" func goid() int { var buf [64]byte n := runtime.Stack(buf[:], false) idField := strings.Fields(strings.TrimPrefix(string(buf[:n]), "goroutine "))[0] id, err := strconv.Atoi(idField) if err != nil { panic(println("cannot get goroutine id: %v", err)) } return id } func main() { var wg sync.WaitGroup for i := 0 ; i < 30 ; i++ { wg.Add(1) go func() { println("goid", goid()) defer wg.Done() t := 0 for i := 0 ; i < 1e8 ; i++ { t += 2 } println("total: ", t, goid()) }() } wg.Wait() }
$ LD_LIBRARY_PATH="/home/amarkin/repos/gollvm_trunk/installed-debug/lib64" /home/amarkin/repos/gollvm_trunk/installed-debug/bin/go build t.go
# command-line-arguments
unreachable
UNREACHABLE executed at /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/escape.cc:2473!
 #0 0x000055ed90306f6c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/amarkin/repos/gollvm_trunk/llvm/lib/Support/Unix/Signals.inc:565:22
 #1 0x000055ed90307027 PrintStackTraceSignalHandler(void*) /home/amarkin/repos/gollvm_trunk/llvm/lib/Support/Unix/Signals.inc:632:1
 #2 0x000055ed90304ca2 llvm::sys::RunSignalHandlers() /home/amarkin/repos/gollvm_trunk/llvm/lib/Support/Signals.cpp:97:20
 #3 0x000055ed903068c3 SignalHandler(int) /home/amarkin/repos/gollvm_trunk/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x00007fb863ca8420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #5 0x00007fb86374000b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007fb86371f859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
 #7 0x000055ed90228363 bindingsErrorHandler(void*, char const*, bool) /home/amarkin/repos/gollvm_trunk/llvm/lib/Support/ErrorHandling.cpp:218:55
 #8 0x000055ed8d96bc8b Escape_analysis_assign::assign(Node*, Node*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/escape.cc:2455:21
 #9 0x000055ed8d9694b6 Escape_analysis_assign::expression(Expression**) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/escape.cc:1790:7
#10 0x000055ed8d9987ed Expression::traverse(Expression**, Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/expressions.cc:45:35
#11 0x000055ed8d9d51f5 Expression_list::traverse(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/expressions.cc:19394:44
#12 0x000055ed8d9b8cdc Call_expression::do_traverse(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/expressions.cc:11148:43
#13 0x000055ed8d99885a Expression::traverse_subexpressions(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/expressions.cc:60:1
#14 0x000055ed8d968bb2 Escape_analysis_assign::expression(Expression**) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/escape.cc:1547:3
#15 0x000055ed8d9987ed Expression::traverse(Expression**, Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/expressions.cc:45:35
#16 0x000055ed8d8a7efa Statement::traverse_expression(Traverse*, Expression**) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.cc:86:45
#17 0x000055ed8d8be6ad Expression_statement::do_traverse(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.h:916:63
#18 0x000055ed8d8a7e6e Statement::traverse_contents(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.cc:65:1
#19 0x000055ed8d967f58 Escape_analysis_assign::statement(Block*, unsigned long*, Statement*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/escape.cc:1338:3
#20 0x000055ed8d8a7e01 Statement::traverse(Block*, unsigned long*, Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.cc:46:34
#21 0x000055ed8d82d6d2 Block::traverse(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/gogo.cc:6908:62
#22 0x000055ed8d8b2a60 If_statement::do_traverse(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.cc:3772:7
#23 0x000055ed8d8a7e6e Statement::traverse_contents(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.cc:65:1
#24 0x000055ed8d967f58 Escape_analysis_assign::statement(Block*, unsigned long*, Statement*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/escape.cc:1338:3
#25 0x000055ed8d8a7e01 Statement::traverse(Block*, unsigned long*, Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.cc:46:34
#26 0x000055ed8d82d6d2 Block::traverse(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/gogo.cc:6908:62
#27 0x000055ed8d8be74b Block_statement::do_traverse(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.h:983:46
#28 0x000055ed8d8a7e6e Statement::traverse_contents(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.cc:65:1
#29 0x000055ed8d967f58 Escape_analysis_assign::statement(Block*, unsigned long*, Statement*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/escape.cc:1338:3
#30 0x000055ed8d8a7e01 Statement::traverse(Block*, unsigned long*, Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/statements.cc:46:34
#31 0x000055ed8d82d6d2 Block::traverse(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/gogo.cc:6908:62
#32 0x000055ed8d828fa5 Function::traverse(Traverse*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/gogo.cc:5829:44
#33 0x000055ed8d96d415 Gogo::assign_connectivity(Escape_context*, Named_object*) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/escape.cc:2955:26
#34 0x000055ed8d966f64 Gogo::analyze_escape() /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/escape.cc:943:14
#35 0x000055ed8d8143ea go_parse_input_files(char const**, unsigned int, bool, bool) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/gofrontend/go/go.cc:162:21
#36 0x000055ed8d7f6cc5 gollvm::driver::CompileGoImpl::invokeFrontEnd() /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/driver/CompileGo.cpp:749:8
#37 0x000055ed8d7f43a6 gollvm::driver::CompileGoImpl::performAction(gollvm::driver::Compilation&, gollvm::driver::Action const&, llvm::SmallVector const&, gollvm::driver::Artifact const&) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/driver/CompileGo.cpp:193:7
#38 0x000055ed8d7f7bc0 gollvm::driver::CompileGo::performAction(gollvm::driver::Compilation&, gollvm::driver::Action const&, llvm::SmallVector const&, gollvm::driver::Artifact const&) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/driver/CompileGo.cpp:966:1
#39 0x000055ed8d7e72e0 gollvm::driver::Driver::processAction(gollvm::driver::Action*, gollvm::driver::Compilation&, bool) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/driver/Driver.cpp:707:11
#40 0x000055ed8d7e74a5 gollvm::driver::Driver::processActions(gollvm::driver::Compilation&) /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/driver/Driver.cpp:730:9
#41 0x000055ed8d7dab5d main /home/amarkin/repos/gollvm_trunk/llvm/tools/gollvm/driver-main/llvm-goc.cpp:228:7
#42 0x00007fb863721083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#43 0x000055ed8d7d9f6e _start (/home/amarkin/repos/gollvm_trunk/installed-debug/bin/llvm-goc+0x8e3f6e)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/amarkin/repos/gollvm_trunk/installed-debug/bin/llvm-goc -c -O2 -g -m64 -fdebug-prefix-map=/tmp/go-build360302384=/tmp/go-build -gno-record-gcc-switches -o $WORK/b001/_go_.o -I $WORK/b001/_importcfgroot_ ./t.go $WORK/b001/_gomod_.go

What did you expect to see?

Successful build

What did you see instead?

Stack dump

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 6, 2022
@cagedmantis cagedmantis added this to the Backlog milestone Oct 6, 2022
@cagedmantis
Copy link
Contributor

@thanm

@thanm
Copy link
Contributor

thanm commented Oct 6, 2022

thanks for the report. I'll take a look.

@thanm
Copy link
Contributor

thanm commented Oct 6, 2022

Looks like the problem here really with the front end, not with escape analysis. For this package:

package p

func f(x int) {
	if x != 0 {
		panic(println("not zero"))
	}
}

I get the crash cited in the bug when building with gollvm/gccgo, but with the regular Go compiler I get:

$ go build small.go
# command-line-arguments
./small.go:5:9: println("not zero") (no value) used as value

I will look into a fix (which should also get rid of the escape analysis crash).

@thanm thanm modified the milestones: Backlog, Gccgo Oct 6, 2022
@thanm thanm self-assigned this Oct 6, 2022
@gopherbot
Copy link

Change https://go.dev/cl/439815 mentions this issue: compiler: better arg type checking for selected builtins

nstester pushed a commit to nstester/gcc that referenced this issue Oct 7, 2022
Tighten up the argument type checking for Builtin_call_expression to
catch erroneous cases such as

   panic(panic("bad")))

where an argument void type is being passed to panic/alignof/sizeof.

Fixes golang/go#56071.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/439815
@golang golang locked and limited conversation to collaborators Oct 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants