Skip to content

[clang][deps] Call getMemBuffer with RequiresNullTerminator false - #195072

Merged
smithp35 merged 1 commit into
llvm:mainfrom
smithp35:read-without-requiring-null-terminate
Apr 30, 2026
Merged

[clang][deps] Call getMemBuffer with RequiresNullTerminator false#195072
smithp35 merged 1 commit into
llvm:mainfrom
smithp35:read-without-requiring-null-terminate

Conversation

@smithp35

Copy link
Copy Markdown
Contributor

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.

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.
@smithp35
smithp35 requested a review from jansvoboda11 April 30, 2026 12:47
@llvmorg-github-actions llvmorg-github-actions Bot added the clang Clang issues not falling into any other category label Apr 30, 2026
@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-clang

Author: Peter Smith (smithp35)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/195072.diff

1 Files Affected:

  • (modified) clang/lib/DependencyScanning/InProcessModuleCache.cpp (+2-1)
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

@jansvoboda11 jansvoboda11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@smithp35
smithp35 merged commit 7072b13 into llvm:main Apr 30, 2026
20 of 23 checks passed
enferex pushed a commit to enferex/llvm-project that referenced this pull request May 5, 2026
…vm#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.
moar55 pushed a commit to moar55/llvm-project that referenced this pull request May 12, 2026
…vm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants