[clang] Assertion `E->isPRValue() && E->getType()->isIntegralOrEnumerationType()' failed with constexpr __builtin_assume_aligned
Clang assertion builds on x86-64 crash with the following C++ testcase:
Reproducer: https://godbolt.org/z/3jjn71nGE
constexpr int a = (4);
int n;
constexpr void *q1 = __builtin_assume_aligned(&n, a, 2);
Backtrace:
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ExprConstant.cpp:16158: bool EvaluateIntegerOrLValue(const clang::Expr*, clang::APValue&, {anonymous}::EvalInfo&): Assertion `E->isPRValue() && E->getType()->isIntegralOrEnumerationType()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1. <source>:5:56: current parser token ';'
#0 0x0000000004468688 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4468688)
#1 0x0000000004465534 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4465534)
#2 0x0000000004465b6c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4465b6c)
#3 0x00000000043a4448 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000760115e45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000760115e9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#6 0x0000760115e4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x0000760115e288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x0000760115e2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x0000760115e3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x000000000819a1e4 EvaluateInteger(clang::Expr const*, llvm::APSInt&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#11 0x000000000819c773 getAlignmentArgument(clang::Expr const*, clang::QualType, (anonymous namespace)::EvalInfo&, llvm::APSInt&) ExprConstant.cpp:0:0
#12 0x00000000081e9527 (anonymous namespace)::PointerExprEvaluator::VisitBuiltinCallExpr(clang::CallExpr const*, unsigned int) ExprConstant.cpp:0:0
#13 0x00000000081eabbb (anonymous namespace)::PointerExprEvaluator::VisitCallExpr(clang::CallExpr const*) ExprConstant.cpp:0:0
#14 0x00000000081643d9 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::PointerExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#15 0x0000000008165ff7 EvaluatePointer(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) ExprConstant.cpp:0:0
#16 0x000000000816a255 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#17 0x000000000818036b EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) (.part.0) ExprConstant.cpp:0:0
#18 0x00000000081e6d35 clang::Expr::EvaluateAsInitializer(clang::ASTContext const&, clang::VarDecl const*, clang::Expr::EvalResult&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x81e6d35)
#19 0x0000000007fbf317 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>*, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7fbf317)
#20 0x0000000007fbf502 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7fbf502)
#21 0x00000000071971c2 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71971c2)
#22 0x00000000071ab13a clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71ab13a)
#23 0x0000000006dc3081 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dc3081)
#24 0x0000000006de3219 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de3219)
#25 0x0000000006d8e64b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8e64b)
#26 0x0000000006d8ee3f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8ee3f)
#27 0x0000000006d9b5f8 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9b5f8)
#28 0x0000000006d9c555 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9c555)
#29 0x0000000006d794aa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d794aa)
#30 0x0000000004f62718 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f62718)
#31 0x000000000528edf8 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x528edf8)
#32 0x000000000521bf8d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x521bf8d)
#33 0x0000000005364abd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5364abd)
#34 0x0000000000dabaac cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdabaac)
#35 0x0000000000da26ca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#36 0x0000000000da284d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#37 0x0000000004fdb1f9 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
#38 0x00000000043a4884 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43a4884)
#39 0x0000000004fdbd65 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
#40 0x0000000004f93c12 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f93c12)
#41 0x0000000004f98577 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f98577)
#42 0x0000000004fa2ae5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fa2ae5)
#43 0x0000000000da7faa clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda7faa)
#44 0x0000000000cc3c5a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc3c5a)
#45 0x0000760115e2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#46 0x0000760115e2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#47 0x0000000000da2075 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda2075)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
This reproduces on x86-64 Clang trunk and can be traced back to Clang 16.0.0. This testcase was generated by fuzzer.
@llvm/issue-subscribers-clang-frontend
Author: RainFly (RainFly-code)
Reproducer: https://godbolt.org/z/3jjn71nGE
constexpr int a = (4);
int n;
constexpr void *q1 = __builtin_assume_aligned(&n, a, 2);
Backtrace:
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ExprConstant.cpp:16158: bool EvaluateIntegerOrLValue(const clang::Expr*, clang::APValue&, {anonymous}::EvalInfo&): Assertion `E->isPRValue() && E->getType()->isIntegralOrEnumerationType()' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1. <source>:5:56: current parser token ';'
#<!-- -->0 0x0000000004468688 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4468688)
#<!-- -->1 0x0000000004465534 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4465534)
#<!-- -->2 0x0000000004465b6c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4465b6c)
#<!-- -->3 0x00000000043a4448 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#<!-- -->4 0x0000760115e45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#<!-- -->5 0x0000760115e9ec0c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9ec0c)
#<!-- -->6 0x0000760115e4527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#<!-- -->7 0x0000760115e288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#<!-- -->8 0x0000760115e2881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#<!-- -->9 0x0000760115e3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#<!-- -->10 0x000000000819a1e4 EvaluateInteger(clang::Expr const*, llvm::APSInt&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#<!-- -->11 0x000000000819c773 getAlignmentArgument(clang::Expr const*, clang::QualType, (anonymous namespace)::EvalInfo&, llvm::APSInt&) ExprConstant.cpp:0:0
#<!-- -->12 0x00000000081e9527 (anonymous namespace)::PointerExprEvaluator::VisitBuiltinCallExpr(clang::CallExpr const*, unsigned int) ExprConstant.cpp:0:0
#<!-- -->13 0x00000000081eabbb (anonymous namespace)::PointerExprEvaluator::VisitCallExpr(clang::CallExpr const*) ExprConstant.cpp:0:0
#<!-- -->14 0x00000000081643d9 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::PointerExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#<!-- -->15 0x0000000008165ff7 EvaluatePointer(clang::Expr const*, (anonymous namespace)::LValue&, (anonymous namespace)::EvalInfo&, bool) ExprConstant.cpp:0:0
#<!-- -->16 0x000000000816a255 Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) ExprConstant.cpp:0:0
#<!-- -->17 0x000000000818036b EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) (.part.0) ExprConstant.cpp:0:0
#<!-- -->18 0x00000000081e6d35 clang::Expr::EvaluateAsInitializer(clang::ASTContext const&, clang::VarDecl const*, clang::Expr::EvalResult&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x81e6d35)
#<!-- -->19 0x0000000007fbf317 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>*, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7fbf317)
#<!-- -->20 0x0000000007fbf502 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7fbf502)
#<!-- -->21 0x00000000071971c2 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71971c2)
#<!-- -->22 0x00000000071ab13a clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x71ab13a)
#<!-- -->23 0x0000000006dc3081 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6dc3081)
#<!-- -->24 0x0000000006de3219 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de3219)
#<!-- -->25 0x0000000006d8e64b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8e64b)
#<!-- -->26 0x0000000006d8ee3f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d8ee3f)
#<!-- -->27 0x0000000006d9b5f8 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9b5f8)
#<!-- -->28 0x0000000006d9c555 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9c555)
#<!-- -->29 0x0000000006d794aa clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d794aa)
#<!-- -->30 0x0000000004f62718 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f62718)
#<!-- -->31 0x000000000528edf8 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x528edf8)
#<!-- -->32 0x000000000521bf8d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x521bf8d)
#<!-- -->33 0x0000000005364abd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5364abd)
#<!-- -->34 0x0000000000dabaac cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdabaac)
#<!-- -->35 0x0000000000da26ca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#<!-- -->36 0x0000000000da284d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#<!-- -->37 0x0000000004fdb1f9 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
#<!-- -->38 0x00000000043a4884 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43a4884)
#<!-- -->39 0x0000000004fdbd65 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
#<!-- -->40 0x0000000004f93c12 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f93c12)
#<!-- -->41 0x0000000004f98577 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f98577)
#<!-- -->42 0x0000000004fa2ae5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4fa2ae5)
#<!-- -->43 0x0000000000da7faa clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda7faa)
#<!-- -->44 0x0000000000cc3c5a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc3c5a)
#<!-- -->45 0x0000760115e2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#<!-- -->46 0x0000760115e2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#<!-- -->47 0x0000000000da2075 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda2075)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
This reproduces on x86-64 Clang trunk and can be traced back to Clang 16.0.0. This testcase was generated by fuzzer.
Sorry, I just realized this appears to be a duplicate of #46932. Apologies for the duplicate report. Should I close this issue, or is there any reason to keep it open for the additional reproducer/backtrace?
Sorry, I just realized this appears to be a duplicate of #46932. Apologies for the duplicate report. Should I close this issue, or is there any reason to keep it open for the additional reproducer/backtrace?
https://github.com/llvm/llvm-project/issues/46932#issuecomment-4000182843
But your sample still crash on trunk.
Sorry, I just realized this appears to be a duplicate of #46932. Apologies for the duplicate report. Should I close this issue, or is there any reason to keep it open for the additional reproducer/backtrace?
But your sample still crash on trunk.
As I pointed out one of the examples still crashes, the comment that it was fixed is incorrect