Issue 138850
Summary Clang-21 crash with: Assertion `Entry != DelayedTypos.end() && "Failed to get the state for a TypoExpr!"' failed.
Labels new issue
Assignees
Reporter hyf751175784
    ### Description
I encountered a crash in Clang-21 when compiling the following code:
```cpp
void _Z4func() {
entry:
        int tmp = add(int, 0, 0);
        uint tmp = add(uint, 1, 1);
        ubyte tmp = add(ubyte, 1, 2);
        sbyte tmp = add(sbyte, 2, 3);
        call(void, f, (int)tmp);
        call(void, g, (ubyte)tmp);
 ret(void);
}
```
### Clang Version

```sh
$ clang -v
Ubuntu clang version 21.0.0 (++20250501082025+9b1051281e43-1~exp1~20250501082214.882)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-21/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Candidate multilib: .;@m64
Selected multilib: .;@m64
```

### Command
The compilation command used was:
```sh
clang++ bug.cpp  -O3 -Wall -Wextra -fno-strict-aliasing -fwrapv -g -fsanitize=address  -c -o bug.o
```

### Error Message
```sh
<source>:3:26: error: expected '(' for function-style cast or type construction
    3 |         int tmp = add(int, 0, 0);
      | ~~~^
<source>:4:9: error: use of undeclared identifier 'uint'; did you mean 'int'?
    4 |         uint tmp = add(uint, 1, 1);
      | ^~~~
      |         int
<source>:4:14: error: redefinition of 'tmp'
 4 |         uint tmp = add(uint, 1, 1);
      | ^
<source>:3:13: note: previous definition is here
    3 |         int tmp = add(int, 0, 0);
      |             ^
<source>:4:24: error: use of undeclared identifier 'uint'; did you mean 'using'?
    4 |         uint tmp = add(uint, 1, 1);
      |                        ^~~~
      | using
<source>:4:24: error: expected _expression_
<source>:5:9: error: unknown type name 'ubyte'
    5 |         ubyte tmp = add(ubyte, 1, 2);
      |         ^
<source>:5:25: error: use of undeclared identifier 'ubyte'
    5 |         ubyte tmp = add(ubyte, 1, 2);
      | ^~~~~
<source>:6:9: error: unknown type name 'sbyte'
    6 | sbyte tmp = add(sbyte, 2, 3);
      |         ^
<source>:6:25: error: use of undeclared identifier 'sbyte'
    6 |         sbyte tmp = add(sbyte, 2, 3);
      |                         ^~~~~
<source>:7:18: error: expected '(' for function-style cast or type construction
    7 |         call(void, f, (int)tmp);
      |              ~~~~^
<source>:7:20: error: use of undeclared identifier 'f'
    7 |         call(void, f, (int)tmp);
      | ^
clang++: /root/llvm-project/llvm/tools/clang/lib/Sema/SemaLookup.cpp:5791: const clang::Sema::TypoExprState& clang::Sema::getTypoExprState(clang::TypoExpr*) const: Assertion `Entry != DelayedTypos.end() && "Failed to get the state for a TypoExpr!"' 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-trunk/bin/clang++ -gdwarf-4 -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 -O3 -Wall -Wextra -fno-strict-aliasing -fwrapv -g -fsanitize=address <source>
1.	<source>:8:9: current parser token 'call'
2.	<source>:1:16: parsing function body '_Z4func'
3.	<source>:1:16: in compound statement ('{}')
 #0 0x0000000003f76d78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f76d78)
 #1 0x0000000003f74a04 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f74a04)
 #2 0x0000000003eb98c8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007401b9842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007401b98969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007401b9842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007401b98287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007401b982871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007401b9839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000006d15a66 clang::Sema::getTypoExprState(clang::TypoExpr*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d15a66)
#10 0x0000000006c0e1e7 (anonymous namespace)::TransformTypos::TransformTypoExpr(clang::TypoExpr*) SemaExprCXX.cpp:0:0
#11 0x0000000006c24a69 clang::TreeTransform<(anonymous namespace)::TransformTypos>::TransformRecoveryExpr(clang::RecoveryExpr*) SemaExprCXX.cpp:0:0
#12 0x0000000006c42d66 (anonymous namespace)::TransformTypos::RecursiveTransformLoop(clang::Expr*, bool&) SemaExprCXX.cpp:0:0
#13 0x0000000006c1770d clang::Sema::CorrectDelayedTyposInExpr(clang::Expr*, clang::VarDecl*, bool, llvm::function_ref<clang::ActionResult<clang::Expr*, true> (clang::Expr*)>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c1770d)
#14 0x0000000006c18d0d clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c18d0d)
#15 0x0000000006f7526e clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6f7526e)
#16 0x00000000066f2124 clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66f2124)
#17 0x00000000066e9b42 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66e9b42)
#18 0x00000000066eaa6d clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66eaa6d)
#19 0x00000000066f2783 clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66f2783)
#20 0x00000000066f2f4a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66f2f4a)
#21 0x00000000065fa913 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65fa913)
#22 0x0000000006630fbd 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+++0x6630fbd)
#23 0x00000000065ee44e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65ee44e)
#24 0x00000000065eec09 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65eec09)
#25 0x00000000065f652a clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65f652a)
#26 0x00000000065f74cd clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65f74cd)
#27 0x00000000065f7980 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65f7980)
#28 0x00000000065e9873 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65e9873)
#29 0x0000000004918f78 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4918f78)
#30 0x0000000004c0c235 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c0c235)
#31 0x0000000004b8b83e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b8b83e)
#32 0x0000000004d000e9 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d000e9)
#33 0x0000000000da766f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda766f)
#34 0x0000000000d9d83a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#35 0x000000000497f839 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
#36 0x0000000003eb9d64 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3eb9d64)
#37 0x000000000497fe4f 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
#38 0x000000000494229d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x494229d)
#39 0x000000000494332e 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+++0x494332e)
#40 0x000000000494b185 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x494b185)
#41 0x0000000000da35d8 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda35d8)
#42 0x0000000000c28a64 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc28a64)
#43 0x00007401b9829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#44 0x00007401b9829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#45 0x0000000000d9d2e5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xd9d2e5)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

The issue can also be reproduced on Compiler Explorer:https://godbolt.org/z/ePK8o9EMo
Please let me know if you need any more details.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to