[PATCH] D46568: [SimplifyCFG] Fix a crash when folding PHIs

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 7 17:36:43 PDT 2018


davide created this revision.
davide added reviewers: efriedma, aprantl, vsk, JDevlieghere, dblaikie.
Herald added a subscriber: hiraditya.

This fixes a crash found by @zhendongsu when running SimplifyCFG.
This is the gist:

We enter MergeBlockIntoPredecessor with a block looking like this:

  for.inc.us-lcssa:                                 ; preds = %cond.end
    %k.1.lcssa.ph = phi i32 [ %conv15, %cond.end ]
    %t.3.lcssa.ph = phi i32 [ %k.1.lcssa.ph, %cond.end ]
    br label %for.inc, !dbg !66
  
  [note the first arg of the PHI being a PHI].

`FoldSingleEntryPHINodes` gets rid of both PHIs (calling, eraseFromParent).
But right before we call the function, we push into `IncomingValues` the only argument of the PHIs, and shortly after we try to iterate over something which has been invalidated before :(

The way I propose(d) to fix this is that of not pushing into `IncomingValues` if `PN.getIncomingValue(0)` isa<PHINode>.
It seems enough to cover all the cases. Eli proposed to move the debug info handling in the function which takes care of folding the phi, although this is a little tricky because we remove the redundant dbg.values post slice (so it's left as a follow up).

An attempt to fix:
http://llvm.org/bugs/show_bug.cgi?id=37300 and rdar://problem/39910460

The thing that worries me the most is the testcase (as it's admittedly, insane). I spent some time trying to reduce it but I was never able to get to something manageable in size (or something which doesn't screw up debug info). `bugpoint` itself doesn't seem to help much here. Ideas on how to reduce further are appreciated :)


https://reviews.llvm.org/D46568

Files:
  llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
  llvm/test/Transforms/SimplifyCFG/fold-debug-info.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46568.145602.patch
Type: text/x-patch
Size: 35125 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180508/1635407b/attachment.bin>


More information about the llvm-commits mailing list