Issue 56426
Summary [AVR] clang++ crashes when building cpp program with virtual functions
Labels backend:AVR
Assignees benshi001
Reporter benshi001
    For the following program

```
class HardwareSerial {
  public:
    virtual int available(void);
};

int HardwareSerial::available(void) {
  return 1;
}
```

Build it with command `clang++ --target=avr  -mmcu=atmega328 -O3 -S b.cc`, the following error rises

```
clang++: /home/benshi/work/llvm-project/llvm/lib/IR/Constants.cpp:2201: static llvm::Constant* llvm::ConstantExpr::getBitCast(llvm::Constant*, llvm::Type*, bool): Assertion `CastInst::castIsValid(Instruction::BitCast, C, DstTy) && "Invalid constantexpr bitcast!"' 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: /home/benshi/work/llvm-project/debug/bin/clang++ --target=avr -mmcu=atmega328 -O3 -S b.cc
1.      <eof> parser at end of file
 #0 0x00005630417461f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/benshi/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:569:22
 #1 0x00005630417462b3 PrintStackTraceSignalHandler(void*) /home/benshi/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:636:1
 #2 0x0000563041743e1a llvm::sys::RunSignalHandlers() /home/benshi/work/llvm-project/llvm/lib/Support/Signals.cpp:103:20
 #3 0x0000563041745a05 llvm::sys::CleanupOnSignal(unsigned long) /home/benshi/work/llvm-project/llvm/lib/Support/Unix/Signals.inc:361:31
 #4 0x0000563041666904 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/benshi/work/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:76:5
 #5 0x0000563041666e3d CrashRecoverySignalHandler(int) /home/benshi/work/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:390:1
 #6 0x00007ff69c588420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #7 0x00007ff69c02500b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #8 0x00007ff69c004859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
 #9 0x00007ff69c004729 get_sysdep_segment_value /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:509:8
#10 0x00007ff69c004729 _nl_load_domain /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:970:34
#11 0x00007ff69c015fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#12 0x0000563040aca147 llvm::ConstantExpr::getBitCast(llvm::Constant*, llvm::Type*, bool) /home/benshi/work/llvm-project/llvm/lib/IR/Constants.cpp:2201:3
#13 0x0000563041ee5429 clang::CodeGen::CodeGenVTables::addVTableComponent(clang::CodeGen::ConstantArrayBuilder&, clang::VTableLayout const&, unsigned int, llvm::Constant*, unsigned int&, unsigned int, bool) /home/benshi/work/llvm-project/clang/lib/CodeGen/CGVTables.cpp:812:25
#14 0x0000563041ee5721 clang::CodeGen::CodeGenVTables::createVTableInitializer(clang::CodeGen::ConstantStructBuilder&, clang::VTableLayout const&, llvm::Constant*, bool) /home/benshi/work/llvm-project/clang/lib/CodeGen/CGVTables.cpp:850:25
#15 0x00005630420b45d9 (anonymous namespace)::ItaniumCXXABI::emitVTableDefinitions(clang::CodeGen::CodeGenVTables&, clang::CXXRecordDecl const*) /home/benshi/work/llvm-project/clang/lib/CodeGen/ItaniumCXXABI.cpp:1729:39
#16 0x0000563041ee6559 clang::CodeGen::CodeGenVTables::GenerateClassData(clang::CXXRecordDecl const*) /home/benshi/work/llvm-project/clang/lib/CodeGen/CGVTables.cpp:1101:1
#17 0x0000563041ee64aa clang::CodeGen::CodeGenModule::EmitVTable(clang::CXXRecordDecl*) /home/benshi/work/llvm-project/clang/lib/CodeGen/CGVTables.cpp:1090:1
#18 0x000056304315c3c8 (anonymous namespace)::CodeGeneratorImpl::HandleVTable(clang::CXXRecordDecl*) /home/benshi/work/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:317:26
#19 0x0000563043153dbc clang::BackendConsumer::HandleVTable(clang::CXXRecordDecl*) /home/benshi/work/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:414:5
#20 0x00005630454f158a clang::Sema::DefineUsedVTables() /home/benshi/work/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:17855:9
#21 0x0000563045178785 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) /home/benshi/work/llvm-project/clang/lib/Sema/Sema.cpp:1069:7
#22 0x0000563045178bd8 clang::Sema::ActOnEndOfTranslationUnit() /home/benshi/work/llvm-project/clang/lib/Sema/Sema.cpp:1124:9
#23 0x000056304500b305 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/benshi/work/llvm-project/clang/lib/Parse/Parser.cpp:703:12
#24 0x00005630450068db clang::ParseAST(clang::Sema&, bool, bool) /home/benshi/work/llvm-project/clang/lib/Parse/ParseAST.cpp:162:37
#25 0x00005630427a7017 clang::ASTFrontendAction::ExecuteAction() /home/benshi/work/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1143:11
#26 0x0000563043150018 clang::CodeGenAction::ExecuteAction() /home/benshi/work/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:1143:5
#27 0x00005630427a68d6 clang::FrontendAction::Execute() /home/benshi/work/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1040:38
#28 0x00005630426d7a2d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/benshi/work/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1033:42
#29 0x00005630429537d5 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/benshi/work/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:266:38
#30 0x000056303f8b1c41 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/benshi/work/llvm-project/clang/tools/driver/cc1_main.cpp:248:40
#31 0x000056303f8a22a2 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) /home/benshi/work/llvm-project/clang/tools/driver/driver.cpp:317:20
#32 0x0000563042595739 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()::operator()() const /home/benshi/work/llvm-project/clang/lib/Driver/Job.cpp:407:32
#33 0x0000563042595d68 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::'lambda'()>(long) /home/benshi/work/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40
#34 0x0000563040192a3e llvm::function_ref<void ()>::operator()() const /home/benshi/work/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62
#35 0x0000563041667050 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /home/benshi/work/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:426:10
#36 0x0000563042595957 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/benshi/work/llvm-project/clang/lib/Driver/Job.cpp:407:7
#37 0x0000563042534c30 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /home/benshi/work/llvm-project/clang/lib/Driver/Compilation.cpp:200:22
#38 0x0000563042534fbe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const /home/benshi/work/llvm-project/clang/lib/Driver/Compilation.cpp:254:62
#39 0x00005630425464f1 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) /home/benshi/work/llvm-project/clang/lib/Driver/Driver.cpp:1738:28
#40 0x000056303f8a37ab clang_main(int, char**) /home/benshi/work/llvm-project/clang/tools/driver/driver.cpp:513:39
#41 0x000056303f8a0add main /home/benshi/work/llvm-project/debug/tools/clang/tools/driver/clang-driver.cpp:11:63
#42 0x00007ff69c006083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#43 0x000056303f8a09fe _start (/home/benshi/work/llvm-project/debug/bin/clang+++0x2c729fe)
clang-15: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 15.0.0 ([email protected]:llvm/llvm-project.git ac77649951db17f1126bde08d580ec101f0759bc)
Target: avr
Thread model: posix
InstalledDir: /home/benshi/work/llvm-project/debug/bin
clang-15: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-15: note: diagnostic msg: /tmp/b-59a4ba.cpp
clang-15: note: diagnostic msg: /tmp/b-59a4ba.sh
clang-15: note: diagnostic msg:

********************
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to