Author: Nikita Popov
Date: 2026-02-03T09:23:00Z
New Revision: 6d994d8bf614ffcee0ec491eb80a479cc884f633

URL: 
https://github.com/llvm/llvm-project/commit/6d994d8bf614ffcee0ec491eb80a479cc884f633
DIFF: 
https://github.com/llvm/llvm-project/commit/6d994d8bf614ffcee0ec491eb80a479cc884f633.diff

LOG: [MC] Try to fix ubsan bot

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 d064f395af7ac226dec3f8e90516a26e96e2acf1)

Added: 
    

Modified: 
    llvm/lib/MC/MCObjectStreamer.cpp

Removed: 
    


################################################################################
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();
 }


        
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to