[llvm] r284633 - [GlobalMerge] Handle non-landingpad EH pads

Reid Kleckner via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 12:56:22 PDT 2016


Author: rnk
Date: Wed Oct 19 14:56:22 2016
New Revision: 284633

URL: http://llvm.org/viewvc/llvm-project?rev=284633&view=rev
Log:
[GlobalMerge] Handle non-landingpad EH pads

This code crashed on funclet-style EH instructions such as catchpad,
catchswitch, and cleanuppad. Just treat all EH pad instructions
equivalently and avoid merging the globals they reference through any
use.

Added:
    llvm/trunk/test/CodeGen/ARM/Windows/wineh-basic.ll
Modified:
    llvm/trunk/lib/CodeGen/GlobalMerge.cpp

Modified: llvm/trunk/lib/CodeGen/GlobalMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalMerge.cpp?rev=284633&r1=284632&r2=284633&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalMerge.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalMerge.cpp Wed Oct 19 14:56:22 2016
@@ -502,22 +502,18 @@ void GlobalMerge::collectUsedGlobalVaria
 void GlobalMerge::setMustKeepGlobalVariables(Module &M) {
   collectUsedGlobalVariables(M);
 
-  for (Module::iterator IFn = M.begin(), IEndFn = M.end(); IFn != IEndFn;
-       ++IFn) {
-    for (Function::iterator IBB = IFn->begin(), IEndBB = IFn->end();
-         IBB != IEndBB; ++IBB) {
-      // Follow the invoke link to find the landing pad instruction
-      const InvokeInst *II = dyn_cast<InvokeInst>(IBB->getTerminator());
-      if (!II) continue;
+  for (Function &F : M) {
+    for (BasicBlock &BB : F) {
+      Instruction *Pad = BB.getFirstNonPHI();
+      if (!Pad->isEHPad())
+        continue;
 
-      const LandingPadInst *LPInst = II->getUnwindDest()->getLandingPadInst();
-      // Look for globals in the clauses of the landing pad instruction
-      for (unsigned Idx = 0, NumClauses = LPInst->getNumClauses();
-           Idx != NumClauses; ++Idx)
+      // Keep globals used by landingpads and catchpads.
+      for (const Use &U : Pad->operands()) {
         if (const GlobalVariable *GV =
-            dyn_cast<GlobalVariable>(LPInst->getClause(Idx)
-                                     ->stripPointerCasts()))
+                dyn_cast<GlobalVariable>(U->stripPointerCasts()))
           MustKeepGlobalVariables.insert(GV);
+      }
     }
   }
 }

Added: llvm/trunk/test/CodeGen/ARM/Windows/wineh-basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/Windows/wineh-basic.ll?rev=284633&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/Windows/wineh-basic.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/Windows/wineh-basic.ll Wed Oct 19 14:56:22 2016
@@ -0,0 +1,48 @@
+; RUN: llc < %s | FileCheck %s
+
+; CHECK: "??1field@@AAA at XZ":
+; CHECK: bl free
+
+; C++ source:
+; class field { ~field(); };
+; extern "C" void free(void *ptr);
+; field::~field() { free((void *)0); }
+
+; ModuleID = 't.cpp'
+source_filename = "t.cpp"
+target datalayout = "e-m:w-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+target triple = "thumbv7--windows-msvc19.0.24210"
+
+%class.field = type { i8 }
+
+; Function Attrs: nounwind
+define arm_aapcs_vfpcc void @"\01??1field@@AAA at XZ"(%class.field* nocapture readnone %this) unnamed_addr #0 align 2 personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
+entry:
+  invoke arm_aapcs_vfpcc void @free(i8* null)
+          to label %invoke.cont unwind label %terminate
+
+invoke.cont:                                      ; preds = %entry
+  ret void
+
+terminate:                                        ; preds = %entry
+  %0 = cleanuppad within none []
+  tail call arm_aapcs_vfpcc void @__std_terminate() #2 [ "funclet"(token %0) ]
+  unreachable
+}
+
+declare arm_aapcs_vfpcc void @free(i8*) local_unnamed_addr #1
+
+declare arm_aapcs_vfpcc i32 @__CxxFrameHandler3(...)
+
+declare arm_aapcs_vfpcc void @__std_terminate() local_unnamed_addr
+
+attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a9" "target-features"="+dsp,+fp16,+neon,+strict-align,+vfp3" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="cortex-a9" "target-features"="+dsp,+fp16,+neon,+strict-align,+vfp3" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { noreturn nounwind }
+
+!llvm.module.flags = !{!0, !1}
+!llvm.ident = !{!2}
+
+!0 = !{i32 1, !"wchar_size", i32 2}
+!1 = !{i32 1, !"min_enum_size", i32 4}
+!2 = !{!"clang version 4.0.0 (trunk 284595) (llvm/trunk 284597)"}




More information about the llvm-commits mailing list