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

    <tr>
        <th>Summary</th>
        <td>
            [CodeGen] Assertion 'Offset >= Size' failed. with `-mms-bitfields`
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          patrick-rivos
      </td>
    </tr>
</table>

<pre>
    Testcase:
```
#pragma pack(1)
struct {
  char a;
  signed : 1;
  signed : 0;
  unsigned b;
} c;
```

Backtrace:
```
clang-19: /root/llvm-project/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:1008: void {anonymous}::CGRecordLowering::insertPadding(): Assertion `Offset >= Size' 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-20240409/bin/clang-19 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -main-file-name example.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mms-bitfields -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-assertions-trunk-20240409/lib/clang/19 -internal-isystem /opt/compiler-explorer/clang-assertions-trunk-20240409/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/14.0.1/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-a9d207.o -x c <source>
1.      <eof> parser at end of file
 #0 0x0000000003935458 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x3935458)
 #1 0x0000000003932bac SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f6dffe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f6dffe969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007f6dffe42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007f6dffe287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007f6dffe2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007f6dffe39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x0000000003c4694f (anonymous namespace)::CGRecordLowering::lower(bool) CGRecordLayoutBuilder.cpp:0:0
 #9 0x0000000003c48bb9 clang::CodeGen::CodeGenTypes::ComputeRecordLayout(clang::RecordDecl const*, llvm::StructType*) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x3c48bb9)
#10 0x0000000003d82a17 clang::CodeGen::CodeGenTypes::ConvertRecordDeclType(clang::RecordDecl const*) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x3d82a17)
#11 0x0000000003d83d7b clang::CodeGen::CodeGenTypes::getCGRecordLayout(clang::RecordDecl const*) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x3d83d7b)
#12 0x0000000003d83ff8 clang::CodeGen::CodeGenTypes::isZeroInitializable(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x3d83ff8)
#13 0x0000000003c31fbf clang::CodeGen::CodeGenModule::EmitNullConstant(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x3c31fbf)
#14 0x0000000003d0f58d clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x3d0f58d)
#15 0x0000000003d105a5 clang::CodeGen::CodeGenModule::EmitTentativeDefinition(clang::VarDecl const*) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x3d105a5)
#16 0x000000000635dc2c clang::Sema::ActOnEndOfTranslationUnit() (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x635dc2c)
#17 0x00000000061decc1 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x61decc1)
#18 0x00000000061d182a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x61d182a)
#19 0x00000000041e1498 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x41e1498)
#20 0x000000000445f899 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x445f899)
#21 0x00000000043e913e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x43e913e)
#22 0x000000000454289e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0x454289e)
#23 0x0000000000c43a6c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0xc43a6c)
#24 0x0000000000c3ccfa ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#25 0x0000000000c4068e clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0xc4068e)
#26 0x0000000000b23fd4 main (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0xb23fd4)
#27 0x00007f6dffe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#28 0x00007f6dffe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#29 0x0000000000c3c7ee _start (/opt/compiler-explorer/clang-assertions-trunk-20240409/bin/clang-19+0xc3c7ee)
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
```

Godbolt: https://godbolt.org/z/3eqqo8zT7

Found via fuzzer.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWd1y4ygWfhpyQ-GSkGxLF7lw23FPV81s906ys1V740JwpDCRQAMoP_30WyDZMU4mM94d73Z1XBKCc77v_HEkmLWyUQDXaP4JzTdXbHD32lz3zBnJH4iRj9peVVq8XN-BdZxZQNkKJRuUrNAimf6PtzTrDWs6hnvGHxAtUkTL8ZF1ZuAOo-Wn8R5jfs8MZig7DAQUAqNshdP3h5Oj4UFND6rDIFpuMH-9O8EWfj8x_uAM479LgbdMNSQtvTpEt0Zrh-i2bR870hv9K3B_Gyb5YVkhul1rAZ9B-avPPwPXRvzIXvTgPg2yFWBmvO9RtkqTpPBCH7UU3gxMafXS6cGi5caDyVaH1foJjFTNOCqVBeO-MSH8EC28RbMVXlk_LLXCaJF8rWsLDqPsBmUbfCu_A6JLXDPZgpiNvL79eLO6vcF2qDrpMMPV0GADvTYOO43vneut10e3iG4b6e6HasZ1N1F_awFp7QAW0S1mSmCpeDsIwO4eMDfM3uPqYGe6xr2B3mgO1oLAVg9mHPYrmbWaS-ZAYDMobLmRvZsg3zrGH7AYuv7grGSGkvKb0Y1hHWamGTpQzk6-0n3wje562YIh8Ny32oDZ-4uwvckscWZQD4QmNE_yp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