The design of the PreserveCFG Checker (landed as D81558 [NewPM] Introduce PreserveCFG check) has a fundamental flaw which makes it incorrect. The checker is based on the PreservedAnalyses result returned by functional passes: if CFGAnalyses is in the returned PreservedAnalyses set, then the checker asserts that the CFG snapshot saved before the pass is equal to the CFG snapshot taken after the the pass. The problem is in passes that change CFG and invalidate CFGAnalyses on their own. Such passes do not return CFGanalyses in the returned PreservedAnalyses. So the checker mistakenly expects CFG unchanged. As an example see the class TestSimplifyCFGInvalidatingAnalysisPass in the new tests.
It is interesting that the bug was not found in LLVM. That is because the CFG checker ran only if CFGAnalyses was checked incorrectly:
if (!PassPA.allAnalysesInSetPreserved<CFGAnalyses>()) return;
but must be checked as follows:
auto PAC = PA.getChecker<PreservedCFGCheckerAnalysis>(); if (!(PAC.preserved() || PAC.preservedSet<AllAnalysesOn<Function>>() || PAC.preservedSet<CFGAnalyses>()) return;
This fix and a fully redesigned checker will be sent as a separate follow-up patch.
could you please be more precise. Specifically state explicitly what is "accordingly".