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

Crash in Clang 17 front-end for code that previously worked #67317

Closed
andreasfertig opened this issue Sep 25, 2023 · 6 comments · Fixed by #67817
Closed

Crash in Clang 17 front-end for code that previously worked #67317

andreasfertig opened this issue Sep 25, 2023 · 6 comments · Fixed by #67817
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-valid release:backport release:merged

Comments

@andreasfertig
Copy link
Contributor

Hello,

the following code which is a reduced test case from C++ Insights (https://github.com/andreasfertig/cppinsights/blob/9147b894b814a3d7dcf82ac9b16965680baffeb1/tests/FieldDeclArrayRef2Test.cpp) leads to a crash in the front-end with Clang 17 while it worked with the previous versions (https://compiler-explorer.com/z/c51Gxj7b5):

struct array
{
    int (&data)[2];
    array() : data(*new int[1][2]) { }
};

int main()
{
    array a;
}
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-17.0.1/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -emit-llvm -Xclang -disable-llvm-passes <source>
1.	<source>:4:36: current parser token '{'
2.	<source>:1:1: parsing struct/union/class body 'array'
 #0 0x0000000003349f18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3349f18)
 #1 0x0000000003348044 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3348044)
 #2 0x000000000329c028 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fe7b1587420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x0000000006950cec CheckEvaluationResult(CheckEvaluationResultKind, (anonymous namespace)::EvalInfo&, clang::SourceLocation, clang::QualType, clang::APValue const&, clang::Expr::ConstantExprKind, clang::FieldDecl const*, llvm::SmallPtrSet<clang::MaterializeTemporaryExpr const*, 8u>&) ExprConstant.cpp:0:0
 #5 0x0000000006950b31 CheckEvaluationResult(CheckEvaluationResultKind, (anonymous namespace)::EvalInfo&, clang::SourceLocation, clang::QualType, clang::APValue const&, clang::Expr::ConstantExprKind, clang::FieldDecl const*, llvm::SmallPtrSet<clang::MaterializeTemporaryExpr const*, 8u>&) ExprConstant.cpp:0:0
 #6 0x00000000069623bb (anonymous namespace)::ExtractSubobjectHandler::result_type findSubobject<(anonymous namespace)::ExtractSubobjectHandler>((anonymous namespace)::EvalInfo&, clang::Expr const*, (anonymous namespace)::CompleteObject const&, (anonymous namespace)::SubobjectDesignator const&, (anonymous namespace)::ExtractSubobjectHandler&) ExprConstant.cpp:0:0
 #7 0x000000000696e927 handleLValueToRValueConversion((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::QualType, (anonymous namespace)::LValue const&, clang::APValue&, bool) ExprConstant.cpp:0:0
 #8 0x000000000696eeae EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) ExprConstant.cpp:0:0
 #9 0x00000000069700b7 clang::Expr::EvaluateForOverflow(clang::ASTContext const&) const (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x69700b7)
#10 0x0000000005a8eeb5 clang::Sema::CheckForIntOverflow(clang::Expr const*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5a8eeb5)
#11 0x0000000005ae6f63 clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5ae6f63)
#12 0x0000000005f632d2 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5f632d2)
#13 0x0000000005cb9fc3 clang::Sema::BuildMemberInitializer(clang::ValueDecl*, clang::Expr*, clang::SourceLocation) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5cb9fc3)
#14 0x0000000005cddcef clang::Sema::BuildMemInitializer(clang::Decl*, clang::Scope*, clang::CXXScopeSpec&, clang::IdentifierInfo*, clang::OpaquePtr<clang::QualType>, clang::DeclSpec const&, clang::SourceLocation, clang::Expr*, clang::SourceLocation) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5cddcef)
#15 0x000000000590d942 clang::Parser::ParseMemInitializer(clang::Decl*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x590d942)
#16 0x00000000059114b8 clang::Parser::ParseConstructorInitializer(clang::Decl*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x59114b8)
#17 0x00000000058d0fd0 clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58d0fd0)
#18 0x00000000058d093d clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58d093d)
#19 0x000000000591ec68 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x591ec68)
#20 0x0000000005920dd1 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5920dd1)
#21 0x00000000058f15b4 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58f15b4)
#22 0x00000000058c519d clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58c519d)
#23 0x00000000058c632f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#24 0x00000000058cda8f clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58cda8f)
#25 0x00000000058cef0a clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58cef0a)
#26 0x00000000058cf470 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58cf470)
#27 0x00000000058be922 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58be922)
#28 0x00000000044f8b05 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x44f8b05)
#29 0x0000000003dd5f21 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3dd5f21)
#30 0x0000000003d5b9fb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3d5b9fb)
#31 0x0000000003eb5c23 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3eb5c23)
#32 0x0000000000bd50c5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0xbd50c5)
#33 0x0000000000bce42d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#34 0x0000000003ba7489 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
#35 0x000000000329c453 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x329c453)
#36 0x0000000003ba76a9 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
#37 0x0000000003b6f477 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3b6f477)
#38 0x0000000003b6fe2d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3b6fe2d)
#39 0x0000000003b79d0c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3b79d0c)
#40 0x0000000000bd2d31 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0xbd2d31)
#41 0x0000000000acf511 main (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0xacf511)
#42 0x00007fe7b102b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#43 0x0000000000bcdc2e _start (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0xbcdc2e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

Andreas

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Sep 25, 2023
@tbaederr tbaederr added confirmed Verified by a second party crash-on-valid labels Sep 25, 2023
@tbaederr
Copy link
Contributor

Assertion is:

clang-17: /home/tbaeder/code/llvm-project/clang/lib/AST/ExprConstant.cpp:2414: bool CheckEvaluationResult(CheckEvaluationResultKind, EvalInfo &, SourceLocation, QualType, const APValue &, ConstantExprKind, const FieldDecl *, CheckedTemporaries &): Assertion `SubobjectDecl && "SubobjectDecl shall be non-null"' failed.

@hazohelet

@cor3ntin cor3ntin added clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed clang Clang issues not falling into any other category labels Sep 26, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 26, 2023

@llvm/issue-subscribers-clang-frontend

Hello,

the following code which is a reduced test case from C++ Insights (https://github.com/andreasfertig/cppinsights/blob/9147b894b814a3d7dcf82ac9b16965680baffeb1/tests/FieldDeclArrayRef2Test.cpp) leads to a crash in the front-end with Clang 17 while it worked with the previous versions (https://compiler-explorer.com/z/c51Gxj7b5):

struct array
{
    int (&amp;data)[2];
    array() : data(*new int[1][2]) { }
};

int main()
{
    array a;
}
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-17.0.1/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -emit-llvm -Xclang -disable-llvm-passes &lt;source&gt;
1.	&lt;source&gt;:4:36: current parser token '{'
2.	&lt;source&gt;:1:1: parsing struct/union/class body 'array'
 #<!-- -->0 0x0000000003349f18 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3349f18)
 #<!-- -->1 0x0000000003348044 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3348044)
 #<!-- -->2 0x000000000329c028 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #<!-- -->3 0x00007fe7b1587420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #<!-- -->4 0x0000000006950cec CheckEvaluationResult(CheckEvaluationResultKind, (anonymous namespace)::EvalInfo&amp;, clang::SourceLocation, clang::QualType, clang::APValue const&amp;, clang::Expr::ConstantExprKind, clang::FieldDecl const*, llvm::SmallPtrSet&lt;clang::MaterializeTemporaryExpr const*, 8u&gt;&amp;) ExprConstant.cpp:0:0
 #<!-- -->5 0x0000000006950b31 CheckEvaluationResult(CheckEvaluationResultKind, (anonymous namespace)::EvalInfo&amp;, clang::SourceLocation, clang::QualType, clang::APValue const&amp;, clang::Expr::ConstantExprKind, clang::FieldDecl const*, llvm::SmallPtrSet&lt;clang::MaterializeTemporaryExpr const*, 8u&gt;&amp;) ExprConstant.cpp:0:0
 #<!-- -->6 0x00000000069623bb (anonymous namespace)::ExtractSubobjectHandler::result_type findSubobject&lt;(anonymous namespace)::ExtractSubobjectHandler&gt;((anonymous namespace)::EvalInfo&amp;, clang::Expr const*, (anonymous namespace)::CompleteObject const&amp;, (anonymous namespace)::SubobjectDesignator const&amp;, (anonymous namespace)::ExtractSubobjectHandler&amp;) ExprConstant.cpp:0:0
 #<!-- -->7 0x000000000696e927 handleLValueToRValueConversion((anonymous namespace)::EvalInfo&amp;, clang::Expr const*, clang::QualType, (anonymous namespace)::LValue const&amp;, clang::APValue&amp;, bool) ExprConstant.cpp:0:0
 #<!-- -->8 0x000000000696eeae EvaluateAsRValue((anonymous namespace)::EvalInfo&amp;, clang::Expr const*, clang::APValue&amp;) ExprConstant.cpp:0:0
 #<!-- -->9 0x00000000069700b7 clang::Expr::EvaluateForOverflow(clang::ASTContext const&amp;) const (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x69700b7)
#<!-- -->10 0x0000000005a8eeb5 clang::Sema::CheckForIntOverflow(clang::Expr const*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5a8eeb5)
#<!-- -->11 0x0000000005ae6f63 clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5ae6f63)
#<!-- -->12 0x0000000005f632d2 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5f632d2)
#<!-- -->13 0x0000000005cb9fc3 clang::Sema::BuildMemberInitializer(clang::ValueDecl*, clang::Expr*, clang::SourceLocation) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5cb9fc3)
#<!-- -->14 0x0000000005cddcef clang::Sema::BuildMemInitializer(clang::Decl*, clang::Scope*, clang::CXXScopeSpec&amp;, clang::IdentifierInfo*, clang::OpaquePtr&lt;clang::QualType&gt;, clang::DeclSpec const&amp;, clang::SourceLocation, clang::Expr*, clang::SourceLocation) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5cddcef)
#<!-- -->15 0x000000000590d942 clang::Parser::ParseMemInitializer(clang::Decl*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x590d942)
#<!-- -->16 0x00000000059114b8 clang::Parser::ParseConstructorInitializer(clang::Decl*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x59114b8)
#<!-- -->17 0x00000000058d0fd0 clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&amp;) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58d0fd0)
#<!-- -->18 0x00000000058d093d clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&amp;) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58d093d)
#<!-- -->19 0x000000000591ec68 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&amp;, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x591ec68)
#<!-- -->20 0x0000000005920dd1 clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&amp;, clang::Parser::ParsedTemplateInfo const&amp;, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&amp;) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x5920dd1)
#<!-- -->21 0x00000000058f15b4 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&amp;, clang::Parser::ParsedTemplateInfo const&amp;, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58f15b4)
#<!-- -->22 0x00000000058c519d clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec&amp;, clang::AccessSpecifier) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58c519d)
#<!-- -->23 0x00000000058c632f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#<!-- -->24 0x00000000058cda8f clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&amp;, clang::ParsedAttributes&amp;, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58cda8f)
#<!-- -->25 0x00000000058cef0a clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58cef0a)
#<!-- -->26 0x00000000058cf470 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58cf470)
#<!-- -->27 0x00000000058be922 clang::ParseAST(clang::Sema&amp;, bool, bool) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x58be922)
#<!-- -->28 0x00000000044f8b05 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x44f8b05)
#<!-- -->29 0x0000000003dd5f21 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3dd5f21)
#<!-- -->30 0x0000000003d5b9fb clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3d5b9fb)
#<!-- -->31 0x0000000003eb5c23 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3eb5c23)
#<!-- -->32 0x0000000000bd50c5 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0xbd50c5)
#<!-- -->33 0x0000000000bce42d ExecuteCC1Tool(llvm::SmallVectorImpl&lt;char const*&gt;&amp;, llvm::ToolContext const&amp;) driver.cpp:0:0
#<!-- -->34 0x0000000003ba7489 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const::'lambda'()&gt;(long) Job.cpp:0:0
#<!-- -->35 0x000000000329c453 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref&lt;void ()&gt;) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x329c453)
#<!-- -->36 0x0000000003ba76a9 clang::driver::CC1Command::Execute(llvm::ArrayRef&lt;std::optional&lt;llvm::StringRef&gt;&gt;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;*, bool*) const (.part.0) Job.cpp:0:0
#<!-- -->37 0x0000000003b6f477 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&amp;, clang::driver::Command const*&amp;, bool) const (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3b6f477)
#<!-- -->38 0x0000000003b6fe2d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3b6fe2d)
#<!-- -->39 0x0000000003b79d0c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&amp;, llvm::SmallVectorImpl&lt;std::pair&lt;int, clang::driver::Command const*&gt;&gt;&amp;) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0x3b79d0c)
#<!-- -->40 0x0000000000bd2d31 clang_main(int, char**, llvm::ToolContext const&amp;) (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0xbd2d31)
#<!-- -->41 0x0000000000acf511 main (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0xacf511)
#<!-- -->42 0x00007fe7b102b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#<!-- -->43 0x0000000000bcdc2e _start (/opt/compiler-explorer/clang-17.0.1/bin/clang+++0xbcdc2e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139

Andreas

@hazohelet
Copy link
Member

Relevant patch: https://reviews.llvm.org/D146358

The crash is happening in UB-checking use of constexpr evaluator, where it evaluates the expression *new int[1][3] as rvalue.
Evaluating uninitialized arrays as rvalue fails because it's indeed uninitialized, and the uninitialized subobjects do not have names like struct subobjects do, thus the crash. So the proper solution here would be to fallback to the old diagnostic subobject of type T is not initialized so as not to see any more regressions from the assertion. I'll upload PR soon.

One weird thing is that I cannot get the old diagnostics for this crashing case printed. I cannot reproduce the crash from non-UB-checking use of constexpr evaluator. Falling back to the old diagnostics would be generally good, but I'm a little concerned that it may end up generating diagnostics that no one is going to see.

About the UB-checking usage,

if (isa<BinaryOperator, UnaryOperator>(E)) {
E->EvaluateForOverflow(Context);
continue;
}
looks questionable because it determines to evaluate expression as rvalue whenever the AST is BinaryOperator or UnaryOperator, while the intention seems to be to detect overflow from arithmetic operations like a + b or ++a. I tinkered this part a little bit yesterday and reported 4 crashses, all of which seemed to be caused by other unhealthy codes, so this piece of code would probably be OK.

hazohelet added a commit to hazohelet/llvm-project that referenced this issue Oct 27, 2023
https://reviews.llvm.org/D146358 was assuming that all subobjects have
their own name (`SubobjectDecl`), but it was not true for array
elements.

Fixes llvm#67317
@hazohelet hazohelet added this to the LLVM 17.0.X Release milestone Oct 27, 2023
@hazohelet hazohelet reopened this Oct 27, 2023
@hazohelet
Copy link
Member

/branch hazohelet/llvm-project/release/17.x

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 27, 2023

/pull-request llvm/llvm-project-release-prs#751

@sunshaoce
Copy link
Contributor

I'm sorry, the error was caused by my mistake.

@sunshaoce sunshaoce reopened this Oct 30, 2023
hazohelet added a commit to hazohelet/llvm-project that referenced this issue Oct 30, 2023
…7817)

https://reviews.llvm.org/D146358 was assuming that all subobjects have
their own name (`SubobjectDecl`), but it was not true for array
elements.

Fixes llvm#67317
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" confirmed Verified by a second party crash-on-valid release:backport release:merged
Projects
7 participants