[llvm-commits] [llvm] r140277 - /llvm/trunk/lib/CodeGen/ShadowStackGC.cpp

Bill Wendling isanbard at gmail.com
Wed Sep 21 15:14:28 PDT 2011


Author: void
Date: Wed Sep 21 17:14:28 2011
New Revision: 140277

URL: http://llvm.org/viewvc/llvm-project?rev=140277&view=rev
Log:
Attempt to update the shadow stack GC pass to the new EH model.

This inserts a cleanup landingpad instruction and a resume to mimic the old
unwind instruction.

Modified:
    llvm/trunk/lib/CodeGen/ShadowStackGC.cpp

Modified: llvm/trunk/lib/CodeGen/ShadowStackGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ShadowStackGC.cpp?rev=140277&r1=140276&r2=140277&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ShadowStackGC.cpp (original)
+++ llvm/trunk/lib/CodeGen/ShadowStackGC.cpp Wed Sep 21 17:14:28 2011
@@ -109,7 +109,7 @@
         State = 1;
 
       case 1:
-        // Find all 'return' and 'unwind' instructions.
+        // Find all 'return', 'resume', and 'unwind' instructions.
         while (StateBB != StateE) {
           BasicBlock *CurBB = StateBB++;
 
@@ -141,9 +141,21 @@
           return 0;
 
         // Create a cleanup block.
-        BasicBlock *CleanupBB = BasicBlock::Create(F.getContext(),
-                                                   CleanupBBName, &F);
-        UnwindInst *UI = new UnwindInst(F.getContext(), CleanupBB);
+        LLVMContext &C = F.getContext();
+        BasicBlock *CleanupBB = BasicBlock::Create(C, CleanupBBName, &F);
+        Type *ExnTy = StructType::get(Type::getInt8PtrTy(C),
+                                      Type::getInt32Ty(C), NULL);
+        // FIXME: Assuming the C++ personality function probably isn't the best
+        //        thing in the world.
+        Constant *PersFn =
+          F.getParent()->
+          getOrInsertFunction("__gxx_personality_v0",
+                              FunctionType::get(Type::getInt32Ty(C), true));
+        LandingPadInst *LPad = LandingPadInst::Create(ExnTy, PersFn, 1,
+                                                      "cleanup.lpad",
+                                                      CleanupBB);
+        LPad->setCleanup(true);
+        ResumeInst *RI = ResumeInst::Create(LPad, CleanupBB);
 
         // Transform the 'call' instructions into 'invoke's branching to the
         // cleanup block. Go in reverse order to make prettier BB names.
@@ -174,7 +186,7 @@
           delete CI;
         }
 
-        Builder.SetInsertPoint(UI->getParent(), UI);
+        Builder.SetInsertPoint(RI->getParent(), RI);
         return &Builder;
       }
     }





More information about the llvm-commits mailing list