Repository: go
Issue: gollvm: error in backend: Segmented stacks do not support vararg functions. Building goptuna, go-sqlite3
Labels: NeedsInvestigation

It seems that I was lucky today: my first pure gollvm related bug.

### What version of Go are you using (`go version`)?

<pre>
$ go version
</pre>
go version go1.15rc2 gollvm LLVM 12.0.0git linux/amd64

### Does this issue reproduce with the latest release?
No idea.


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> 
</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/oceanfish81/.cache/go-build"
GOENV="/home/oceanfish81/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/oceanfish81/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/oceanfish81/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/tools"
GCCGO="/usr/local/bin/llvm-goc"
AR="ar"
CC="/usr/bin/clang"
CXX="/usr/bin/clang++"
CGO_ENABLED="1"
GOMOD="/home/oceanfish81/go/src/github.com/c-bata/goptuna/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build762480405=/tmp/go-build -gno-record-gcc-switches -funwind-tables"
</pre>
</details>

### What did you do?

```
> ~/goptuna/cmd$ go build
> go: downloading github.com/jinzhu/gorm v1.9.10
> go: downloading github.com/spf13/cobra v0.0.5
> go: downloading github.com/mattn/go-sqlite3 v1.10.0
> go: downloading github.com/go-sql-driver/mysql v1.4.1
> go: downloading github.com/spf13/pflag v1.0.3
> go: downloading github.com/jinzhu/inflection v1.0.0
> # github.com/mattn/go-sqlite3
> 
> sqlite3-binding.c:111991:38: 
**warning: implicit conversion from 'long long' to 'double' changes value from 9223372036854775806 to 9223372036854775808**
> [-Wimplicit-const-int-float-conversion]

> sqlite3-binding.c:111993:46: 
**warning: implicit conversion from 'long long' to 'double' changes value from 9223372036854775806 to 9223372036854775808**
> [-Wimplicit-const-int-float-conversion]
**fatal error: error in backend: Segmented stacks do not support vararg functions.**

> PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
```

```
> Stack dump:
> 0.      Program arguments: /usr/bin/clang -I ../../go/pkg/mod/github.com/mattn/go-sqlite3@v1.10.0 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build291041450/b057=/tmp/go-build -gno-record-gcc-switches -funwind-tables -I $WORK/b057/ -g -O2 -std=gnu99 -DSQLITE_ENABLE_RTREE -DSQLITE_THREADSAFE=1 -DHAVE_USLEEP=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4_UNICODE61 -DSQLITE_TRACE_SIZE_LIMIT=15 -DSQLITE_OMIT_DEPRECATED -DSQLITE_DISABLE_INTRINSIC -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -Wno-deprecated-declarations -DHAVE_PREAD64=1 -DHAVE_PWRITE64=1 -I/home/oceanfish81/go/pkg/mod/github.com/mattn/go-sqlite3@v1.10.0 -fsplit-stack -o $WORK/b057/_x011.o -c sqlite3-binding.c

> 1.      <eof> parser at end of file
> 2.      Code generation
> 

3.      Running pass **'Function Pass Manager'** on module **'sqlite3-binding.c'**.
4.      Running pass **'Prologue/Epilogue Insertion & Frame Finalization'** on function **'@sqlite3_mprintf'**
 #0 0x00000000022bc394 PrintStackTraceSignalHandler(v
[bug_report.zip](https://github.com/golang/go/files/5224173/bug_report.zip)
oid*) (/usr/bin/clang+0x22bc394)
 #1 0x00000000022ba11e llvm::sys::RunSignalHandlers() (/usr/bin/clang+0x22ba11e)
 #2 0x00000000022bb63d llvm::sys::CleanupOnSignal(unsigned long) (/usr/bin/clang+0x22bb63d)
 #3 0x000000000224cfda (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) (/usr/bin/clang+0x224cfda)
 #4 0x000000000224cf7b (/usr/bin/clang+0x224cf7b)
 #5 0x00000000022b68ce (/usr/bin/clang+0x22b68ce)
 #6 0x00000000009baf32 (/usr/bin/clang+0x9baf32)
 #7 0x000000000225077f llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/bin/clang+0x225077f)
 #8 0x0000000002250658 (/usr/bin/clang+0x2250658)
 #9 0x00000000014e31d7 llvm::X86FrameLowering::adjustForSegmentedStacks(llvm::MachineFunction&, llvm::MachineBasicBlock&) const (/usr/bin/clang+0x14e31d7)
#10 0x0000000001ac3993 (anonymous namespace)::PEI::runOnMachineFunction(llvm::MachineFunction&) (/usr/bin/clang+0x1ac3993)
#11 0x00000000019f51ee llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/bin/clang+0x19f51ee)
#12 0x0000000001cf8249 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/bin/clang+0x1cf8249)
#13 0x0000000001cfdbe3 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/bin/clang+0x1cfdbe3)
#14 0x0000000001cf89fb llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/bin/clang+0x1cf89fb)
#15 0x000000000247c149 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/usr/bin/clang+0x247c149)
#16 0x0000000002f3dd86 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/bin/clang+0x2f3dd86)
#17 0x000000000392f293 clang::ParseAST(clang::Sema&, bool, bool) (/usr/bin/clang+0x392f293)
#18 0x00000000029c4a87 clang::FrontendAction::Execute() (/usr/bin/clang+0x29c4a87)
#19 0x0000000002960b21 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/bin/clang+0x2960b21)
#20 0x0000000002a5d4aa clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/bin/clang+0x2a5d4aa)
#21 0x00000000009babc7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang+0x9babc7)
#22 0x00000000009b8eb1 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) (/usr/bin/clang+0x9b8eb1)
#23 0x000000000283a012 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::$_1>(long) (/usr/bin/clang+0x283a012)
#24 0x000000000224cf5d llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/bin/clang+0x224cf5d)
#25 0x000000000283952f clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/usr/bin/clang+0x283952f)
#26 0x000000000280bd9e clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/usr/bin/clang+0x280bd9e)
#27 0x000000000280bf47 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/usr/bin/clang+0x280bf47)
#28 0x0000000002822478 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/usr/bin/clang+0x2822478)
#29 0x00000000009b893c main (/usr/bin/clang+0x9b893c)
#30 0x00007f8bfee070b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#31 0x00000000009b5f4e _start (/usr/bin/clang+0x9b5f4e)
clang-11: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-11: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-11: note: diagnostic msg: /tmp/sqlite3-binding-77e279.c
clang-11: note: diagnostic msg: /tmp/sqlite3-binding-77e279.sh
clang-11: note: diagnostic msg:

[bug_report.zip](https://github.com/golang/go/files/5224176/bug_report.zip)
```

```
> ~/goptuna/cmd$ go build -tags noasm

> # github.com/mattn/go-sqlite3
> sqlite3-binding.c:111991:38: warning: implicit conversion from 'long long' to 'double' changes value from 9223372036854775806 to 9223372036854775808 [-Wimplicit-const-int-float-conversion]
> sqlite3-binding.c:111993:46: warning: implicit conversion from 'long long' to 'double' changes value from 9223372036854775806 to 9223372036854775808 [-Wimplicit-const-int-float-conversion]
> fatal error: error in backend: Segmented stacks do not support vararg functions.
> PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
> Stack dump:
> 0.      Program arguments: /usr/bin/clang -I ../../go/pkg/mod/github.com/mattn/go-sqlite3@v1.10.0 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build682516810/b057=/tmp/go-build -gno-record-gcc-switches -funwind-tables -I $WORK/b057/ -g -O2 -std=gnu99 -DSQLITE_ENABLE_RTREE -DSQLITE_THREADSAFE=1 -DHAVE_USLEEP=1 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS4_UNICODE61 -DSQLITE_TRACE_SIZE_LIMIT=15 -DSQLITE_OMIT_DEPRECATED -DSQLITE_DISABLE_INTRINSIC -DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1 -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -Wno-deprecated-declarations -DHAVE_PREAD64=1 -DHAVE_PWRITE64=1 -I/home/oceanfish81/go/pkg/mod/github.com/mattn/go-sqlite3@v1.10.0 -fsplit-stack -o $WORK/b057/_x011.o -c sqlite3-binding.c
> 1.      <eof> parser at end of file
> 2.      Code generation
> 3.      Running pass 'Function Pass Manager' on module 'sqlite3-binding.c'.
> 4.      Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@sqlite3_mprintf'
>  #0 0x00000000022bc394 PrintStackTraceSignalHandler(void*) (/usr/bin/clang+0x22bc394)
>  #1 0x00000000022ba11e llvm::sys::RunSignalHandlers() (/usr/bin/clang+0x22ba11e)
>  #2 0x00000000022bb63d llvm::sys::CleanupOnSignal(unsigned long) (/usr/bin/clang+0x22bb63d)
>  #3 0x000000000224cfda (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) (/usr/bin/clang+0x224cfda)
>  #4 0x000000000224cf7b (/usr/bin/clang+0x224cf7b)
>  #5 0x00000000022b68ce (/usr/bin/clang+0x22b68ce)
>  #6 0x00000000009baf32 (/usr/bin/clang+0x9baf32)
>  #7 0x000000000225077f llvm::report_fatal_error(llvm::Twine const&, bool) (/usr/bin/clang+0x225077f)
>  #8 0x0000000002250658 (/usr/bin/clang+0x2250658)
>  #9 0x00000000014e31d7 llvm::X86FrameLowering::adjustForSegmentedStacks(llvm::MachineFunction&, llvm::MachineBasicBlock&) const (/usr/bin/clang+0x14e31d7)
> #10 0x0000000001ac3993 (anonymous namespace)::PEI::runOnMachineFunction(llvm::MachineFunction&) (/usr/bin/clang+0x1ac3993)
> #11 0x00000000019f51ee llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/bin/clang+0x19f51ee)
> #12 0x0000000001cf8249 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/bin/clang+0x1cf8249)
> #13 0x0000000001cfdbe3 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/bin/clang+0x1cfdbe3)
> #14 0x0000000001cf89fb llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/bin/clang+0x1cf89fb)
> #15 0x000000000247c149 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/usr/bin/clang+0x247c149)
> #16 0x0000000002f3dd86 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/bin/clang+0x2f3dd86)
> #17 0x000000000392f293 clang::ParseAST(clang::Sema&, bool, bool) (/usr/bin/clang+0x392f293)
> #18 0x00000000029c4a87 clang::FrontendAction::Execute() (/usr/bin/clang+0x29c4a87)
> #19 0x0000000002960b21 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/bin/clang+0x2960b21)
> #20 0x0000000002a5d4aa clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/bin/clang+0x2a5d4aa)
> #21 0x00000000009babc7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang+0x9babc7)
> #22 0x00000000009b8eb1 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) (/usr/bin/clang+0x9b8eb1)
> #23 0x000000000283a012 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::$_1>(long) (/usr/bin/clang+0x283a012)
> #24 0x000000000224cf5d llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/usr/bin/clang+0x224cf5d)
> #25 0x000000000283952f clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/usr/bin/clang+0x283952f)
> #26 0x000000000280bd9e clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/usr/bin/clang+0x280bd9e)
> #27 0x000000000280bf47 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/usr/bin/clang+0x280bf47)
> #28 0x0000000002822478 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/usr/bin/clang+0x2822478)
> #29 0x00000000009b893c main (/usr/bin/clang+0x9b893c)
> #30 0x00007f3bd68f70b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
> #31 0x00000000009b5f4e _start (/usr/bin/clang+0x9b5f4e)
> clang-11: error: clang frontend command failed with exit code 70 (use -v to see invocation)
> clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /usr/bin
> clang-11: note: diagnostic msg:
> ********************
> 
> PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
> Preprocessed source(s) and associated run script(s) are located at:
> clang-11: note: diagnostic msg: /tmp/sqlite3-binding-37789f.c
> clang-11: note: diagnostic msg: /tmp/sqlite3-binding-37789f.sh
> clang-11: note: diagnostic msg:
> 
```

### What did you expect to see?
Normal building , testing pipelines - at least without datal errors.


### What did you see instead?
A crash.

CC @thanm , @cherrymui 
@ianlancetaylor , maybe you can commen something.
BCC @c-bata , @danderson , @cookieo9 , @larsmans , @rittneje , @GJRTimmer, @mattn 

Ivan