[PATCH] D38940: Make x86 __ehhandler comdat if parent function is

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 09:59:33 PDT 2017


rnk added a comment.

Thanks! Needs a test case. It should be possible to test this directly with `opt`.



================
Comment at: lib/Target/X86/X86WinEHState.cpp:404-405
                        TheModule);
+  if (ParentFunc->getComdat())
+    Trampoline->setComdat(TheModule->getOrInsertComdat(ParentFunc->getName()));
   BasicBlock *EntryBB = BasicBlock::Create(Context, "entry", Trampoline);
----------------
It's probably more correct to take the comdat of ParentFunc directly, like this:
  if (auto *C = ParentFunc->getComdat())
    Trampoline->setComdat(C);

This is unlikely to matter in practice. The only way I can think of to get into a situation where it matters is perhaps:
  int g();
  static int f() { // will make an __ehhandler and get inlined into the initializer for x
    try { return g(); } catch (...) { return 0; }
  }
  int __declspec(selectany) x = f(); // will create a dynamic initializer function comdat with 'x'


https://reviews.llvm.org/D38940





More information about the llvm-commits mailing list