[PATCH] D61063: [ExecutionEngine] Fix a compiler warning in StoreValueToMemory

Pavel Labath via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 06:04:16 PDT 2019


labath created this revision.
labath added a reviewer: lhames.
Herald added a project: LLVM.

gcc was diagnosing a memcpy in this function with "memcpy writing to an
object of type 'struct llvm::GenericValue' with no trivial
copy-assignment". After closer examination, it became clear that the
pointer in the function *never* refers to a GenericValue object, and all
callers cast some other pointer (typically void*) to GenericValue*.
There doesn't seem to be any reason for such a convoluted solution so I
just change the function to accept a void* instead, which has the nice
side-effect of fixing the warning as well.


Repository:
  rL LLVM

https://reviews.llvm.org/D61063

Files:
  include/llvm/ExecutionEngine/ExecutionEngine.h
  lib/ExecutionEngine/ExecutionEngine.cpp
  lib/ExecutionEngine/Interpreter/Execution.cpp


Index: lib/ExecutionEngine/Interpreter/Execution.cpp
===================================================================
--- lib/ExecutionEngine/Interpreter/Execution.cpp
+++ lib/ExecutionEngine/Interpreter/Execution.cpp
@@ -1049,8 +1049,7 @@
   ExecutionContext &SF = ECStack.back();
   GenericValue Val = getOperandValue(I.getOperand(0), SF);
   GenericValue SRC = getOperandValue(I.getPointerOperand(), SF);
-  StoreValueToMemory(Val, (GenericValue *)GVTOP(SRC),
-                     I.getOperand(0)->getType());
+  StoreValueToMemory(Val, GVTOP(SRC), I.getOperand(0)->getType());
   if (I.isVolatile() && PrintVolatile)
     dbgs() << "Volatile store: " << I;
 }
Index: lib/ExecutionEngine/ExecutionEngine.cpp
===================================================================
--- lib/ExecutionEngine/ExecutionEngine.cpp
+++ lib/ExecutionEngine/ExecutionEngine.cpp
@@ -355,14 +355,12 @@
     Dest[Size-1] = 0;
 
     // Endian safe: Array[i] = (PointerTy)Dest;
-    EE->StoreValueToMemory(PTOGV(Dest.get()),
-                           (GenericValue*)(&Array[i*PtrSize]), SBytePtr);
+    EE->StoreValueToMemory(PTOGV(Dest.get()), &Array[i * PtrSize], SBytePtr);
     Values.push_back(std::move(Dest));
   }
 
   // Null terminate it
-  EE->StoreValueToMemory(PTOGV(nullptr),
-                         (GenericValue*)(&Array[InputArgv.size()*PtrSize]),
+  EE->StoreValueToMemory(PTOGV(nullptr), &Array[InputArgv.size() * PtrSize],
                          SBytePtr);
   return Array.get();
 }
@@ -1045,8 +1043,8 @@
   }
 }
 
-void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
-                                         GenericValue *Ptr, Type *Ty) {
+void ExecutionEngine::StoreValueToMemory(const GenericValue &Val, void *Ptr,
+                                         Type *Ty) {
   const unsigned StoreBytes = getDataLayout().getTypeStoreSize(Ty);
 
   switch (Ty->getTypeID()) {
@@ -1068,7 +1066,7 @@
   case Type::PointerTyID:
     // Ensure 64 bit target pointers are fully initialized on 32 bit hosts.
     if (StoreBytes != sizeof(PointerTy))
-      memset(&(Ptr->PointerVal), 0, StoreBytes);
+      memset(Ptr, 0, StoreBytes);
 
     *((PointerTy*)Ptr) = Val.PointerVal;
     break;
@@ -1227,7 +1225,7 @@
 
   if (Init->getType()->isFirstClassType()) {
     GenericValue Val = getConstantValue(Init);
-    StoreValueToMemory(Val, (GenericValue*)Addr, Init->getType());
+    StoreValueToMemory(Val, Addr, Init->getType());
     return;
   }
 
Index: include/llvm/ExecutionEngine/ExecutionEngine.h
===================================================================
--- include/llvm/ExecutionEngine/ExecutionEngine.h
+++ include/llvm/ExecutionEngine/ExecutionEngine.h
@@ -384,11 +384,8 @@
   const GlobalValue *getGlobalValueAtAddress(void *Addr);
 
   /// StoreValueToMemory - Stores the data in Val of type Ty at address Ptr.
-  /// Ptr is the address of the memory at which to store Val, cast to
-  /// GenericValue *.  It is not a pointer to a GenericValue containing the
-  /// address at which to store Val.
-  void StoreValueToMemory(const GenericValue &Val, GenericValue *Ptr,
-                          Type *Ty);
+  /// Ptr is the address of the memory at which to store Val.
+  void StoreValueToMemory(const GenericValue &Val, void *Ptr, Type *Ty);
 
   void InitializeMemory(const Constant *Init, void *Addr);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61063.196433.patch
Type: text/x-patch
Size: 3352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190424/bbdc68be/attachment.bin>


More information about the llvm-commits mailing list