[clang] [clang][deps] Call getMemBuffer with RequiresNullTerminator false (PR #195072)
Peter Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 30 05:47:42 PDT 2026
https://github.com/smithp35 created https://github.com/llvm/llvm-project/pull/195072
The getMemBuffer() has a default parameter RequiresNullTerminator which is set to true.
In ModuleCache the MemoryBuffer::getOpenFile is called with /* RequiresNullTerminator=*/false. This means that initial contents of the MemoryBuffer may not have a trailing 0x0 at the end of the file.
When assertions are enabled and RequiresNullTerminator is true the MemoryBuffer will trigger a "Buffer is not null terminated!" assertion failure if BufEnd[0] != 0.
We have at one build with assertions enabled that is triggering this MemoryBuffer assertion failure in the check-clang tests:
* ClangScanDeps/modules-dep-args.c
* Driver/modules-driver-import-std.cpp
The failure is specific to one particular machine, we have not been able to reproduce locally. It is possible that the failure is filesystem type or path length dependent.
Changing the RequiresNullTerminator in getMemBuffer to false to match the value of RequiresNullTerminator in getOpenFile fixes the problem and all tests pass.
>From 41f1091f16b2e56e9657213739c11d9b799d89bf Mon Sep 17 00:00:00 2001
From: Peter Smith <peter.smith at arm.com>
Date: Wed, 29 Apr 2026 11:41:17 +0100
Subject: [PATCH] [clang][deps] Call getMemBuffer with RequiresNullTerminator
false
The getMemBuffer() has a default parameter RequiresNullTerminator
which is set to true.
In ModuleCache the MemoryBuffer::getOpenFile is called with /*
RequiresNullTerminator=*/false. This means that initial contents of
the MemoryBuffer may not have a trailing 0x0 at the end of the file.
When assertions are enabled and RequiresNullTerminator is true the
MemoryBuffer will trigger a "Buffer is not null terminated!"
assertion failure if BufEnd[0] != 0.
We have at one build with assertions enabled that is triggering this
MemoryBuffer assertion failure in the check-clang tests:
* ClangScanDeps/modules-dep-args.c
* Driver/modules-driver-import-std.cpp
The failure is specific to one particular machine, we have not been
able to reproduce locally. It is possible that the failure is
filesystem type or path length dependent.
Changing the RequiresNullTerminator in getMemBuffer to false to match
the value of RequiresNullTerminator in getOpenFile fixes the problem
and all tests pass.
---
clang/lib/DependencyScanning/InProcessModuleCache.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/lib/DependencyScanning/InProcessModuleCache.cpp b/clang/lib/DependencyScanning/InProcessModuleCache.cpp
index 7bbad3ca1da3a..538ff2952c4f5 100644
--- a/clang/lib/DependencyScanning/InProcessModuleCache.cpp
+++ b/clang/lib/DependencyScanning/InProcessModuleCache.cpp
@@ -179,7 +179,8 @@ class InProcessModuleCache : public ModuleCache {
}
Size = Entry.Buffer->getBufferSize();
ModTime = Entry.ModTime;
- return llvm::MemoryBuffer::getMemBuffer(*Entry.Buffer);
+ return llvm::MemoryBuffer::getMemBuffer(*Entry.Buffer,
+ /* RequiresNullTerminator */ false);
}
};
} // namespace
More information about the cfe-commits
mailing list