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

    <tr>
        <th>Summary</th>
        <td>
            [clang] crashes when redeclaring a struct with [[gnu::unused]] attribute
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            crash
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Reproducer:
https://godbolt.org/z/M8nT1v9PG
```c
struct [[gnu::unused]] foo { } x;

void bar()
{
  extern struct foo { } x;
}
```

Backtrace:
```console
clang: /root/llvm-project/llvm/tools/clang/lib/AST/ASTStructuralEquivalence.cpp:2576: clang::DiagnosticBuilder clang::StructuralEquivalenceContext::Diag2(clang::SourceLocation, unsigned int): Assertion `Complain && "Not allowed to complain"' 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 -std=c23 <source>
1.      <source>:5:26: current parser token ';'
2.      <source>:4:1: parsing function body 'bar'
3.      <source>:4:1: in compound statement ('{}')
 #0 0x00000000040213f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x40213f8)
 #1 0x000000000401e824 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x401e824)
 #2 0x0000000003f63058 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x000073ffcbe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000073ffcbe969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000073ffcbe42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000073ffcbe287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000073ffcbe2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x000073ffcbe39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00000000076acb10 CheckStructurallyEquivalentAttributes(clang::StructuralEquivalenceContext&, clang::Decl const*, clang::Decl const*, clang::Decl const*) ASTStructuralEquivalence.cpp:0:0
#10 0x00000000076bd890 IsStructurallyEquivalent(clang::StructuralEquivalenceContext&, clang::RecordDecl*, clang::RecordDecl*) ASTStructuralEquivalence.cpp:0:0
#11 0x00000000076bea0d clang::StructuralEquivalenceContext::CheckKindSpecificEquivalence(clang::Decl*, clang::Decl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x76bea0d)
#12 0x00000000076bf553 clang::StructuralEquivalenceContext::Finish() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x76bf553)
#13 0x00000000076bf8b8 clang::StructuralEquivalenceContext::IsEquivalent(clang::QualType, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x76bf8b8)
#14 0x0000000007576f2c clang::ASTContext::mergeTagDefinitions(clang::QualType, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7576f2c)
#15 0x00000000075c7271 clang::ASTContext::mergeTypes(clang::QualType, clang::QualType, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x75c7271)
#16 0x0000000006a7e052 clang::Sema::MergeVarDeclTypes(clang::VarDecl*, clang::VarDecl*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a7e052)
#17 0x0000000006a97658 clang::Sema::MergeVarDecl(clang::VarDecl*, clang::LookupResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a97658)
#18 0x0000000006a98a8a clang::Sema::CheckVariableDeclaration(clang::VarDecl*, clang::LookupResult&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a98a8a)
#19 0x0000000006a9c154 clang::Sema::ActOnVariableDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&, llvm::ArrayRef<clang::BindingDecl*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a9c154)
#20 0x0000000006abc7af clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6abc7af)
#21 0x0000000006abd0f0 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6abd0f0)
#22 0x00000000067098e3 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67098e3)
#23 0x0000000006718d19 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+0x6718d19)
#24 0x00000000067219cf clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67219cf)
#25 0x0000000006721e9c clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6721e9c)
#26 0x00000000067e3af2 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+0x67e3af2)
#27 0x00000000067e47c9 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 24u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67e47c9)
#28 0x00000000067ec92b clang::Parser::ParseCompoundStatementBody(bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67ec92b)
#29 0x00000000067ed13a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x67ed13a)
#30 0x00000000066e334b clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66e334b)
#31 0x000000000671971d 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+0x671971d)
#32 0x00000000066d676e clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66d676e)
#33 0x00000000066d6f0f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66d6f0f)
#34 0x00000000066de783 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66de783)
#35 0x00000000066df695 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66df695)
#36 0x00000000066d179a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x66d179a)
#37 0x00000000049c32f8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49c32f8)
#38 0x0000000004cb7355 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4cb7355)
#39 0x0000000004c335ae clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c335ae)
#40 0x0000000004da8971 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4da8971)
#41 0x0000000000daff4f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdaff4f)
#42 0x0000000000da6baa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#43 0x0000000004a2ad09 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 0x0000000003f634f4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f634f4)
#45 0x0000000004a2b31f 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 0x00000000049ed58d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49ed58d)
#47 0x00000000049ee61e 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+0x49ee61e)
#48 0x00000000049f60b5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x49f60b5)
#49 0x0000000000dac405 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xdac405)
#50 0x0000000000c60394 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc60394)
#51 0x000073ffcbe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#52 0x000073ffcbe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#53 0x0000000000da6655 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda6655)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsW11zpDiy_TX4RVEOkPh88AMuu-Z6bs9t37ZjXh1CJGXWlMRIwl3eX78hAcWHy2V7mp6diN2NnZkyQqlzTqZSiRBUqXLLAS6c4NIJrs5oox-FvHhaUSnFd3WWifzl4hvUUuQNA-mQ1HHTR61rZX7ijYM3W5FnotLnQm4dvPmngze_xfzee05uf3Hc1And9v_McVOlZcM0smNdbnljbJC04Y2C3AmunOAKFUIgJ7pETnSF9g65NCbc9FmUOcqodHDs4MRci0wLQrDXIDnqDB_rHF2NUbT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