Closed
Description
Hi !
I got an assertion failed using clang 17.0.1 under windows. (This also happen with clang 16, but not with clang 15)
In godbold, I need to use the "assertions" version of clang to get this crash.
Here is a way to get it :
https://godbolt.org/z/nrnMeYfob
Preprocessed source:
# 1 "<built-in>"
# 1 "main.cpp"
template <typename T>
struct Vector
{
int begin();
};
template <typename T>
using iterator_t = decltype(T().begin());
template <typename I>
using iter_difference_t = long long int;
template <typename R>
using range_difference_t = iter_difference_t<iterator_t<R>>;
template <typename R>
struct iterator
{
range_difference_t<R> n_{};
void test(range_difference_t<R> x)
{
auto const a = x - 1;
[[maybe_unused]] auto const step = n_ * a;
}
};
int main()
{
auto i = iterator<Vector<int>>();
i.test(2);
return 1;
}
The code is strange, sorry. It is because it is a minimalist code to reproduce the bug.
Run script:
# Crash reproducer for clang version 17.0.1
# Driver args: "--driver-mode=g++" "-c" "-emit-llvm" "-Xclang" "-disable-llvm-passes" "main.cpp"
# Original command: "C:\\Program Files\\LLVM\\bin\\clang++.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30151" "-emit-llvm-bc" "-emit-llvm-uselists" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-fcoverage-compilation-dir=C:\\C\\rah2\\test" "-resource-dir" "C:\\Program Files\\LLVM\\lib\\clang\\17" "-internal-isystem" "C:\\Program Files\\LLVM\\lib\\clang\\17\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Tools\\MSVC\\14.29.30133\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Tools\\MSVC\\14.29.30133\\atlmfc\\include" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22000.0\\ucrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22000.0\\shared" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22000.0\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22000.0\\winrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22000.0\\cppwinrt" "-fdeprecated-macro" "-fdebug-compilation-dir=C:\\C\\rah2\\test" "-ferror-limit" "19" "-fmessage-length=207" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30151" "-std=c++14" "-fdelayed-template-parsing" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-disable-llvm-passes" "-faddrsig" "-o" "main.bc" "-x" "c++" "main.cpp"
"C:\\Program Files\\LLVM\\bin\\clang++.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.29.30151" "-emit-llvm-bc" "-emit-llvm-uselists" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "x86-64" "-tune-cpu" "generic" "-fcoverage-compilation-dir=C:\\C\\rah2\\test" "-fdeprecated-macro" "-fdebug-compilation-dir=C:\\C\\rah2\\test" "-ferror-limit" "19" "-fmessage-length=207" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.29.30151" "-std=c++14" "-fdelayed-template-parsing" "-fcxx-exceptions" "-fexceptions" "-fcolor-diagnostics" "-disable-llvm-passes" "-faddrsig" "-x" "c++" "main-5cee9d.cpp"
The error message is:
Unexpected sugar-free: Decltype
UNREACHABLE executed at /root/llvm-project/clang/lib/AST/ASTContext.cpp:12692!
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-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 <source>
1. <source>:25:50: current parser token ';'
2. <source>:18:1: parsing struct/union/class body 'iterator'
3. <source>:23:5: parsing function body 'iterator::test'
4. <source>:23:5: in compound statement ('{}')
#0 0x00000000036e7558 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e7558)
#1 0x00000000036e53dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x36e53dc)
#2 0x0000000003632918 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007ff487c50420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007ff48771300b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#5 0x00007ff4876f2859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#6 0x000000000363dbca (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x363dbca)
#7 0x0000000006c8a6dd getCommonNonSugarTypeNode(clang::ASTContext&, clang::Type const*, clang::Qualifiers&, clang::Type const*, clang::Qualifiers&) ASTContext.cpp:0:0
#8 0x0000000006c8b13d clang::ASTContext::getCommonSugaredType(clang::QualType, clang::QualType, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x6c8b13d)
#9 0x0000000006c8cb21 getCommonTemplateArguments(clang::ASTContext&, llvm::SmallVectorImpl<clang::TemplateArgument>&, llvm::ArrayRef<clang::TemplateArgument>, llvm::ArrayRef<clang::TemplateArgument>) ASTContext.cpp:0:0
#10 0x0000000006c8b6a1 clang::ASTContext::getCommonSugaredType(clang::QualType, clang::QualType, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x6c8b6a1)
#11 0x0000000006377792 clang::Sema::UsualArithmeticConversions(clang::ActionResult<clang::Expr*, true>&, clang::ActionResult<clang::Expr*, true>&, clang::SourceLocation, clang::Sema::ArithConvKind) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x6377792)
#12 0x0000000006380945 clang::Sema::CheckMultiplyDivideOperands(clang::ActionResult<clang::Expr*, true>&, clang::ActionResult<clang::Expr*, true>&, clang::SourceLocation, bool, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x6380945)
#13 0x000000000638764a clang::Sema::CreateBuiltinBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x638764a)
#14 0x0000000006388fdc clang::Sema::BuildBinOp(clang::Scope*, clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x6388fdc)
#15 0x0000000006389303 clang::Sema::ActOnBinOp(clang::Scope*, clang::SourceLocation, clang::tok::TokenKind, clang::Expr*, clang::Expr*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x6389303)
#16 0x0000000005e55431 clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5e55431)
#17 0x0000000005e1502d clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5e1502d)
#18 0x0000000005e21f40 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5e21f40)
#19 0x0000000005e2a215 clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5e2a215)
#20 0x0000000005e2a657 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5e2a657)
#21 0x0000000005ec9e50 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5ec9e50)
#22 0x0000000005ecab51 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5ecab51)
#23 0x0000000005ecbaa9 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5ecbaa9)
#24 0x0000000005ecd37a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5ecd37a)
#25 0x0000000005dfda16 clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5dfda16)
#26 0x0000000005dfd71d clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5dfd71d)
#27 0x0000000005e4868e clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5e4868e)
#28 0x0000000005e4a510 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-assertions-17.0.1/bin/clang+++0x5e4a510)
#29 0x0000000005e23d78 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5e23d78)
#30 0x0000000005ee6092 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5ee6092)
#31 0x0000000005eec631 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) ParseTemplate.cpp:0:0
#32 0x0000000005eec8a3 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5eec8a3)
#33 0x0000000005e2a7f9 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5e2a7f9)
#34 0x0000000005df6584 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5df6584)
#35 0x0000000005df7452 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5df7452)
#36 0x0000000005deb76a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x5deb76a)
#37 0x0000000004939258 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4939258)
#38 0x00000000041a1c09 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41a1c09)
#39 0x00000000041278ce clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x41278ce)
#40 0x0000000004281de6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x4281de6)
#41 0x0000000000bc67eb cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc67eb)
#42 0x0000000000bbefaa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#43 0x0000000003f83419 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
#44 0x0000000003632dc4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3632dc4)
#45 0x0000000003f83a0f 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
#46 0x0000000003f4b275 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4b275)
#47 0x0000000003f4bcdd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f4bcdd)
#48 0x0000000003f5385d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0x3f5385d)
#49 0x0000000000bc4a87 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbc4a87)
#50 0x0000000000abef61 main (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xabef61)
#51 0x00007ff4876f4083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#52 0x0000000000bbea8e _start (/opt/compiler-explorer/clang-assertions-17.0.1/bin/clang+++0xbbea8e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
Hope this helps!