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

    <tr>
        <th>Summary</th>
        <td>
            [Clang][ASTWriter] Assertion `(Value < (1u << BitsWidth)) && "Passing narrower bit width!"' failed.
        </td>
    </tr>

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

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

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

<pre>
    When trying to compile a PCH using the following command on trunk (d51e06c73c33b6c35ee47542a9674da63c6b7f07)

test.sh

```sh
clang++-18 -cc1 -std=c++17 -emit-pch -o qstyle.cpp.oclango qstyle.cpp
```

qstyle.cpp (reduced from qtbase via cvise)

```cpp
template <int... Nx> int stringData(const char (&...x)[Nx]) {
  return 0;
}
int qt_meta_stringdata_CLASSQStyleENDCLASS = stringData(
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
 "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
    "", "", "", "", "", "", "", "", "", "");
```

The command crashes with this backtrace

```console
clang++-18: /data/llvm-project/clang/include/clang/Serialization/ASTWriter.h:901: void clang::BitsPacker::addBits(uint32_t, uint32_t): Assertion `(Value < (1u << BitsWidth)) && "Passing narrower bit width!"' 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: clang++-18 -cc1 -std=c++17 -emit-pch -ferror-limit 0 -o qstyle.cpp.oclango qstyle.cpp
1.      <eof> parser at end of file
2.      qstyle.cpp:1:53: serializing 'x'
 #0 0x000055555add97b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/llvm-project/llvm/lib/Support/Unix/Signals.inc:727:0
 #1 0x000055555add72f4 llvm::sys::RunSignalHandlers() /data/llvm-project/llvm/lib/Support/Signals.cpp:105:0
 #2 0x000055555add7f0e SignalHandler(int) /data/llvm-project/llvm/lib/Support/Unix/Signals.inc:403:0
 #3 0x00007ffff7bc6980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #4 0x00007ffff67f4e87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007ffff67f67f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00007ffff67e63fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
 #7 0x00007ffff67e6472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #8 0x000055555bc09ba9 (/data/llvm-project/build/bin/clang-18+0x66b5ba9)
 #9 0x000055555bc51169 clang::ParmVarDecl::getObjCDeclQualifier() const /data/llvm-project/clang/include/clang/AST/Decl.h:1813:0
#10 0x000055555bc51169 clang::ASTDeclWriter::VisitParmVarDecl(clang::ParmVarDecl*) /data/llvm-project/clang/lib/Serialization/ASTWriterDecl.cpp:1171:0
#11 0x000055555bc551cf decltype(auto) llvm::dyn_cast<clang::DeclaratorDecl, clang::Decl>(clang::Decl*) /data/llvm-project/llvm/include/llvm/Support/Casting.h:662:0
#12 0x000055555bc551cf clang::ASTDeclWriter::Visit(clang::Decl*) /data/llvm-project/clang/lib/Serialization/ASTWriterDecl.cpp:279:0
#13 0x000055555bc55523 clang::ASTDeclWriter::Emit(clang::Decl*) /data/llvm-project/clang/lib/Serialization/ASTWriterDecl.cpp:50:0
#14 0x000055555bc55523 clang::ASTWriter::WriteDecl(clang::ASTContext&, clang::Decl*) /data/llvm-project/clang/lib/Serialization/ASTWriterDecl.cpp:2723:0
#15 0x000055555bc45510 clang::ASTWriter::WriteASTCore(clang::Sema&, llvm::StringRef, clang::Module*) /data/llvm-project/clang/lib/Serialization/ASTWriter.cpp:5089:0
#16 0x000055555bc46865 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::_M_set_length(unsigned long) /usr/include/c++/7/bits/basic_string.h:206:0
#17 0x000055555bc46865 std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>::clear() /usr/include/c++/7/bits/basic_string.h:1014:0
#18 0x000055555bc46865 clang::ASTWriter::WriteAST(clang::Sema&, llvm::StringRef, clang::Module*, llvm::StringRef, bool) /data/llvm-project/clang/lib/Serialization/ASTWriter.cpp:4643:0
#19 0x000055555bc64220 std::__shared_ptr_access<clang::PCHBuffer, (__gnu_cxx::_Lock_policy)2, false, false>::_M_get() const /usr/include/c++/7/bits/shared_ptr_base.h:975:0
#20 0x000055555bc64220 std::__shared_ptr_access<clang::PCHBuffer, (__gnu_cxx::_Lock_policy)2, false, false>::operator->() const /usr/include/c++/7/bits/shared_ptr_base.h:969:0
#21 0x000055555bc64220 clang::PCHGenerator::HandleTranslationUnit(clang::ASTContext&) /data/llvm-project/clang/lib/Serialization/GeneratePCH.cpp:68:0
#22 0x000055555bad7c08 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) /data/llvm-project/clang/lib/Frontend/MultiplexConsumer.cpp:297:0
#23 0x000055555cd42589 clang::ParseAST(clang::Sema&, bool, bool) /data/llvm-project/clang/lib/Parse/ParseAST.cpp:176:0
#24 0x000055555baa5379 clang::FrontendAction::Execute() /data/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1069:0
#25 0x000055555ba30e50 llvm::Error::setChecked(bool) /data/llvm-project/llvm/include/llvm/Support/Error.h:307:0
#26 0x000055555ba30e50 llvm::Error::operator bool() /data/llvm-project/llvm/include/llvm/Support/Error.h:239:0
#27 0x000055555ba30e50 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /data/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1057:0
#28 0x000055555bb361f3 std::__shared_ptr_access<clang::FrontendOptions, (__gnu_cxx::_Lock_policy)2, false, false>::_M_get() const /usr/include/c++/7/bits/shared_ptr_base.h:975:0
#29 0x000055555bb361f3 std::__shared_ptr_access<clang::FrontendOptions, (__gnu_cxx::_Lock_policy)2, false, false>::operator*() const /usr/include/c++/7/bits/shared_ptr_base.h:961:0
#30 0x000055555bb361f3 clang::CompilerInvocation::getFrontendOpts() /data/llvm-project/clang/include/clang/Frontend/CompilerInvocation.h:254:0
#31 0x000055555bb361f3 clang::CompilerInstance::getFrontendOpts() /data/llvm-project/clang/include/clang/Frontend/CompilerInstance.h:291:0
#32 0x000055555bb361f3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /data/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:273:0
#33 0x000055555954097e cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /data/llvm-project/clang/tools/driver/cc1_main.cpp:294:0
#34 0x0000555559537c38 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /data/llvm-project/clang/tools/driver/driver.cpp:366:0
#35 0x000055555953b0a4 clang_main(int, char**, llvm::ToolContext const&) /data/llvm-project/clang/tools/driver/driver.cpp:407:0
#36 0x000055555954c9e1 main /data/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:16:0
#37 0x00007ffff67d7c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#38 0x0000555559536f6a _start (/data/llvm-project/build/bin/clang-18+0x3fe2f6a)
./test.sh: line 1: 29285 Aborted                 (core dumped) clang++-18 -cc1 -std=c++17 -emit-pch -ferror-limit 0 -o qstyle.cpp.oclango qstyle.cpp
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWltv4zYW_jXMC2FDInV9yINjxztd9JLW6RTYF4GiKJuNLHpIKnH21y9ISbaocSZOkKbZYgJjhqIlnu87F_KcIxOl-Lpm7BKEVyBcXJBGb4S8fOBFzuT6IhfF4-UfG1ZDLR95vYZaQCq2O14xSODN_BNslJ3eMFiKqhIP5oqK7ZbUBRTmsaa-gwAlRegzL6IxphjnEcUhY0EcBoikURwUJMI0yuPSiwFKgbcA3qz9VzOlp2oznAKR1376aVqReg3QFUBXEz-BE0p9OFG6AHhB22k_hhO25Xqyoxs4EfCL0o8Vm9Ldbirs08OpkZSh6ONNhpJkRUNZAUsptvCLzoli8J4TSO-5YiMeh-UOAjTb7iqiGQR4zms9nU7hz3uAryGvNVRa8nq9IJoAlFBRKw3phkgjFaBoOp3uzfrh1c97EC4ASiGIr9plIZRMN7KGHsDdFIgX7cCs_EVnW6ZJ1kooiCbZ_MfZavXrylC7_nlhryDACxdEvzqEACH7mf8_jv5ZNP52HN9N8Z3Ghxr9s2j87Ti-m-I7jQ81-k7jI43ek0Z6zGdPpea3G3aoO6gkasMUfOB6A_WGK5gTeqcloex0Ti5qJSp2qpoA2OzCy8Imwcuqut9OdlL8yagGaNnduuQ1rZqCDWZWTHJS8f8SzUUN0HK2uv1Dcs3kdAPwLPV8s-694AVsn8AzgGdXXKsbQu-YbK9JUZgpgJKG1xqjTBt9HMepWWSmFJNGCjRcUPKZVI2tKUyt4DdmZC7MQn_wQm_MY6ZeQBFAkVHujSkB6zWsiZTigUmYcw0f2lt9q_kYloRXrJi2Crr58Xq2uoaqybdcQwL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