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

    <tr>
        <th>Summary</th>
        <td>
            [Clang] Assertion `NumBits <= MAX_INT_BITS && "bitwidth too large"' failed when using `__atomic_exchange`
        </td>
    </tr>

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

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

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

<pre>
    Compiler Explorer: [https://godbolt.org/z/nW3sbTYYz](https://godbolt.org/z/nW3sbTYYz)

Attempting to compile the following program with Clang Assertion Trunk:
```c
struct S { char x[1804289383]; };

void foo (struct S *x, struct S *y, struct S *z) {
  __atomic_exchange(x, y, z, __ATOMIC_SEQ_CST);
}
```

Stack dump:
```
clang: /root/llvm-project/llvm/lib/IR/Type.cpp:277: static llvm::IntegerType* llvm::IntegerType::get(llvm::LLVMContext&, unsigned int): Assertion `NumBits <= MAX_INT_BITS && "bitwidth too large"' 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 <source>
1.      <eof> parser at end of file
2.      <source>:3:6: LLVM IR generation of declaration 'foo'
3.      <source>:3:6: Generating code for declaration 'foo'
 #0 0x0000000003b99d28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b99d28)
 #1 0x0000000003b979ec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b979ec)
 #2 0x0000000003ae61f8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x000070b866242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000070b8662969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000070b866242476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000070b8662287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000070b86622871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x000070b866239e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000003563ba7 llvm::IntegerType::get(llvm::LLVMContext&, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3563ba7)
#10 0x00000000040fc6b5 clang::CodeGen::CodeGenFunction::EmitAtomicExpr(clang::AtomicExpr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x40fc6b5)
#11 0x00000000043bfd28 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#12 0x00000000043c58ac clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43c58ac)
#13 0x000000000434e8be clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x434e8be)
#14 0x0000000004374b85 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4374b85)
#15 0x0000000003efb405 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3efb405)
#16 0x0000000003f03114 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f03114)
#17 0x0000000003f6b5b4 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f6b5b4)
#18 0x0000000003f7d59c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f7d59c)
#19 0x0000000003fe5f4a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe5f4a)
#20 0x0000000003fe0c65 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe0c65)
#21 0x0000000003fe121b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fe121b)
#22 0x0000000003feb593 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#23 0x00000000044f2e26 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#24 0x00000000044e3a08 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44e3a08)
#25 0x000000000661af54 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x661af54)
#26 0x00000000044f0998 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44f0998)
#27 0x00000000047aa2e9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47aa2e9)
#28 0x0000000004728c2e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4728c2e)
#29 0x000000000488fb6e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x488fb6e)
#30 0x0000000000cd801f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcd801f)
#31 0x0000000000ccfd2a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#32 0x0000000004534669 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
#33 0x0000000003ae66a4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3ae66a4)
#34 0x0000000004534c5f 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
#35 0x00000000044fa59d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x44fa59d)
#36 0x00000000044fb68d 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+0x44fb68d)
#37 0x0000000004502fb5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4502fb5)
#38 0x0000000000cd4eef clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcd4eef)
#39 0x0000000000ba49a4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xba49a4)
#40 0x000070b866229d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#41 0x000070b866229e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#42 0x0000000000ccf7de _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xccf7de)
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/eJzkWl1z46i2_TXkhbJLQt8PeXCcuG-mumf6dlI9d55cCCGZaQlUgNLO_PpbgOwIxckkOZ5Tp-p0dT6MYLPW2pvNFgErxRpO6SVIrkByfYEHvRPy8pH9iXmcx8lFKarHy7XoetZSCW_2fSsklSBaQZBc7bTuFYhWAG0A2jSiKkWrl0I2AG3-AmjDf49Uef_HH3-B5Bqg_O3dUQGCaxCs3PeV1rTrNeMN1AISBwbqHYW1aFvx0zzopWgk7uBPpndw3WLewJVSVGomOLyXA_9hJnZG08D9J-6z0nIgGt5BkF1BssMS7kFyFeZBjPIiyiMDPrqCIDM_prgeBKtgLQQEKH8yglZ7gNZw2vA4bzAMzXTODoTbLdaiY2RL92SHeUMByq0VO_Iv8227Xd3_9uV2vb27-d_t-u7eaHSEk13PqE1h3mlMfsBq6PrnEriPxOhlfYo2UggN0KZtH7pFL8WflBw-mh-sBGhz-w2gzf1jT5ekNzZRlpnBSmPNCLRdoxWIVrdc04ZK0xOg1QsPbENDNUD5U4fPn79_WQuu6V4DlBr6A7eBWkHGtaW-mvgXpMGvQ3fFtIIgWoPoGn5Z_d_29tf77dXtvRE8BSiFAKGS6Z-s0juohYAtlkZoBFAGa8xaWi2dHF8_36zubqAayo5piGE5NFDSXkht4m8WxUzvhnJJRDdRydeOKTVQBdAGY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