r243973 - [CodeGen] Don't write into a SmallVector's uninitialized memory.

Benjamin Kramer benny.kra at googlemail.com
Tue Aug 4 05:34:30 PDT 2015


Author: d0k
Date: Tue Aug  4 07:34:30 2015
New Revision: 243973

URL: http://llvm.org/viewvc/llvm-project?rev=243973&view=rev
Log:
[CodeGen] Don't write into a SmallVector's uninitialized memory.

That's just ugly and not needed in this case. No functionality change.

Modified:
    cfe/trunk/lib/CodeGen/CGCleanup.cpp

Modified: cfe/trunk/lib/CodeGen/CGCleanup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=243973&r1=243972&r2=243973&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCleanup.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCleanup.cpp Tue Aug  4 07:34:30 2015
@@ -685,13 +685,10 @@ void CodeGenFunction::PopCleanupBlock(bo
   // Copy the cleanup emission data out.  Note that SmallVector
   // guarantees maximal alignment for its buffer regardless of its
   // type parameter.
-  SmallVector<char, 8*sizeof(void*)> CleanupBuffer;
-  CleanupBuffer.reserve(Scope.getCleanupSize());
-  memcpy(CleanupBuffer.data(),
-         Scope.getCleanupBuffer(), Scope.getCleanupSize());
-  CleanupBuffer.set_size(Scope.getCleanupSize());
-  EHScopeStack::Cleanup *Fn =
-    reinterpret_cast<EHScopeStack::Cleanup*>(CleanupBuffer.data());
+  auto *CleanupSource = reinterpret_cast<char *>(Scope.getCleanupBuffer());
+  SmallVector<char, 8 * sizeof(void *)> CleanupBuffer(
+      CleanupSource, CleanupSource + Scope.getCleanupSize());
+  auto *Fn = reinterpret_cast<EHScopeStack::Cleanup *>(CleanupBuffer.data());
 
   EHScopeStack::Cleanup::Flags cleanupFlags;
   if (Scope.isNormalCleanup())





More information about the cfe-commits mailing list