Fix a gcroot lowering bug.
authorEvan Cheng <evan.cheng@apple.com>
Sat, 1 Sep 2007 02:00:51 +0000 (02:00 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sat, 1 Sep 2007 02:00:51 +0000 (02:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41668 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LowerGC.cpp
test/CodeGen/Generic/GC/lower_gcroot.ll [new file with mode: 0644]

index e1576845dc2affffc60c570640d830abe4d76b3f..0da1d9199ba49889ab7fb7aeaf5fddc8ead07f97 100644 (file)
@@ -262,7 +262,7 @@ bool LowerGC::runOnFunction(Function &F) {
     cast<PointerType>(GCRootInt->getFunctionType()->getParamType(0));
   Constant *Null = ConstantPointerNull::get(PtrLocTy);
 
-  // Initialize all of the gcroot records now, and eliminate them as we go.
+  // Initialize all of the gcroot records now.
   for (unsigned i = 0, e = GCRoots.size(); i != e; ++i) {
     // Initialize the meta-data pointer.
     Par[2] = ConstantInt::get(Type::Int32Ty, i);
@@ -282,7 +282,6 @@ bool LowerGC::runOnFunction(Function &F) {
     new StoreInst(Constant::getNullValue(PtrLocTy->getElementType()),
                   GCRoots[i]->getOperand(1), GCRoots[i]);
     new StoreInst(GCRoots[i]->getOperand(1), RootPtrPtr, GCRoots[i]);
-    GCRoots[i]->getParent()->getInstList().erase(GCRoots[i]);
   }
 
   // Now that the record is all initialized, store the pointer into the global
@@ -290,6 +289,10 @@ bool LowerGC::runOnFunction(Function &F) {
   Value *C = new BitCastInst(AI, PointerType::get(MainRootRecordType), "", IP);
   new StoreInst(C, RootChain, IP);
 
+  // Eliminate all the gcroot records now.
+  for (unsigned i = 0, e = GCRoots.size(); i != e; ++i)
+    GCRoots[i]->getParent()->getInstList().erase(GCRoots[i]);
+
   // On exit from the function we have to remove the entry from the GC root
   // chain.  Doing this is straight-forward for return and unwind instructions:
   // just insert the appropriate copy.
diff --git a/test/CodeGen/Generic/GC/lower_gcroot.ll b/test/CodeGen/Generic/GC/lower_gcroot.ll
new file mode 100644 (file)
index 0000000..3a3abac
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | llc
+
+       %Env = type opaque*
+
+define void @.main(%Env) {
+       call void @llvm.gcroot( %Env* null, %Env null )
+       unreachable
+}
+
+declare void @llvm.gcroot(%Env*, %Env)