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