When current state is CFG_Finalized, function validateCFG() should return true directly.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
In the validateSuccessorInvariants function, we validate the correspondence between the number of successors and the type of branching instruction. An error is triggered when an instruction is an unconditional branch and has no successors.
When there is a "b _ZdlPvm@PLT" TailCall instruction at the end of a basic block. This instruction jumps to the PLT table, and does not have any successors. Although this instruction is an unconditional jump, the function “isUnconditionalBranch” returns false because the inst is a TailCall and doesn’t need CFG validation.
However, when the “inst-lowering” Pass is applied, the lowerTailCall function is invoked, removing the “kTailCall” label from this instruction. Consequently, the isTailCall(Inst) function returns true, which then leads to an error during the CFG validation of this instruction.
I agree that we shouldn't validate CFG after the instruction lowering pass. Thanks for the fix and for providing the explanation.
Implementation-wise, I think we should make the validation requirement even stronger. Once a CFG is finalized, i.e. a function is in CFG_Finalized state, we should skip the check. You can simply return true from validateCFG().
nit: drop curly braces.