@@ -670,13 +670,29 @@ int Abc_NtkFraigStore( Abc_Ntk_t * pNtkAdd )
670670 extern int Abc_NodeCompareCiCo ( Abc_Ntk_t * pNtkOld , Abc_Ntk_t * pNtkNew );
671671 if ( !Abc_NodeCompareCiCo (pNtk , (Abc_Ntk_t * )Vec_PtrEntry (vStore , 0 )) )
672672 {
673+ // Abc_NtkCompareSignals() sorts the PIs/POs/boxes of both networks by name as a
674+ // side effect, which is what makes the comparison meaningful when the two do use
675+ // the same names. When they do not, the comparison fails, the store is reset and
676+ // this network is kept -- so the sort has to be undone here. Otherwise the stored
677+ // network is a permutation of the one the caller read in, and everything after it
678+ // is off by that permutation with nothing to indicate it.
679+ Vec_Ptr_t * vPis = Vec_PtrDup ( pNtk -> vPis );
680+ Vec_Ptr_t * vPos = Vec_PtrDup ( pNtk -> vPos );
681+ Vec_Ptr_t * vBoxes = Vec_PtrDup ( pNtk -> vBoxes );
673682 // reorder PIs of pNtk2 according to pNtk1
674683 if ( !Abc_NtkCompareSignals ( pNtk , (Abc_Ntk_t * )Vec_PtrEntry (vStore , 0 ), 1 , 1 ) )
675684 {
685+ Vec_PtrFree ( pNtk -> vPis ); pNtk -> vPis = vPis ; vPis = NULL ;
686+ Vec_PtrFree ( pNtk -> vPos ); pNtk -> vPos = vPos ; vPos = NULL ;
687+ Vec_PtrFree ( pNtk -> vBoxes ); pNtk -> vBoxes = vBoxes ; vBoxes = NULL ;
688+ Abc_NtkOrderCisCos ( pNtk );
676689 printf ( "Trying to store the network with different primary inputs.\n" );
677690 printf ( "The previously stored networks are deleted and this one is added.\n" );
678691 Abc_NtkFraigStoreClean ();
679692 }
693+ if ( vPis ) Vec_PtrFree ( vPis );
694+ if ( vPos ) Vec_PtrFree ( vPos );
695+ if ( vBoxes ) Vec_PtrFree ( vBoxes );
680696 }
681697 }
682698 Vec_PtrPush ( vStore , pNtk );
0 commit comments