[clang] [libclang] Document CXUnsavedFile::Length width and fix test narrowing (PR #228405)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 16 05:24:41 PDT 2026


================
@@ -82,9 +82,11 @@ class LibclangParseTest : public ::testing::Test {
         fixed_addr_string(new std::string(Filename)),
         fixed_addr_string(new std::string(Contents))));
     UnsavedFiles.push_back({
-        it.first->first->c_str(),   // filename
-        it.first->second->c_str(),  // contents
-        it.first->second->size()    // length
+        it.first->first->c_str(),  // filename
+        it.first->second->c_str(), // contents
+        // CXUnsavedFile::Length is `unsigned long`, which is 32 bits on
+        // 64-bit Windows, so converting from size_t here narrows.
+        static_cast<unsigned long>(it.first->second->size()) // length
----------------
UebelAndre wrote:

> Huh, do we not have any 32-bit post-commit CI bots? I know we don't have one for Windows, but we wouldn't build the tests there anyway. But other platforms should hit the same failure.

Narrowing requires `size_t` wider than `unsigned long` and on ILP32 both are 32 bits. So I think this can only be caught on a 64 bit system.

> Is this the only such failure we have?

It's the only one that I've found but I'm fairly new to llvm-project so I may not be looking in all the right places.

https://github.com/llvm/llvm-project/pull/228405


More information about the cfe-commits mailing list