Skip to content

release/22.x: [MC] Try to fix ubsan bot#177907

Merged
c-rhodes merged 1 commit intollvm:release/22.xfrom
llvmbot:issue177187
Feb 3, 2026
Merged

release/22.x: [MC] Try to fix ubsan bot#177907
c-rhodes merged 1 commit intollvm:release/22.xfrom
llvmbot:issue177187

Conversation

@llvmbot
Copy link
Copy Markdown
Member

@llvmbot llvmbot commented Jan 26, 2026

Backport d064f39

Requested by: @nikic

@llvmbot
Copy link
Copy Markdown
Member Author

llvmbot commented Jan 26, 2026

@llvm/pr-subscribers-llvm-mc

Author: None (llvmbot)

Changes

Backport d064f39

Requested by: @nikic


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

1 Files Affected:

  • (modified) llvm/lib/MC/MCObjectStreamer.cpp (+2-1)
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();
 }

@nikic nikic requested a review from pcc January 26, 2026 08:30
@nikic
Copy link
Copy Markdown
Contributor

nikic commented Jan 26, 2026

(This did fix the ubsan buildbot.)

@c-rhodes c-rhodes moved this from Needs Triage to Needs Review in LLVM Release Status Jan 26, 2026
Copy link
Copy Markdown
Collaborator

@c-rhodes c-rhodes left a comment

Choose a reason for hiding this comment

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

seems like a simple fix that worked so im just going to go ahead and approve so we can land this

@github-project-automation github-project-automation Bot moved this from Needs Review to Needs Merge in LLVM Release Status Feb 3, 2026
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)
@c-rhodes c-rhodes merged commit 6d994d8 into llvm:release/22.x Feb 3, 2026
1 check was pending
@github-project-automation github-project-automation Bot moved this from Needs Merge to Done in LLVM Release Status Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:mc Machine (object) code

Projects

Development

Successfully merging this pull request may close these issues.

3 participants