CTSRD-CHERI / llvm-project

Fork of LLVM adding CHERI support
49 stars 44 forks source link

Error recovery: Assertion `!D->isInvalidDecl() && "Cannot get layout of invalid decl!"' failed #616

Open acoplan-arm opened 2 years ago

acoplan-arm commented 2 years ago

CHERI LLVM crashes on the following (invalid) C code:

struct __attribute__((packed)) s {
    union {
        __intcap c;
    }
};

which is simply missing a semi-colon after the union. Backtrace:

clang: /local/scratch/jenkins/workspace/orello-LLVM-linux_morello_master/morello-llvm-project/clang/lib/AST/RecordLayoutBuilder.cpp:3240: const clang::ASTRecordLayout &clang::ASTContext::getASTRecordLayout(const clang::RecordDecl *) const: Assertion `!D->isInvalidDecl() && "Cannot get layout of invalid decl!"' failed.
PLEASE submit a bug report to https://git.morello-project.org/morello/llvm-project/-/issues and include the crash backtrace, preprocessed source, and associated run script.
If you built clang from source, please provide a reduced test case by running:
    $LLVM_BUILD_DIR/bin/creduce_crash_testcase.py <reproducer>.sh
Stack dump:
0.  Program arguments: /morello-sdk/bin/clang -g -o /tmp/compiler-explorer-compiler202245-80-kviqn5.189j/output.s -mllvm --x86-asm-syntax=intel -S -target aarch64-unknown-freebsd13 --sysroot=/morello-sdk/sysroot-morello-purecap -Wall -march=morello+c64 -mabi=purecap -fcolor-diagnostics -fno-crash-diagnostics -O2 <source>
1.  <source>:5:2: current parser token ';'
2.  <source>:1:1: parsing struct/union body 's'
 #0 0x00000000049b9abc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/morello-sdk/bin/clang+0x49b9abc)
 #1 0x00000000049b750e llvm::sys::RunSignalHandlers() (/morello-sdk/bin/clang+0x49b750e)
 #2 0x00000000049b8d7d llvm::sys::CleanupOnSignal(unsigned long) (/morello-sdk/bin/clang+0x49b8d7d)
 #3 0x0000000004921c58 (/morello-sdk/bin/clang+0x4921c58)
 #4 0x0000000004921f45 (/morello-sdk/bin/clang+0x4921f45)
 #5 0x00007f4afe9f13c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
 #6 0x00007f4afe66803b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4303b)
 #7 0x00007f4afe647859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #8 0x00007f4afe647729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #9 0x00007f4afe659006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
#10 0x0000000006f492c9 clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/morello-sdk/bin/clang+0x6f492c9)
#11 0x0000000006f4aef8 clang::ASTContext::getFieldOffset(clang::ValueDecl const*) const (/morello-sdk/bin/clang+0x6f4aef8)
#12 0x000000000631de47 (/morello-sdk/bin/clang+0x631de47)
#13 0x000000000631d54b clang::Sema::ActOnFields(clang::Scope*, clang::SourceLocation, clang::Decl*, llvm::ArrayRef<clang::Decl*>, clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributesView const&) (/morello-sdk/bin/clang+0x631d54b)
#14 0x00000000060a79d9 clang::Parser::ParseStructUnionBody(clang::SourceLocation, clang::TypeSpecifierType, clang::RecordDecl*) (/morello-sdk/bin/clang+0x60a79d9)
#15 0x00000000060e3c09 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributesWithRange&) (/morello-sdk/bin/clang+0x60e3c09)
#16 0x0000000006097b1a clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*) (/morello-sdk/bin/clang+0x6097b1a)
#17 0x000000000604944a clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/morello-sdk/bin/clang+0x604944a)
#18 0x0000000006048fda clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/morello-sdk/bin/clang+0x6048fda)
#19 0x0000000006047cc5 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (/morello-sdk/bin/clang+0x6047cc5)
#20 0x0000000006045967 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/morello-sdk/bin/clang+0x6045967)
#21 0x00000000060451bb clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) (/morello-sdk/bin/clang+0x60451bb)
#22 0x000000000603fde4 clang::ParseAST(clang::Sema&, bool, bool) (/morello-sdk/bin/clang+0x603fde4)
#23 0x000000000560ae92 clang::FrontendAction::Execute() (/morello-sdk/bin/clang+0x560ae92)
#24 0x0000000005571cb8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/morello-sdk/bin/clang+0x5571cb8)
#25 0x00000000056cc755 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/morello-sdk/bin/clang+0x56cc755)
#26 0x0000000002fc0699 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/morello-sdk/bin/clang+0x2fc0699)
#27 0x0000000002fbe4be (/morello-sdk/bin/clang+0x2fbe4be)
#28 0x00000000053c1da2 (/morello-sdk/bin/clang+0x53c1da2)
#29 0x0000000004921b1c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/morello-sdk/bin/clang+0x4921b1c)
#30 0x00000000053c190a clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (/morello-sdk/bin/clang+0x53c190a)
#31 0x000000000538097d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/morello-sdk/bin/clang+0x538097d)
#32 0x0000000005380f07 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/morello-sdk/bin/clang+0x5380f07)
#33 0x000000000539febb clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/morello-sdk/bin/clang+0x539febb)
#34 0x0000000002fbdd87 main (/morello-sdk/bin/clang+0x2fbdd87)
#35 0x00007f4afe6490b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b3)
#36 0x0000000002f16d6a _start (/morello-sdk/bin/clang+0x2f16d6a)
arichardson commented 2 years ago

I have a local patch that changes the diagnostics for packed structs that I believe will fix this crash. Will submit a PR once I've finished writing the tests.