<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:SimSun;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@SimSun";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Please review the attached fix for a problem in the pass manager, and commit if acceptable. The fix is against TOT and has passed regression tests.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The problem is in the assignPassManager() methods. For example, in LoopPass::assignPassManager():<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>    // Create new Loop Pass Manager if it does not exist.<o:p></o:p></p><p class=MsoNormal>    assert (!PMS.empty() && "Unable to create Loop Pass Manager");<o:p></o:p></p><p class=MsoNormal>    PMDataManager *PMD = PMS.top();<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>    // [1] Create new Call Graph Pass Manager<o:p></o:p></p><p class=MsoNormal>    LPPM = new LPPassManager();<o:p></o:p></p><p class=MsoNormal>    LPPM->populateInheritedAnalysis(PMS);<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>    // [2] Set up new manager's top level manager<o:p></o:p></p><p class=MsoNormal>    PMTopLevelManager *TPM = PMD->getTopLevelManager();<o:p></o:p></p><p class=MsoNormal>    TPM->addIndirectPassManager(LPPM);<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>    // [3] Assign manager to manage this new manager. This may create<o:p></o:p></p><p class=MsoNormal>    // and push new managers into PMS<o:p></o:p></p><p class=MsoNormal>    Pass *P = LPPM->getAsPass();<o:p></o:p></p><p class=MsoNormal>    TPM->schedulePass(P);<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>    // [4] Push new manager into PMS<o:p></o:p></p><p class=MsoNormal>    PMS.push(LPPM);<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Step 3 above may create and push new managers into PMS, in which case the Depth of LPPM will no longer be correct. This may in turn cause other things to go wrong. For example, it may cause some analysis passes to be freed prematurely and cause crash.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>My fix is to not set the depth of a pass manager until it is pushed onto the stack.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Regards,<o:p></o:p></p><p class=MsoNormal>Xiaoyi<o:p></o:p></p></div></body></html>