Skip to content

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

Closed
smithp35 wants to merge 1 commit into
llvm:mainfrom
smithp35:read-without-requiring-null-terminate
Closed

[clang][deps] Call getMemBuffer with RequiresNullTerminator false#194867
smithp35 wants to merge 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.

We have at one build with assertions enabled that is tripping over an assertion in MemoryBuffer that is checking for null termination. This failure is currently specific to this single machine and all attempts to reproduce have failed.

My working theory is that the length of path names are important so on most machines we may be adding trailing 0x0 bytes of padding which are being counted as null terminators.

Patch is in a draft state to see if we can tell if this fixes the problem.

@smithp35 smithp35 added the skip-precommit-approval PR for CI feedback, not intended for review label Apr 29, 2026
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 force-pushed the read-without-requiring-null-terminate branch from 15e8806 to 41f1091 Compare April 30, 2026 12:43
@smithp35

Copy link
Copy Markdown
Contributor Author

Closing in favour of full PR

@smithp35 smithp35 closed this Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-precommit-approval PR for CI feedback, not intended for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant