<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/88400>88400</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Clang] [ICE] [crash-on-valid] clang frontend crashes when using modules, self-friend template with concepts
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          yujincheng08
      </td>
    </tr>
</table>

<pre>
    ### Description
Maybe related to #86769, but I have merged its fix #86914 and still crash.

Minimum reproducible example:
https://gist.github.com/yujincheng08/418bd6732f4be87fd24617e2f869883e

### Stack dump:
<details>
```
[build] 1.      /home/loves/test/foo.cc:6:8: at annotation token
[build] 2.      /home/loves/test/foo.cc:5:10: parsing function body 'y'
[build] 3.      /home/loves/test/foo.cc:5:10: in compound statement ('{}')
[build] 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):
[build] 0  libLLVM.so.18.1 0x00007fc38ce4d256 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 54
[build] 1  libLLVM.so.18.1      0x00007fc38ce4b210 llvm::sys::RunSignalHandlers() + 80
[build] 2  libLLVM.so.18.1 0x00007fc38cd9ce70
[build] 3  libc.so.6 0x00007fc388d3a520
[build] 4  libclang-cpp.so.18.1 0x00007fc39216f0aa
[build] 5  libclang-cpp.so.18.1 0x00007fc392124b7d
[build] 6  libclang-cpp.so.18.1 0x00007fc392120904
[build] 7  libclang-cpp.so.18.1 0x00007fc392120300 clang::Expr::EvaluateAsConstantExpr(clang::Expr::EvalResult&, clang::ASTContext const&, clang::Expr::ConstantExprKind) const + 1472
[build] 8  libclang-cpp.so.18.1 0x00007fc39278d436
[build] 9 libclang-cpp.so.18.1 0x00007fc3927882cf
[build] 10 libclang-cpp.so.18.1 0x00007fc392787c4a clang::Sema::CheckConstraintSatisfaction(clang::NamedDecl const*, llvm::ArrayRef<clang::Expr const*>, llvm::SmallVectorImpl<clang::Expr*>&, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange, clang::ConstraintSatisfaction&) + 810
[build] 11 libclang-cpp.so.18.1 0x00007fc39278a201 clang::Sema::EnsureTemplateArgumentListConstraints(clang::TemplateDecl*, clang::MultiLevelTemplateArgumentList const&, clang::SourceRange) + 257
[build] 12 libclang-cpp.so.18.1 0x00007fc392ca0740 clang::Sema::CheckTemplateArgumentList(clang::TemplateDecl*, clang::SourceLocation, clang::TemplateArgumentListInfo&, bool, llvm::SmallVectorImpl<clang::TemplateArgument>&, llvm::SmallVectorImpl<clang::TemplateArgument>&, bool, bool*) + 5408
[build] 13 libclang-cpp.so.18.1 0x00007fc392c9e5ce clang::Sema::CheckTemplateIdType(clang::TemplateName, clang::SourceLocation, clang::TemplateArgumentListInfo&) + 446
[build] 14 libclang-cpp.so.18.1 0x00007fc392ca2119 clang::Sema::ActOnTemplateIdType(clang::Scope*, clang::CXXScopeSpec&, clang::SourceLocation, clang::OpaquePtr<clang::TemplateName>, clang::IdentifierInfo*, clang::SourceLocation, clang::SourceLocation, llvm::MutableArrayRef<clang::ParsedTemplateArgument>, clang::SourceLocation, bool, bool, clang::ImplicitTypenameContext) + 1033
[build] 15 libclang-cpp.so.18.1 0x00007fc391edd8b3 clang::Parser::AnnotateTemplateIdTokenAsType(clang::CXXScopeSpec&, clang::ImplicitTypenameContext, bool) + 179
[build] 16 libclang-cpp.so.18.1 0x00007fc391eedfc0 clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(clang::CXXScopeSpec&, bool, clang::ImplicitTypenameContext) + 848
[build] 17 libclang-cpp.so.18.1 0x00007fc391eee499 clang::Parser::TryAnnotateTypeOrScopeToken(clang::ImplicitTypenameContext) + 569
[build] 18 libclang-cpp.so.18.1 0x00007fc391ee00a7 clang::Parser::isCXXDeclarationSpecifier(clang::ImplicitTypenameContext, clang::Parser::TPResult, bool*) + 2183
[build] 19 libclang-cpp.so.18.1 0x00007fc391edf637 clang::Parser::isCXXSimpleDeclaration(bool) + 55
[build] 20 libclang-cpp.so.18.1 0x00007fc391edf4fe clang::Parser::isCXXDeclarationStatement(bool) + 718
[build] 21 libclang-cpp.so.18.1 0x00007fc391ec818a clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) + 618
[build] 22 libclang-cpp.so.18.1 0x00007fc391ec7cdb clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) + 347
[build] 23 libclang-cpp.so.18.1 0x00007fc391ed0510 clang::Parser::ParseCompoundStatementBody(bool) + 1616
[build] 24 libclang-cpp.so.18.1 0x00007fc391ed15ef clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) + 175
[build] 25 libclang-cpp.so.18.1 0x00007fc391eec5d6 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) + 3574
[build] 26 libclang-cpp.so.18.1 0x00007fc391e36d48 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 4904
[build] 27 libclang-cpp.so.18.1 0x00007fc391eeb63a clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) + 1082
[build] 28 libclang-cpp.so.18.1 0x00007fc391eeb003 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) + 483
[build] 29 libclang-cpp.so.18.1 0x00007fc391eea266 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) + 2038
[build] 30 libclang-cpp.so.18.1 0x00007fc391ee869a clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) + 1466
[build] 31 libclang-cpp.so.18.1 0x00007fc391e212fe clang::ParseAST(clang::Sema&, bool, bool) + 782
[build] 32 libclang-cpp.so.18.1 0x00007fc393c51ef5 clang::FrontendAction::Execute() + 85
[build] 33 libclang-cpp.so.18.1 0x00007fc393bcb4e4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 708
[build] 34 libclang-cpp.so.18.1 0x00007fc393ccc6be clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 750
[build] 35 clang++-18           0x00005567b099ba25 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 4069
[build] 36 clang++-18 0x00005567b0998e25
[build] 37 libclang-cpp.so.18.1 0x00007fc393883999
[build] 38 libLLVM.so.18.1      0x00007fc38cd9cc0c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 140
[build] 39 libclang-cpp.so.18.1 0x00007fc39388332e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const + 366
[build] 40 libclang-cpp.so.18.1 0x00007fc39384b8c1 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const + 897
[build] 41 libclang-cpp.so.18.1 0x00007fc39384bb0e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const + 142
[build] 42 libclang-cpp.so.18.1 0x00007fc3938680ed clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) + 333
[build] 43 clang++-18           0x00005567b0998794 clang_main(int, char**, llvm::ToolContext const&) + 11172
[build] 44 clang++-18 0x00005567b09a6286 main + 102
[build] 45 libc.so.6 0x00007fc388d21d90
[build] 46 libc.so.6            0x00007fc388d21e40 __libc_start_main + 128
[build] 47 clang++-18           0x00005567b0995895 _start + 37
[build] clang++-18: error: clang frontend command failed with exit code 139 (use -v to see invocation)
```
</details>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWl9z4ygS_zTKC5WUAP1BD3lwnPg2e5mbqSS1NXcvKYRaMbuS8AHKxvfpr5BkW7axrdnb2rpUqiwbGvr366a7AXFj5HsDcBvEd0F8f8Vbu1T6dt3-KhuxhOY9ZFe5Kta3AaH9P7oHI7RcWamaILwPwtkXvs4Baai4hQJZhQJCWZImWUDmKG8tekRL_gGoBv0OBZLWoFJ-9r0yHCHeFMhYWVVIaG6WN_2ow9iykXVbIw0rrYpWyLwCBJ-8XlUQ0KHT0tqVcd_IIiCLd2nszbu0yza_EaoOyGKMJiCLCLO8SFJKyigHlpYFiRKcAilZkjFGYTz_DvaL5eI3VLT1ajtvQOcFWC4rE9CH4ackHP77r_Fd3sqqCOJ7hG-CMAvIYqlqCMiiUh9gArKwYGxAFqVSN0IEdJYEdMYCOkPcIt40ynLHNLLqN2iOByXTBo0DOsOhG3XFtZHNOyrbRnQDO-uigKTrgKTH49MfHV82SKh6pdrOqNxCDY1FAWFu-PQuSO_dA8mOp9oRjH6Xdqlai8y6zlWFGl6DcWNAY1oNaK3a3qOq6qO-7jvJ_4B2k69Vq9G32etPSGlkwCK7BATNh9Sq6VT54BoFSfj09MuXt5d_frn7-vT4r4fnNycSJKFz35WSjXUP0jpFt9Ye6RoiVMncjXFj1A1mNxiFn2EYhmkpKBMQFSROOvWcOJ2ZtekfvmnZ2A7pq-YCAsJ2nTT__U0Zq4HXAUnc4pGN0wAF5A7FkcejjrXo_vZVyQkOfao8t82LfG949RNvigq06YzUz8Y8_kvOYy4yAalHjHZiwskkYwFWUB4Tj0DUC1S8eb8Wq5VnsozgpAw5P5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