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

    <tr>
        <th>Summary</th>
        <td>
            clangtk assertion failure: clang::QualType clang::FunctionProtoType::getParamType(unsigned int) const: Assertion `i < getNumParams() && "invalid parameter index"' failed.
        </td>
    </tr>

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

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

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

<pre>
    The following code snippet causes an assertion failure when compiled with the clangtk compiler using the -O0 optimization flag. This behavior can be verified by visiting https://gcc.godbolt.org/z/nPE41Y59q.
```
typedef struct T1 *T2;

int f(T2 a, ...) __attribute__((format_arg(2)));
```

Below is compiler's output copied from gcc.godbolt.org:
```
clang: /root/llvm-project/clang/include/clang/AST/Type.h:4264: clang::QualType clang::FunctionProtoType::getParamType(unsigned int) const: Assertion `i < getNumParams() && "invalid parameter index"' 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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics -O0 <source>
1.      <source>:3:48: current parser token ';'
 #0 0x000055e7bc9601df llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bb41df)
 #1 0x000055e7bc95df4c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bb1f4c)
 #2 0x000055e7bc8a7658 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007fb38afad420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fb38aa7a00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007fb38aa59859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007fb38aa59729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007fb38aa6afd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000055e7bf4224a5 getFunctionOrMethodParamType(clang::Decl const*, unsigned int) SemaDeclAttr.cpp:0:0
 #9 0x000055e7bf44efa7 handleFormatArgAttr(clang::Sema&, clang::Decl*, clang::ParsedAttr const&) SemaDeclAttr.cpp:0:0
#10 0x000055e7bf47ca41 ProcessDeclAttribute(clang::Sema&, clang::Scope*, clang::Decl*, clang::ParsedAttr const&, clang::Sema::ProcessDeclAttributeOptions const&) (.isra.0) SemaDeclAttr.cpp:0:0
#11 0x000055e7bf47def3 clang::Sema::ProcessDeclAttributes(clang::Scope*, clang::Decl*, clang::Declarator const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66d1ef3)
#12 0x000055e7bf414203 clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6668203)
#13 0x000055e7bf41a0e6 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x666e0e6)
#14 0x000055e7bf41adf5 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x666edf5)
#15 0x000055e7bf0cdff0 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6321ff0)
#16 0x000055e7bf0db138 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x632f138)
#17 0x000055e7bf0a8811 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x62fc811)
#18 0x000055e7bf0a90cf clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) Parser.cpp:0:0
#19 0x000055e7bf0afa91 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6303a91)
#20 0x000055e7bf0b03c3 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x63043c3)
#21 0x000055e7bf0a419a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x62f819a)
#22 0x000055e7bdba7f78 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4dfbf78)
#23 0x000055e7bd401ea9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4655ea9)
#24 0x000055e7bd386e46 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x45dae46)
#25 0x000055e7bd4e4d26 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4738d26)
#26 0x000055e7b9e25f5c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1079f5c)
#27 0x000055e7b9e21c7a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x000055e7bd1edd7d 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
#29 0x000055e7bc8a7b60 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3afbb60)
#30 0x000055e7bd1ee5ff 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
#31 0x000055e7bd1b5bfc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4409bfc)
#32 0x000055e7bd1b668d 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+0x440a68d)
#33 0x000055e7bd1be76d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x441276d)
#34 0x000055e7b9e241da clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10781da)
#35 0x000055e7b9d2b215 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xf7f215)
#36 0x00007fb38aa5b083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#37 0x000055e7b9e1ca5e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x1070a5e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWltv47gV_jXKC2GDou4PefBk4u0sZpt0EhTok0GRhzYbmdSSVC776wtKsmMqdibT9Q5QFMhkYpI6POc737mYIrVWrhXAZZR9irLPF7RzG20unyQYp9VFrfnL5f0GkNBNo5-kWiOmOSCrZNuCQ4x2FiyiClFrwTipFRJUNp0B9LQBhZjetrIBjp6k2yC3AcQaqtbuYTdjUGe9WD81u8FIt05u5R90ENXQ9Rzdb6RFNWzoo9QGMapQDegRjBQSOKpf0KO00nkhG-daGyWLiCwjslwzNl9rXuvGzbVZR2T5R0SW6vY6jf-VVb_PI_w5wosox-NP_9G9tMBBIOtMxxy6j1FEFvckSj6Ny_vfUjkkIlLeE0QjcoXm83lEKrRaUeeMrDsHq1VEyoiUQpstdSvq9y9JRKrxZy8v3H74_Qka_YSk3YMUkcIi3bm2c4jp1tstjN6iqYnJ4qjUHvMoWaCILI3WLiLLpnnczlqj_w3MfxxWkKVUrOk4HIws7u4jsrx_aWG-iZJFSvLUS9qJjJLFPzra-PnDsWWnmHfhrdFO-8lheA3ulhq67UdI2amefRxJ5Tx-TCvrvPTFnk1RjiWKkiu0Bvf3bts_bXtoKxSRPCI5igiR6pE2kqPWT4MDg6Ti8BwREpGiZyTw0d-3X68Xd9fIdvVWOkRR3a2RgVYbh5yeMki6TVfPmd6OiL0FTlrbgY3IElHl7ejhG4huqN2gmrIHZygDT5PWQGs0A2uBI6s7Mwz7J6m1mknqgCPTKWSZka0bVb5zlD0g3m3bvYPxPMLVrdFrQ7eImnW3BeXs6GLd9i4duTOD57bRxpNocOpsH6t25kynHiKyrKXaTaPZmj9RI2Ypmq3RTHuJtG293J6Ac4tmd2g2WzM2c1o3bEOlipLP727sF1dzMsdoJphutJlxSddKWyeZRTOh9KzHKxy-wd71I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