Issue 203755
Summary [clang][constexpr] Assertion `!D->isInvalidDecl() && "Cannot get layout of invalid decl!"' failed.` on invalid struct with __builtin_bit_cast
Labels clang
Assignees
Reporter hongtaihu
    This input is generated by a fuzzer.
https://godbolt.org/z/8Kbva6aYP
```cxx
 struct a :;
  constexpr struct {
  } b;
  a c = __builtin_bit_cast(a, b)
```
seems to be introduced since clang 16.0.0

stacktrace
```
<source>:1:12: error: expected '{' after base class list
clang++: /root/llvm-project/clang/lib/AST/RecordLayoutBuilder.cpp:3289: 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://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-16.0.0/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-12.2.0 -fcolor-diagnostics -fno-crash-diagnostics -fsyntax-only <source>
1.	<eof> parser at end of file
 #0 0x000062e5b3eb932f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x412e32f)
 #1 0x000062e5b3eb72cc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x412c2cc)
 #2 0x000062e5b3e03fb8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007688bd645330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x00007688bd69eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
 #5 0x00007688bd64527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #6 0x00007688bd6288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #7 0x00007688bd62881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #8 0x00007688bd63b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
 #9 0x000062e5b77d4d8f clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x7a49d8f)
#10 0x000062e5b75eee50 (anonymous namespace)::BufferToAPValueConverter::visitType(clang::QualType, clang::CharUnits) ExprConstant.cpp:0:0
#11 0x000062e5b760dfd8 (anonymous namespace)::handleLValueToRValueBitCast((anonymous namespace)::EvalInfo&, clang::APValue&, clang::APValue&, clang::CastExpr const*) (.part.0) ExprConstant.cpp:0:0
#12 0x000062e5b7661076 (anonymous namespace)::ExprEvaluatorBase<(anonymous namespace)::RecordExprEvaluator>::VisitCastExpr(clang::CastExpr const*) ExprConstant.cpp:0:0
#13 0x000062e5b7661197 (anonymous namespace)::RecordExprEvaluator::VisitCastExpr(clang::CastExpr const*) ExprConstant.cpp:0:0
#14 0x000062e5b765d5e5 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::RecordExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#15 0x000062e5b765eda4 EvaluateRecord(clang::Expr const*, (anonymous namespace)::LValue const&, clang::APValue&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#16 0x000062e5b766839b clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x78dd39b)
#17 0x000062e5b752adf2 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x779fdf2)
#18 0x000062e5b752b1d9 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x77a01d9)
#19 0x000062e5b68768d5 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x6aeb8d5)
#20 0x000062e5b688e607 clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x6b03607)
#21 0x000062e5b656373e clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x67d873e)
#22 0x000062e5b6574a28 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x67e9a28)
#23 0x000062e5b653ee82 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x67b3e82)
#24 0x000062e5b653f72f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#25 0x000062e5b6544e89 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x67b9e89)
#26 0x000062e5b6545e2d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x67bae2d)
#27 0x000062e5b653a1ba clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x67af1ba)
#28 0x000062e5b4aa6659 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x4d1b659)
#29 0x000062e5b4a2d1ee clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x4ca21ee)
#30 0x000062e5b4b8da83 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x4e02a83)
#31 0x000062e5b12e42a6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x15592a6)
#32 0x000062e5b12e0397 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#33 0x000062e5b48953b9 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
#34 0x000062e5b3e044a0 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x40794a0)
#35 0x000062e5b4895c6f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#36 0x000062e5b485e30c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x4ad330c)
#37 0x000062e5b485ed8d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x4ad3d8d)
#38 0x000062e5b4867f5c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x4adcf5c)
#39 0x000062e5b12e29f2 clang_main(int, char**) (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x15579f2)
#40 0x00007688bd62a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#41 0x00007688bd62a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#42 0x000062e5b12db07e _start (/opt/compiler-explorer/clang-assertions-16.0.0/bin/clang+++0x155007e)
clang-16: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```


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

Reply via email to