release/22.x: [MC] Try to fix ubsan bot#177907
Merged
c-rhodes merged 1 commit intollvm:release/22.xfrom Feb 3, 2026
Merged
Conversation
Member
Author
|
@llvm/pr-subscribers-llvm-mc Author: None (llvmbot) ChangesBackport d064f39 Requested by: @nikic 1 Files Affected:
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 5fd30eccb45c5..0c64d89d7b491 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -111,7 +111,8 @@ void MCObjectStreamer::appendContents(ArrayRef<char> Contents) {
assert(FragSpace >= Contents.size());
// As this is performance-sensitive code, explicitly use std::memcpy.
// Optimization of std::copy to memmove is unreliable.
- std::memcpy(getCurFragEnd(), Contents.begin(), Contents.size());
+ if (!Contents.empty())
+ std::memcpy(getCurFragEnd(), Contents.begin(), Contents.size());
CurFrag->FixedSize += Contents.size();
FragSpace -= Contents.size();
}
|
Contributor
|
(This did fix the ubsan buildbot.) |
c-rhodes
approved these changes
Feb 3, 2026
Collaborator
c-rhodes
left a comment
There was a problem hiding this comment.
seems like a simple fix that worked so im just going to go ahead and approve so we can land this
Check that the size is non-zero to make sure we don't call memcpy with null pointers. This is well-defined now, but ubsan may still warn about it. (cherry picked from commit d064f39)
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.
Backport d064f39
Requested by: @nikic