Clang crashed in ASTContext::getCommonSugaredType · Issue #97005 · llvm/llvm-project (original) (raw)

Clang ToT version is used:

$ clang --version
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 5bbec8f4b6a26e8b4a4209d90a2ad0a0d2416a55)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /ext/sdc/arbeit/space1/build/bin
Build config: +assertions   

The source code is:

$ cat reduce.cpp
bool a;
constexpr const unsigned char c[] = { 5 };
constexpr const unsigned char d[1] = { 0 };
auto b = (a ? d : c);

Running the compiler results in a crash:

$ clang -fsyntax-only reduce.cpp 
clang: /export/serge/llvm/space1/llvm-project/clang/lib/AST/ASTContext.cpp:13501: clang::QualType clang::ASTContext::getCommonSugaredType(clang::QualType, clang::QualType, bool): Assertion `QX == QY' 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: clang -fsyntax-only reduce.cpp
1.	reduce.cpp:4:20: current parser token ')'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  clang     0x0000000002070b28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
1  clang     0x000000000206e55e llvm::sys::RunSignalHandlers() + 238
2  clang     0x0000000001fe5727
3  libc.so.6 0x00007f9621462520
4  libc.so.6 0x00007f96214b69fc pthread_kill + 300
5  libc.so.6 0x00007f9621462476 raise + 22
6  libc.so.6 0x00007f96214487f3 abort + 211
7  libc.so.6 0x00007f962144871b
8  libc.so.6 0x00007f9621459e96
9  clang     0x000000000529813c clang::ASTContext::getCommonSugaredType(clang::QualType, clang::QualType, bool) + 8332
10 clang     0x00000000049ad0d4 clang::Sema::CXXCheckConditionalOperands(clang::ActionResult<clang::Expr*, true>&, clang::ActionResult<clang::Expr*, true>&, clang::ActionResult<clang::Expr*, true>&, clang::ExprValueKind&, clang::ExprObjectKind&, clang::SourceLocation) + 1412
11 clang     0x000000000483ac6f clang::Sema::ActOnConditionalOp(clang::SourceLocation, clang::SourceLocation, clang::Expr*, clang::Expr*, clang::Expr*) + 367
12 clang     0x00000000044111e6 clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) + 4742
13 clang     0x0000000004419b5d clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool, bool, clang::OpaquePtr<clang::QualType>&, clang::SourceLocation&) + 3021
14 clang     0x0000000004416e76 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) + 11270
15 clang     0x0000000004411761 clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) + 33
16 clang     0x000000000440ff04 clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 196
17 clang     0x00000000043d2156 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) + 3670
18 clang     0x00000000043cf299 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 3433
19 clang     0x00000000043a6285 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) + 1365
20 clang     0x00000000043a5ab4 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) + 596
21 clang     0x00000000043a4abb clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) + 3659
22 clang     0x00000000043a2229 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) + 2217
23 clang     0x000000000439d4e5 clang::ParseAST(clang::Sema&, bool, bool) + 581
24 clang     0x0000000002b3be76 clang::FrontendAction::Execute() + 262
25 clang     0x0000000002aa0934 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1092
26 clang     0x0000000002c0dd07 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 535
27 clang     0x0000000000b39f37 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 4967
28 clang     0x0000000000b36993
29 clang     0x00000000028cce69
30 clang     0x0000000001fe5469 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 137
31 clang     0x00000000028cc83a clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 266
32 clang     0x00000000028831df clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 463
33 clang     0x000000000288375a clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 154
34 clang     0x00000000028a7b17 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 743
35 clang     0x0000000000b35865 clang_main(int, char**, llvm::ToolContext const&) + 5461
36 clang     0x0000000000b46347 main + 87
37 libc.so.6 0x00007f9621449d90
38 libc.so.6 0x00007f9621449e40 __libc_start_main + 128
39 clang     0x0000000000b33f85 _start + 37
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 5bbec8f4b6a26e8b4a4209d90a2ad0a0d2416a55)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /ext/sdc/arbeit/space1/build/bin
Build config: +assertions
clang: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/reduce-159e8c.cpp
clang: note: diagnostic msg: /tmp/reduce-159e8c.sh
clang: note: diagnostic msg: 

********************

The crash is triggered here:

clang::QualType clang::ASTContext::getCommonSugaredType(clang::QualType, clang::QualType, bool): Assertion `QX == QY' failed.

It can also be obverved online: https://godbolt.org/z/GGnfzbPv7.