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

[AVR] crash in SelectionDAG #59914

Open
benshi001 opened this issue Jan 10, 2023 · 1 comment
Open

[AVR] crash in SelectionDAG #59914

benshi001 opened this issue Jan 10, 2023 · 1 comment
Assignees

Comments

@benshi001
Copy link
Member

benshi001 commented Jan 10, 2023

The following C code leads crash

// a.c
void foo(int);
__flash const int *aff1(__flash const int *p) {
        foo(*p);
        return p + 1;
}

Command:

clang a.c -O3 -Wall -S --target=avr -mmcu=atmega328

Crash message:

/usr/include/c++/7/bits/stl_vector.h:797: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = llvm::SUnit; _Alloc = std::allocator<llvm::SUnit>; std::vector<_Tp, _Alloc>::reference = llvm::SUnit&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__builtin_expect(__n < this->size(), true)' failed.
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: ./bin/clang a.c -O3 -Wall -S --target=avr -mmcu=atmega328
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'a.c'.
4.      Running pass 'AVR DAG->DAG Instruction Selection' on function '@aff1'
 #0 0x000055fe55588aaa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./bin/clang+0x2171aaa)
 #1 0x000055fe5558677c llvm::sys::CleanupOnSignal(unsigned long) (./bin/clang+0x216f77c)
 #2 0x000055fe554e4ee8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f9b3236b420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f9b31e0800b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f9b31de7859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
 #6 0x000055fe54229b82 (./bin/clang+0xe12b82)
 #7 0x000055fe565ad63f llvm::ScheduleDAGSDNodes::AddSchedEdges() (./bin/clang+0x319663f)
 #8 0x000055fe565a8aba (anonymous namespace)::ScheduleDAGRRList::Schedule() ScheduleDAGRRList.cpp:0:0
 #9 0x000055fe564ed17a llvm::SelectionDAGISel::CodeGenAndEmitDAG() (./bin/clang+0x30d617a)
#10 0x000055fe564f0219 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (./bin/clang+0x30d9219)
#11 0x000055fe564f22be llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (.part.971) SelectionDAGISel.cpp:0:0
#12 0x000055fe54971bd2 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.72) MachineFunctionPass.cpp:0:0
#13 0x000055fe54eb42a6 llvm::FPPassManager::runOnFunction(llvm::Function&) (./bin/clang+0x1a9d2a6)
#14 0x000055fe54eb4531 llvm::FPPassManager::runOnModule(llvm::Module&) (./bin/clang+0x1a9d531)
#15 0x000055fe54eb4fc2 llvm::legacy::PassManagerImpl::run(llvm::Module&) (./bin/clang+0x1a9dfc2)
#16 0x000055fe5590bf06 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>>) (./bin/clang+0x24f4f06)
#17 0x000055fe566218c9 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) crtstuff.c:0:0
#18 0x000055fe57327359 clang::ParseAST(clang::Sema&, bool, bool) (./bin/clang+0x3f10359)
#19 0x000055fe5662241d clang::CodeGenAction::ExecuteAction() (./bin/clang+0x320b41d)
#20 0x000055fe560056a1 clang::FrontendAction::Execute() (./bin/clang+0x2bee6a1)
#21 0x000055fe55f98fea clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (./bin/clang+0x2b81fea)
#22 0x000055fe560db047 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (./bin/clang+0x2cc4047)
#23 0x000055fe5423323c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (./bin/clang+0xe1c23c)
#24 0x000055fe5422e1bf ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#25 0x000055fe55e1d015 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#26 0x000055fe554e5673 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (./bin/clang+0x20ce673)
#27 0x000055fe55e1f948 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (./bin/clang+0x2a08948)
#28 0x000055fe55dee7eb clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (./bin/clang+0x29d77eb)
#29 0x000055fe55def343 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (./bin/clang+0x29d8343)
#30 0x000055fe55df61d9 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (./bin/clang+0x29df1d9)
#31 0x000055fe54230ebd clang_main(int, char**) (./bin/clang+0xe19ebd)
#32 0x00007f9b31de9083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#33 0x000055fe5422917e _start (./bin/clang+0xe1217e)
clang-16: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 16.0.0 (git@github.com:llvm/llvm-project.git e4a7b328205e791e9eeafa85f0b19e6d062fe8cc)
Target: avr
Thread model: posix
InstalledDir: /home/benshi/work/llvm-project/build/./bin
clang-16: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-16: note: diagnostic msg: /tmp/a-7d51fa.c
clang-16: note: diagnostic msg: /tmp/a-7d51fa.sh
clang-16: note: diagnostic msg:

********************
@benshi001 benshi001 self-assigned this Jan 10, 2023
@benshi001
Copy link
Member Author

I find a workaround, if we always return false in bool AVRTargetLowering::getPostIndexedAddressParts(...), then this crash is suppressed.

@benshi001 benshi001 removed their assignment Jan 20, 2023
@benshi001 benshi001 self-assigned this Apr 7, 2023
benshi001 added a commit that referenced this issue Apr 12, 2023
We temporarily only allow post increment load/store from/to data memory,
and disable post increment load from program space.

Updates #59914

Reviewed By: mzh

Differential Revision: https://reviews.llvm.org/D147761
flemairen6 pushed a commit to Xilinx/llvm-project that referenced this issue May 10, 2023
We temporarily only allow post increment load/store from/to data memory,
and disable post increment load from program space.

Updates llvm#59914

Reviewed By: mzh

Differential Revision: https://reviews.llvm.org/D147761
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant