[PATCH v2 1/1] utils: Fix segfault in flattencfg

Matt Arsenault arsenm2 at gmail.com
Fri Aug 8 14:18:10 PDT 2014


On Aug 8, 2014, at 1:41 PM, Jan Vesely <jan.vesely at rutgers.edu> wrote:

> v2: continue iterating through the rest of the bb
>    use for loop
> 
> Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> ---
> lib/Transforms/Utils/FlattenCFG.cpp | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/Transforms/Utils/FlattenCFG.cpp b/lib/Transforms/Utils/FlattenCFG.cpp
> index 51ead40..4eb3e3d 100644
> --- a/lib/Transforms/Utils/FlattenCFG.cpp
> +++ b/lib/Transforms/Utils/FlattenCFG.cpp
> @@ -238,9 +238,13 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder,
>     // Do branch inversion.
>     BasicBlock *CurrBlock = LastCondBlock;
>     bool EverChanged = false;
> -    while (1) {
> +    for (;CurrBlock != FirstCondBlock;
> +          CurrBlock = CurrBlock->getSinglePredecessor()) {
>       BranchInst *BI = dyn_cast<BranchInst>(CurrBlock->getTerminator());
>       CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition());
> +      if (!CI)
> +        continue;
> +
>       CmpInst::Predicate Predicate = CI->getPredicate();
>       // Canonicalize icmp_ne -> icmp_eq, fcmp_one -> fcmp_oeq
>       if ((Predicate == CmpInst::ICMP_NE) || (Predicate == CmpInst::FCMP_ONE)) {
> @@ -248,9 +252,6 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder,
>         BI->swapSuccessors();
>         EverChanged = true;
>       }
> -      if (CurrBlock == FirstCondBlock)
> -        break;
> -      CurrBlock = CurrBlock->getSinglePredecessor();
>     }
>     return EverChanged;
>   }

Needs tests





More information about the llvm-commits mailing list