[PATCH] D18252: Drop comdats from the dst module if they are not selected

Mehdi AMINI via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 22 14:08:01 PDT 2016


joker.eph requested changes to this revision.
This revision now requires changes to proceed.

================
Comment at: llvm/lib/Linker/LinkModules.cpp:503
@@ +502,3 @@
+  if (Declaration->use_empty())
+    Declaration->eraseFromParent();
+}
----------------
joker.eph wrote:
> What's happening here is not super nice in the alias case, since you're creating a new GlobalVariable to trash it right after.
> Can't this be done before the if with an early return like below?
> 
> ```
> if (!ReplacedDstComdats.count(C))
>     return;
> if (Declaration->use_empty()) {
>     Declaration->eraseFromParent();
>     return;
> }
>   if (auto *F = dyn_cast<Function>(&GV))
>     F->deleteBody();
>  else if (auto *Var = dyn_cast<GlobalVariable>(&GV)) 
>     Var->setInitializer(nullptr);
>  else { // alias case
>        auto &Alias = cast<GlobalAlias>(GV);
>     Module &M = *Alias.getParent();
>     PointerType &Ty = *cast<PointerType>(Alias.getType());
>     GlobalValue::LinkageTypes L = Alias.getLinkage();
>     auto Declaration =
>         new GlobalVariable(M, Ty.getElementType(), /*isConstant*/ false, L,
>                            /*Initializer*/ nullptr);
>     Declaration->takeName(&Alias);
>     Alias.replaceAllUsesWith(Declaration);
>     Alias.eraseFromParent();
> }
> ```
ping?


http://reviews.llvm.org/D18252





More information about the llvm-commits mailing list