[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Tue Feb 1 21:06:03 PST 2005



Changes in directory llvm-java/lib/Compiler:

Compiler.cpp updated: 1.207 -> 1.208
---
Log message:

Zero initialize allocated memory for each object. This fixes:
Collections, Collections1, Collections2.


---
Diffs of the changes:  (+15 -1)

 Compiler.cpp |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletion(-)


Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.207 llvm-java/lib/Compiler/Compiler.cpp:1.208
--- llvm-java/lib/Compiler/Compiler.cpp:1.207	Tue Feb  1 18:46:22 2005
+++ llvm-java/lib/Compiler/Compiler.cpp	Tue Feb  1 23:05:52 2005
@@ -72,7 +72,8 @@
     BasicBlock* currentBB_;
     Locals locals_;
     OperandStack opStack_;
-    Function *getObjectClass_, *setObjectClass_, *throw_, *isInstanceOf_;
+    Function *getObjectClass_, *setObjectClass_, *throw_, *isInstanceOf_,
+      *memset_;
 
     typedef SetVector<Function*> FunctionSet;
     FunctionSet toCompileFunctions_;
@@ -162,6 +163,10 @@
       isInstanceOf_ = module_.getOrInsertFunction(
         "llvm_java_IsInstanceOf", Type::IntTy,
         ObjectBaseRefTy, VTableBaseRefTy, NULL);
+      memset_ = module_.getOrInsertFunction(
+        "llvm.memset", Type::VoidTy,
+        PointerType::get(Type::SByteTy),
+        Type::UByteTy, Type::ULongTy, Type::UIntTy, NULL);
     }
 
   private:
@@ -2178,6 +2183,15 @@
       const VTableInfo& vi = getVTableInfo(cf);
 
       Value* objRef = new MallocInst(ci.getType(), NULL, TMP, currentBB_);
+      std::vector<Value*> params;
+      params.reserve(4);
+      params.push_back(new CastInst(objRef, PointerType::get(Type::SByteTy),
+                                    TMP, currentBB_)); // dest
+      params.push_back(ConstantUInt::get(Type::UByteTy, 0)); // value
+      params.push_back(ConstantExpr::getSizeOf(ci.getType())); // size
+      params.push_back(ConstantUInt::get(Type::UIntTy, 0)); // alignment
+      new CallInst(memset_, params, "", currentBB_);
+
       Value* objBase = new CastInst(objRef, ObjectBaseRefTy, TMP, currentBB_);
       Value* vtable = new CastInst(vi.vtable,
                                    VTableBaseRefTy,






More information about the llvm-commits mailing list