CE-Programming / toolchain

Toolchain and libraries for C/C++ programming on the TI-84+ CE calculator series
https://ce-programming.github.io/toolchain/index.html
GNU Lesser General Public License v3.0
511 stars 54 forks source link

Unable to legalize instruction #501

Closed nathanfarlow closed 4 weeks ago

nathanfarlow commented 4 weeks ago

Hello, Compiling the following code yields an error when -O1 or higher is passed. -Oz works, however. Seems that it might be related to this issue.

bug.tar.gz

[compiling] src/main.c
[lto opt] obj/lto.bc
fatal error: error in backend: unable to legalize instruction: %55:_(s48) = G_LSHR %53:_, %56:_(s8) (in function: caml_copy_string)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /home/nathan/CEdev/bin/ez80-clang -S -mllvm -profile-guided-section-prefix=false -Wall -Wextra -O1 -Wno-unused-parameter -Wno-unused-parameter -Wno-unused-variable -Wno-unused-label /home/nathan/repro/obj/lto.bc -o /home/nathan/repro/obj/lto.src
1.      Code generation
2.      Running pass 'Function Pass Manager' on module '/home/nathan/repro/obj/lto.bc'.
3.      Running pass 'Legalizer' on function '@caml_copy_string'
 #0 0x000000000201d593 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/nathan/CEdev/bin/ez80-clang+0x201d593)
 #1 0x000000000201b4be llvm::sys::RunSignalHandlers() (/home/nathan/CEdev/bin/ez80-clang+0x201b4be)
 #2 0x000000000201cabd llvm::sys::CleanupOnSignal(unsigned long) (/home/nathan/CEdev/bin/ez80-clang+0x201cabd)
 #3 0x0000000001f951da (/home/nathan/CEdev/bin/ez80-clang+0x1f951da)
 #4 0x0000000001f9517b (/home/nathan/CEdev/bin/ez80-clang+0x1f9517b)
 #5 0x0000000002017877 llvm::sys::Process::Exit(int, bool) (/home/nathan/CEdev/bin/ez80-clang+0x2017877)
 #6 0x00000000011d0dc2 (/home/nathan/CEdev/bin/ez80-clang+0x11d0dc2)
 #7 0x0000000001f98de8 llvm::report_fatal_error(llvm::Twine const&, bool) (/home/nathan/CEdev/bin/ez80-clang+0x1f98de8)
 #8 0x0000000002de5354 (/home/nathan/CEdev/bin/ez80-clang+0x2de5354)
 #9 0x0000000002de567d llvm::reportGISelFailure(llvm::MachineFunction&, llvm::TargetPassConfig const&, llvm::MachineOptimizationRemarkEmitter&, char const*, llvm::StringRef, llvm::MachineInstr const&) (/home/nathan/CEdev/bin/ez80-clang+0x2de567d)
#10 0x0000000002d8d525 llvm::Legalizer::runOnMachineFunction(llvm::MachineFunction&) (/home/nathan/CEdev/bin/ez80-clang+0x2d8d525)
#11 0x0000000001595b9e llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/nathan/CEdev/bin/ez80-clang+0x1595b9e)
#12 0x0000000001959e3d llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/nathan/CEdev/bin/ez80-clang+0x1959e3d)
#13 0x000000000195fab3 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/nathan/CEdev/bin/ez80-clang+0x195fab3)
#14 0x000000000195a47f llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/nathan/CEdev/bin/ez80-clang+0x195a47f)
#15 0x000000000229dcc4 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/home/nathan/CEdev/bin/ez80-clang+0x229dcc4)
#16 0x0000000002b0561e clang::CodeGenAction::ExecuteAction() (/home/nathan/CEdev/bin/ez80-clang+0x2b0561e)
#17 0x0000000002a59657 clang::FrontendAction::Execute() (/home/nathan/CEdev/bin/ez80-clang+0x2a59657)
#18 0x00000000029d0e56 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/nathan/CEdev/bin/ez80-clang+0x29d0e56)
#19 0x0000000002b0101b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/nathan/CEdev/bin/ez80-clang+0x2b0101b)
#20 0x00000000011d0a78 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/nathan/CEdev/bin/ez80-clang+0x11d0a78)
#21 0x00000000011cebab (/home/nathan/CEdev/bin/ez80-clang+0x11cebab)
#22 0x0000000002858df2 (/home/nathan/CEdev/bin/ez80-clang+0x2858df2)
#23 0x0000000001f9515d llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/nathan/CEdev/bin/ez80-clang+0x1f9515d)
#24 0x0000000002858924 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (/home/nathan/CEdev/bin/ez80-clang+0x2858924)
#25 0x000000000281be94 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/home/nathan/CEdev/bin/ez80-clang+0x281be94)
#26 0x000000000281c327 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) const (/home/nathan/CEdev/bin/ez80-clang+0x281c327)
#27 0x0000000002838aa8 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/home/nathan/CEdev/bin/ez80-clang+0x2838aa8)
#28 0x00000000011ce2b7 main (/home/nathan/CEdev/bin/ez80-clang+0x11ce2b7)
#29 0x000077f4caa2a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#30 0x000077f4caa2a28b call_init ./csu/../csu/libc-start.c:128:20
#31 0x000077f4caa2a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#32 0x00000000011cb8ae _start (/home/nathan/CEdev/bin/ez80-clang+0x11cb8ae)
ez80-clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 15.0.0 (https://github.com/jacobly0/llvm-project 5f8512f22751066573aa48ac848a6d2195838ac3)
Target: ez80
Thread model: posix
InstalledDir: /home/nathan/CEdev/bin
ez80-clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
make: *** [/home/nathan/CEdev/meta/makefile.mk:329: obj/lto.src] Error 1
nathanfarlow commented 4 weeks ago

This looks like a small repo of the original issue:

int main(int a) { return a / sizeof(int); }
nathanfarlow commented 4 weeks ago

I followed the instructions here to build ez80-clang from source. That fixed things. To confirm that I was using the newest version of the toolchain previously, I redownloaded the archive from here. This caused the error to reappear. Is that page out of date?

adriweb commented 4 weeks ago

There's also the compiler nightly here https://github.com/CE-Programming/llvm-project/releases/tag/nightly

but yes the toolchain needs a new version anyway.