[PATCH] D62507: [Dominators] PR42041: Skip nullpointer successors

Kristóf Umann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 28 06:17:54 PDT 2019


Szelethus added a comment.

In D62507#1518692 <https://reviews.llvm.org/D62507#1518692>, @NoQ wrote:

> @Szelethus, could you double-check that there's no way to tweak some graph traits (or something like that) in order to filter out null-successors specifically for Clang CFG? I don't immediately see a way to do that, but i might have missed something. Given that `ChildrenGetter<Direction>::Get` returns a `SmallVector`, it shouldn't be that impossible.
>
> Otherwise i hope an extra defensive check wouldn't hurt.


Yup,

  diff --git a/llvm/include/llvm/Support/GenericDomTreeConstruction.h b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
  index c64d2030c6f..14349dbd5b5 100644
  --- a/llvm/include/llvm/Support/GenericDomTreeConstruction.h
  +++ b/llvm/include/llvm/Support/GenericDomTreeConstruction.h
  @@ -111,12 +111,16 @@ struct SemiNCAInfo {
   
       static ResultTy Get(NodePtr N, std::integral_constant<bool, false>) {
         auto RChildren = reverse(children<NodePtr>(N));
  -      return ResultTy(RChildren.begin(), RChildren.end());
  +      ResultTy Ret(RChildren.begin(), RChildren.end());
  +      Ret.erase(std::remove(Ret.begin(), Ret.end(), nullptr), Ret.end());
  +      return Ret;
       }
   
       static ResultTy Get(NodePtr N, std::integral_constant<bool, true>) {
         auto IChildren = inverse_children<NodePtr>(N);
  -      return ResultTy(IChildren.begin(), IChildren.end());
  +      ResultTy Ret(IChildren.begin(), IChildren.end());
  +      Ret.erase(std::remove(Ret.begin(), Ret.end(), nullptr), Ret.end());
  +      return Ret;
       }
   
       using Tag = std::integral_constant<bool, Inverse>;

works perfectly, I'll just need to hide it in a template somehow.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D62507/new/

https://reviews.llvm.org/D62507





More information about the llvm-commits mailing list