Поиск характерных шаблонов кода, приводящих к ошибкам функционирования в программах промышленного размера (1162573), страница 3
Текст из файла (страница 3)
f i n d ( "-split-" ) ;if ( f != s t d : : s t r i n g : : n p o s ) {Stringlp=FunctionName . s u b s t r ( f ) ;Stringfp=FunctionName . s u b s t r ( 0 ,std : : size_tfp}=ff=fp . substr ( f freturnelse {fp+fp . find_last_of (+1) ;lp ;std : : size_tffStringfpFunctionName . s u b s t r ( f freturnfp ;=f ) ;"-" ) ;=FunctionName .
f i n d _ l a s t _ o f (+"-" ) ;1) ;}}/// Return llvm Function 's basic block 's count.inline unsigned int getBBCount ( ) {return BBCount ;}/// Return count of 'controle ' edges in graph.inline unsigned int g e t C o n t r o l D e p C o u n t ( ) {return C o n t r o l D e p C o u n t ;}/// Return count of 'true ' edges count in graph.inline unsigned int g e t T r u e D e p C o u n t ( ) {return TrueDepCount ;}/// Return count of 'anti ' edges count in graph.inline unsigned int g e t A n t i D e p C o u n t ( ) {return A n t i D e p C o u n t ;}/// Return count of 'output ' edges count in graph.16inline unsigned int g e t O u t p u t D e p C o u n t ( )return OutputDepCount ;{}/// Return number of llvm Function 's called functions .inline unsigned int g e t C a l l y F u n c t i o n s C o u n t ( ) {return C a l l y F u n c t i o n s C o u n t ;}/// Return vector , which contains counts of every node type in graph.inline s t d : : v e c t o r <int >* g e t C h a r a c t e r i s t i c V e c t o r ( ) {return &v e c t o r ;}inline s t d : : v e c t o r <s t d : : s e t <int> >*return &c h a r a c h t e r i s t i c s B y S o u r c e ;getCharachteristicsBySourceLines ()}/// Return avrage degree of PDG.inline float g e t A v e r a g e D e g r e e ( ) {return A v e r a g e D e g r e e ;}/// Return true if PDG is result of merge.inline bool g e t M e r g e d ( ) {return Merged ;}/// Return charachteristic vector sizeinline unsigned g e t V e c t o r L e n g t h ( ) {return v e c t o r L e n g t h ;}/// Return number of correspondin source linesinline unsigned g e t S o u r c e L i n e s C o u n t ( ) {return s o u r c e L i n e s C o u n t ;}// Set functions for graph membersinline voidsetAbsFP ( S t r i n gabsFP ){AbsFP = absFP ;}inline voidsetFunctionName ( S t r i n gFunctionNameFN){= FN ;}inline voidsetBBCount (unsigned intbb ){BBCount = bb ;}inline voidsetControlDepCount (ControlDepCount=unsigned intcd )cd ;}inline voidsetTrueDepCount (unsigned int17td ){{{TrueDepCount=td ;}inline voidsetAntiDepCount (AntiDepCount=unsigned intad ){ad ;}inline voidsetOutputDepCount (OutputDepCount=unsigned intod ){od ;}inline voidsetCallyFunctionsCount (CallyFunctionsCount=unsigned intcf ){cf ;}inline voidMerged=setMerged (boolval=true ){val ;}// FIXME: try to make more effective/// Return node by node number.DepGraphNode * g e t N o d e ( unsigned nnumber ) const{for ( unsigned i = 0 ; i < d e p N o d e V e c t .
s i z e ( ) ; ++i )if ( d e p N o d e V e c t [ i ] ->getNNumber ( ) == nnumber )return d e p N o d e V e c t [ i ] ;assert (falsereturnNULL ;&&"Node for this instruction does not exists!" ) ;}/// Optimize graph , remove nodes which deosn 't have edges or/// correspondence source code.void cleanUpPDG ( bool f u l l = false ) {DepNodeVectTypeif( full )tmp ;{while ( ! d e p N o d e V e c t . empty ( ) )if ( d e p N o d e V e c t . b a c k ( ) ->g e t L i n e N ( )==- 1){tmp .
push_back ( d e p N o d e V e c t . b a c k ( ) ) ;d e p N o d e V e c t . pop_back ( ) ;}else {break ;}for ( int i = d e p N o d e V e c t . s i z e ( ) - 2 ; i >=if ( d e p N o d e V e c t [ i ] ->g e t L i n e N ( ) == - 1 ) {0;- - i )tmp . push_back ( d e p N o d e V e c t [ i ] ) ;s t d : : swap ( d e p N o d e V e c t [ i ] ,depNodeVect . back ( ) ) ;d e p N o d e V e c t . pop_back ( ) ;}for(unsignedi=0;i< tmp . s i z e ( ) ;tmp [ i ] ->e r a s e N o d e ( ) ;deletetmp [ i ] ;}18++i ){}tmp . c l e a r ( ) ;while ( ! d e p N o d e V e c t . empty ( ) )if ( d e p N o d e V e c t .
b a c k ( ) ->i s N o E d g e s ( ) ){tmp . push_back ( d e p N o d e V e c t . b a c k ( ) ) ;d e p N o d e V e c t . pop_back ( ) ;}else {break ;}for ( int i = d e p N o d e V e c t . s i z e ( ) - 2 ;if ( d e p N o d e V e c t [ i ] ->i s N o E d g e s ( ) )i>=0;- - i ){tmp . push_back ( d e p N o d e V e c t [ i ] ) ;s t d : : swap ( d e p N o d e V e c t [ i ] ,depNodeVect . back ( ) ) ;d e p N o d e V e c t . pop_back ( ) ;}for ( unsigneddelete tmp [ ii=0;i< tmp . s i z e ( ) ;++i ){];}}/// Remove graph node.void erasePDGsNode ( DepGraphNode * n o d e ) {for ( unsigned i = 0 ; i < d e p N o d e V e c t .
s i z e ( ) ;if ( d e p N o d e V e c t [ i ] == n o d e ) {++i )d e p N o d e V e c t [ i ] ->e r a s e N o d e ( ) ;deletedepNodeVect [ i ] ;s t d : : swap ( d e p N o d e V e c t [ i ] ,depNodeVect . back ( ) ) ;d e p N o d e V e c t . pop_back ( ) ;}}/// Remove graph nodes which degree higher than some number.void compressPDG ( unsigned EdgeP = 2 0 ) {for ( unsigned i = 0 ; i < d e p N o d e V e c t . s i z e ( ) ; ++i )if ( d e p N o d e V e c t [ i ] ->g e t I n D e p C o u n t ( ) > EdgeP||d e p N o d e V e c t [ i ] ->g e t O u t D e p C o u n t ( )>EdgeP ){d e p N o d e V e c t [ i ] ->e r a s e N o d e ( ) ;deletedepNodeVect [ i ] ;s t d : : swap ( d e p N o d e V e c t [ i ] ,depNodeVect .
back ( ) ) ;d e p N o d e V e c t . pop_back ( ) ;}}// concrete SDG to templatevoid d o T e m p l a t e ( ) {// deleting edges and nodes to concrete templatefor ( v e c t _ i t e r a t o r n o d e s I t = g e t V e c t B e g i n I t e r a t o r ( )end=getVectEndIterator () ;nodesIt!=end ;,n o d e s I t ++){switch ( ( * n o d e s I t ) ->g e t N o d e I D ( ) ) {// deleting all control edges in ALLOCA nodes , as the order is notimportantcase ALLOCA_ID :/*for (iterator inIt = (* nodesIt)->inDepBegin (),end = (* nodesIt)->inDepEnd (); inIt != end; inIt ++){19if ((* inIt).
getDepType () == ControlDependence || IncomingFlag )(* nodesIt)->eraseSrcNodeDep ((* inIt).getSrc (), *nodesIt);}*/for( iteratorendif(((=(o u t I t = ( * n o d e s I t ) ->o u t D e p B e g i n ( ) ,* n o d e s I t ) ->outDepEnd ( ) ; o u t I t != e n d ;* o u t I t ) . getDepType ( )==o u t I t ++){ControlDependence )* n o d e s I t ) ->e r a s e S r c N o d e D e p ( * n o d e s I t,(* outIt ) .
getSink () ) ;}break ;// deleting all RETURN nodescase RETURN_ID :erasePDGsNode ( * n o d e s I t ) ;break ;/* case BRANCH_ID :errs () <<" _______BRANCH_________ ";break;*/default : break ;}}cleanUpPDG ( ) ;}/// Print graph in console.void printPDG ( ) {e r r s ( )<<"Print PDG Graph \n Location : "<<getAbsFP ( )<<"\n" ;for ( unsigned i = 0 ; i < d e p N o d e V e c t .
s i z e ( ) ; ++i ) {e r r s ( ) << "----------Inst---------\n" ;e r r s ( ) << "Inst : "<<d e p N o d e V e c t [ i ] ->g e t N o d e I D ( )<<"\n" ;e r r s ( ) << "----Node FLN : "<<d e p N o d e V e c t [ i ] ->g e t F u n c t i o n L i n e N ( )<<"\n" ;e r r s ( ) << "----InEdges ...\n" ;for( iteratori ]) ;errs ()it!=<<<<errs ()for<<it=end ;end=inDepEnd ( d e p N o d e V e c t ["-[DT : "<<( i t ->g e t D e p T y p e ( ) ^ I n c o m i n g F l a g )" Inst : "<< i t -> g e t S r c ( ) ->g e t N o d e I D ( ) <<" FLN : "<< i t -> g e t S r c ( ) ->g e t F u n c t i o n L i n e N ( ) <<"]-" ;"\ nOutEdges ...\n" ;( iteratorit=depNodeVect [ i ] ) ;errs ()i n D e p B e g i n ( depNodeVect [ i ] ) ,++ i t )outDepBegin ( depNodeVect [ i ] ) ,it!=end ;end= outDepEnd (++ i t )"-[DT :"<< i t ->g e t D e p T y p e ( )" Inst : "<< i t -> g e t S i n k ( ) ->g e t N o d e I D ( ) <<" FLN : "<< i t -> g e t S i n k ( ) ->g e t F u n c t i o n L i n e N ( )"\n" ;<<<<errs ()<<}}/// Print garph 's correspondence source code.void p r i n t P D G s S o u r c e ( ) {std : : ifstreamifI F S ( getAbsFP ( ) .
c _ s t r ( ) ) ;( IFS . i s _ o p e n ( ) )intcount=std : : s t r i n gerrs ()<<{1;line ;"\n=== Begin : "<<getAbsFP ( )20<<"===\n" ;<<"]-" ;while ( g e t l i n e ( IFS , l i n e ) ) {for ( unsigned k = 0 ; k < d e p N o d e V e c t . s i z e ( ) ;if ( d e p N o d e V e c t [ k ] ->g e t L i n e N ( ) == c o u n t ) {e r r s ( ) << c o u n t << ": " << l i n e << '\n' ;break ;++k )}c o u n t ++;}errs ()}else<<"====== End : "<<getAbsFP ( )<<"Can 't open : ""===\n" ;<<{errs ()<<getAbsFP ( )<<"\n" ;}}/// Calculate number of every node type in graph.inline void c a l c C h a r a c t e r i s t i c V e c t o r ( ) {for ( unsigned i = 0 ; i < d e p N o d e V e c t .
s i z e ( ) ; ++i )v e c t o r [ d e p N o d e V e c t [ i ] ->g e t N o d e I D ( )-1]++;}/// Calculate number of every node type in graph: ignore nodes with the sameline.inline void c a l c C h a r a c t e r i s t i c B y S o u r c e L i n e s ( ) {for ( unsigned i = 0 ; i < d e p N o d e V e c t . s i z e ( ) ; ++i ) {c h a r a c h t e r i s t i c s B y S o u r c e [ d e p N o d e V e c t [ i ] ->g e t N o d e I D ( )-1]. insert (d e p N o d e V e c t [ i ] ->g e t L i n e N ( ) ) ;}}/// Calculate nodes charachteristics .inline void c a l c N o d e s C h a r a c t e r i s t i c ( ) {for ( unsigned i = 0 ; i < d e p N o d e V e c t .