[llvm-branch-commits] [clang] c4736b9 - Don't memcpy from an empty ArrayRef; the base pointer could be null, and

Richard Smith via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Dec 15 14:42:53 PST 2020


Author: Richard Smith
Date: 2020-12-15T14:37:52-08:00
New Revision: c4736b91f87e9163edcdef78891398f32390ffc2

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

LOG: Don't memcpy from an empty ArrayRef; the base pointer could be null, and
the C rules say memcpy can't accept a null pointer.

This should fix a test failure with the ubsan buildbots.

Added: 
    

Modified: 
    clang/lib/AST/APValue.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 5b340e6e85bd..c18f8854dc2b 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -952,8 +952,10 @@ void APValue::setLValue(LValueBase B, const CharUnits &O,
                         bool IsNullPtr) {
   MutableArrayRef<APValue::LValuePathEntry> InternalPath =
       setLValueUninit(B, O, Path.size(), IsOnePastTheEnd, IsNullPtr);
-  memcpy(InternalPath.data(), Path.data(),
-         Path.size() * sizeof(LValuePathEntry));
+  if (Path.size()) {
+    memcpy(InternalPath.data(), Path.data(),
+           Path.size() * sizeof(LValuePathEntry));
+  }
 }
 
 void APValue::setUnion(const FieldDecl *Field, const APValue &Value) {


        


More information about the llvm-branch-commits mailing list