[PATCH] D21188: [CodeGen] Fix PrologEpilogInserter to avoid duplicate allocation of SEH structs

Etienne Bergeron via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 9 10:29:26 PDT 2016


etienneb created this revision.
etienneb added a reviewer: rnk.
etienneb added a subscriber: llvm-commits.

When stack-protection is activated and WinEH exceptions is used, 
the EHRegNode (exception handling registration) is allocated twice on the stack.

This was not breaking anything except loosing space on the stack.

```
D:\src\llvm\examples>llc exc2.ll  -debug-only=pei
alloc FI(0) at SP[-24]
alloc FI(1) at SP[-48]   <<-- Allocated
alloc FI(1) at SP[-72]   <<-- Allocated twice!?
alloc FI(2) at SP[-76]
alloc FI(4) at SP[-80]
alloc FI(3) at SP[-84]
```

http://reviews.llvm.org/D21188

Files:
  lib/CodeGen/PrologEpilogInserter.cpp

Index: lib/CodeGen/PrologEpilogInserter.cpp
===================================================================
--- lib/CodeGen/PrologEpilogInserter.cpp
+++ lib/CodeGen/PrologEpilogInserter.cpp
@@ -815,6 +815,11 @@
     MaxAlign = std::max(Align, MaxAlign);
   }
 
+  // Retrieve the Exception Handler registration node.
+  int EHRegNodeFrameIndex = INT_MAX;
+  if (const WinEHFuncInfo *FuncInfo = Fn.getWinEHFuncInfo())
+    EHRegNodeFrameIndex = FuncInfo->EHRegNodeFrameIndex;
+
   // Make sure that the stack protector comes before the local variables on the
   // stack.
   SmallSet<int, 16> ProtectedObjs;
@@ -837,7 +842,8 @@
         continue;
       if (MFI->isDeadObjectIndex(i))
         continue;
-      if (MFI->getStackProtectorIndex() == (int)i)
+      if (MFI->getStackProtectorIndex() == (int)i ||
+          EHRegNodeFrameIndex == (int)i)
         continue;
 
       switch (SP->getSSPLayout(MFI->getObjectAllocation(i))) {
@@ -866,10 +872,6 @@
 
   SmallVector<int, 8> ObjectsToAllocate;
 
-  int EHRegNodeFrameIndex = INT_MAX;
-  if (const WinEHFuncInfo *FuncInfo = Fn.getWinEHFuncInfo())
-    EHRegNodeFrameIndex = FuncInfo->EHRegNodeFrameIndex;
-
   // Then prepare to assign frame offsets to stack objects that are not used to
   // spill callee saved registers.
   for (unsigned i = 0, e = MFI->getObjectIndexEnd(); i != e; ++i) {
@@ -882,9 +884,8 @@
       continue;
     if (MFI->isDeadObjectIndex(i))
       continue;
-    if (MFI->getStackProtectorIndex() == (int)i)
-      continue;
-    if (EHRegNodeFrameIndex == (int)i)
+    if (MFI->getStackProtectorIndex() == (int)i ||
+        EHRegNodeFrameIndex == (int)i)
       continue;
     if (ProtectedObjs.count(i))
       continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21188.60195.patch
Type: text/x-patch
Size: 1709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160609/e6729db5/attachment.bin>


More information about the llvm-commits mailing list