[LLVM] Don't memcpy from a null pointer for empty byte-array properties - #23077
Merged
uditagarwal97 merged 1 commit intoSep 2, 2026
Merged
Conversation
PropertyValue's byte-array constructor called std::memcpy unconditionally, but an empty container yields a null data pointer and memcpy declares both operands as nonnull, so every -fsycl compilation that serialized an empty byte array hit undefined behaviour. Skip the copy when there is nothing to copy, and add the unit test that would have caught it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix correctly addresses the undefined behavior and includes suitable regression coverage.
Pull request overview
Prevents undefined behavior when constructing empty byte-array properties.
Changes:
- Guards
memcpywhen the data size is zero. - Adds a regression test for empty containers.
File summaries
| File | Description |
|---|---|
llvm/lib/Support/PropertySetIO.cpp |
Skips zero-length byte-array copies. |
llvm/unittests/Support/PropertySetIOTest.cpp |
Tests empty byte-array construction. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
uditagarwal97
marked this pull request as ready for review
September 1, 2026 23:21
Contributor
Author
|
CI failure is unrelated. Merging! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
PropertyValue::PropertyValue(const byte *Data, SizeTy DataBitSize)inllvm/lib/Support/PropertySetIO.cppends with:Datais null whenever the property value is an empty container: the templated constructor inllvm/include/llvm/Support/PropertySetIO.hforwardsData.data(), and for an emptystd::vector<char>/SmallVectorthat isnullptr.memcpy's parameters are declared__attribute__((nonnull)), somemcpy(dst, nullptr, 0)is undefined behaviour even though the length is zero (https://en.cppreference.com/cpp/string/byte/memcpy)UBSan diagnostic (build configured with
-DLLVM_USE_SANITIZER=Address;Undefined):Fix
Skip the copy when there is nothing to copy:
Co-Authored-By: Claude Opus 5 (1M context) noreply@anthropic.com