Поиск характерных шаблонов кода, приводящих к ошибкам функционирования в программах промышленного размера (1162573), страница 4
Текст из файла (страница 4)
s i z e ( ) ;++i )d e p N o d e V e c t [ i ] -> c a l c ( ) ;}/// Calculate source codes numberinline void c a l c S o u r c e L i n e s C o u n t ( ) {s t d : : s e t <int> l n ;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 ] ->g e t L i n e N ( ) != - 1 ) {i ++)l n . i n s e r t ( d e p N o d e V e c t [ i ] ->g e t L i n e N ( ) ) ;}sourceLinesCount=ln . s i z e () ;}/// calculate average degreeinline void c a l c A v e r a g e D e g r e e ( ) {float avDeg = 0 ;for ( unsigned i = 0 ; i < d e p N o d e V e c t .size () ;avDeg += 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 ( )+++i )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() ;AverageDegree= avDeg/depNodeVect .
s i z e ( ) ;}/// Return true if correspondence source code lines positions satisfy.bool c h e c k L i n e s O r d e r ( unsigned d i f f = 0 ) {s t d : : s e t <int> l i n e s ;21for(unsignedi=0;i<depNodeVect . s i z e ( ) ;++i )l i n e s . i n s e r t ( d e p N o d e V e c t [ i ] ->g e t L i n e N ( ) ) ;if( lines . size ()auto bif ( * b=!=0){l i n e s . begin () ;==- 1)b++;auto e = l i n e s . r b e g i n ( ) ;if ( ( ( * e - * b ) + 1 ) - l i n e sreturn false ;. size ()>=diff ){}}return true ;}inline i t e r a t o r i n D e p B e g i n ( DepGraphNode *T)return T ->i n D e p s . b e g i n ( ) ;{}inline c o n s t _ i t e r a t o r i n D e p B e g i nreturn T ->i n D e p s .
b e g i n ( ) ;(constDepGraphNode*T) const{}inline i t e r a t o r inDepEnd ( DepGraphNode *T)return T ->i n D e p s . e n d ( ) ;{}inline c o n s t _ i t e r a t o r inDepEnd ( constreturn T ->i n D e p s . e n d ( ) ;DepGraphNode*T) const{}inline i t e r a t o r o u t D e p B e g i n ( DepGraphNode *F )return F ->o u t D e p s . b e g i n ( ) ;{}inline c o n s t _ i t e r a t o r o u t D e p B e g i n ( constreturn F ->o u t D e p s . b e g i n ( ) ;DepGraphNode*F ) const}inline i t e r a t o r outDepEnd ( DepGraphNode *F )return F ->o u t D e p s .
e n d ( ) ;{}inline c o n s t _ i t e r a t o r outDepEnd ( constreturn F ->o u t D e p s . e n d ( ) ;DepGraphNode*F ) const}/// Return graph node 's vector begin iterator.inline v e c t _ i t e r a t o r g e t V e c t B e g i n I t e r a t o r ( ) {return d e p N o d e V e c t . b e g i n ( ) ;}inline c o n s t _ v e c t _ i t e r a t o r g e t V e c t B e g i n I t e r a t o r ( ) constreturn d e p N o d e V e c t . b e g i n ( ) ;}22{{{/// Return graph node 's vector end iterator.inline v e c t _ i t e r a t o r g e t V e c t E n d I t e r a t o r ( ) {return d e p N o d e V e c t .
e n d ( ) ;}inline c o n s t _ v e c t _ i t e r a t o r g e t V e c t E n d I t e r a t o r ( ) constreturn d e p N o d e V e c t . e n d ( ) ;{}inline n o d e s _ i t e r a t o r b e g i n ( ) {return n o d e s _ i t e r a t o r ( g e t V e c t B e g i n I t e r a t o r ( ) ) ;}inline n o d e s _ i t e r a t o r e n d ( ) {return n o d e s _ i t e r a t o r ( g e t V e c t E n d I t e r a t o r ( ) ) ;}/// Returm graph size.inline unsigned g e t S i z e ( ) {return d e p N o d e V e c t .
s i z e ( ) ;}/// Adding edge for two nodes in graph.inline void A d d S i m p l e D e p e n d e n c e ( DepGraphNode *DependenceTypef r o m ->o u t D e p s . push_back ( D e p e n d e n c e ( t o ,t o ->i n D e p s . push_back ( D e p e n d e n c e ( f r o m ,from ,depType )depType ,depType ,DepGraphNode*to ,{false ) ) ;true ) ) ;}/// Adding edge for two node 's correspondence llvm Instructions in graph.inline void A d d S i m p l e D e p e n d e n c e ( unsigned f r o m I , unsigned t o I ,DependenceType*DepGraphNode *DepGraphNodedepType )fromNode=getNode ( f r o m I ) ;toNode=getNode ( t o I ) ;f r o m N o d e ->o u t D e p s . push_back ( D e p e n d e n c e ( t o N o d e ,t o N o d e ->i n D e p s .
push_back ( D e p e n d e n c e ( fromNode ,{depType ,depType ,false ) ) ;true ) ) ;}};// End llvm namespace#e n d i fËèñòèíã 2: LLVM SDG PASS// ===--- lib/CCD/PDG.h - Program Dependence Graph ===//////The LLVM Compiler Infrastructure//// The Institute for System Programming (ISP) of the Russian Academy of Sciences//// ===----------------------------------------------------------------------===//#i n c l u d e" l l v m /CCD/ D e p e n d e n c e G r a p h . h "#i n c l u d e" l l v m /CCD/ T o o l s . h "#i n c l u d e" l l v m /CCD/ S e r i a l i z e r . h "#i n c l u d e" l l v m /CCD/ D e p e n d e n c e G r a p h . h "#i n c l u d e" l l v m /CCD/ N o d e C h a r a c t e r i s t i c .
h "#i n c l u d e" l l v m /CCD/ L o a d e r . h "23#i n c l u d e" l l v m /CCD/ Edge . h "#i n c l u d e" l l v m /CCD/ T r a c e B a s e d S l i c e . h "#i n c l u d e" l l v m /CCD/ S u b S e a . h "#i n c l u d e" l l v m / S u p p o r t / CommandLine . h "#i n c l u d e" l l v m / S u p p o r t / raw_ostream . h"#i n c l u d e" l l v m / Support / GraphWriter .
h"using namespacellvm ;// With this flag control dependencies added to PDGstatic c l : : o p t<s t d : : s t r i n g >W i t h C t r l D e p ( "with-ctrl-dep" ,c l : : Hidden ,c l : : i n i t ( "EMPTY" )c l : : d e s c ( "Use Controle Dependences " ) ) ;,c l : : ZeroOrMore ,// Algorithm name for finding isomorphismstatic c l : : o p t<s t d : : s t r i n g >A l g o r i t h m ( "alg" ,c l : : Hidden ,c l : : i n i t ( "" ) ,c l : : ZeroOrMore ,c l : : d e s c ( " Algorithm name for finding isomorphism " ) ) ;// Path where to dump PDG , this path should exist for PDGs serailizationstatic c l : : o p t<s t d : : s t r i n g >PDGFile ( "pdg-dump-path" ,c l : : Hidden ,c l : : i n i t ( "" ) ,c l : : ZeroOrMore ,c l : : d e s c ( "PDG Dump Path" ) ) ;// Path from where load templatesstatic c l : : o p t<s t d : : s t r i n g >T e m p l a t e F i l e ( "template-pdg-path" ,c l : : Hidden ,templatesDump " ) , c l : : ZeroOrMore ,c l : : d e s c ( "Template PDGs Path" ) ) ;cl : : init (// Where to save DOT graphsstatic c l : : o p t<s t d : : s t r i n g >DotGraph ( "dot-graph-path" ,c l : : Hidden ,c l : : i n i t ( "" )c l : : d e s c ( "Path For DOT Graph Print." ) ) ;namespace{class:PDGpublicpublic :static charPDG( ):ModulePass ,publicAliasAnalysis,"/home/ Alexander /llvm/c l : : ZeroOrMore ,{ID ;M o d u l e P a s s ( ID )initializePDGPass ({* PassRegistry: : getPassRegistry () ) ;}boolvoidrunOnModule ( Moduled u m p T o F i l e ( Modulestringml ,private :virtual void&M) ;&M,std : : s t r i n gAliasAnalysis*AA,std : : s t r i n gprefix ) ;getAnalysisUsage ( AnalysisUsageA l i a s A n a l y s i s : : g e t A n a l y s i s U s a g e (AU) ;AU .
a d d R e q u i r e d <A l i a s A n a l y s i s > ( ) ;AU . s e t P r e s e r v e s A l l ( ) ;}};24&AU)const{headrsList ,std : :}charPDG : : ID =0;"make-pdg" , "PDG Construction Pass" , false , false )INITIALIZE_PASS_BEGIN (PDG,INITIALIZE_AG_DEPENDENCY( A l i a s A n a l y s i s )"make-pdg" , "PDG Construction Pass" , false , false )INITIALIZE_PASS_END (PDG,* l l v m : : createPDGPass ( )return new PDG( ) ;ModulePass{}voidPDG : : d u m p T o F i l e ( Modulestringml ,CTRL_EDGEsstd : : s t r i n gctrlctrlDepctrlctrl}std : : s t r i n gheadrsList ,WithCtrlDep . g e t V a l u e ( ) ;{=="PARR" ){=="FULL" ){= PARR ;= FULL ;else if ( c t r l D e p .
empty ( ) )}*AA,{=JUMP ;else if ( c t r l D e p}="JUMP" )==else if ( c t r l D e p}AliasAnalysisctrl ;std : : s t r i n gif ( c t r l D e p&M,prefix )ctrl= EMPTY;else{{"-with-ctrl-dep option can take {JUMP , PARR , FULL} values\n" ;e r r s ( )<<return ;}std : : ofstreamOFSML( ml . c _ s t r ( ) ,s t d : : i o s : : outstd : : s t r i n gpdgstd : : s t r i n gname = M. g e t M o d u l e I d e n t i f i e r ( ) ;"/"+prefixstd : : ofstreamif+"-"'/' , '-' ) ;".pdg" ;name .
e n d ( ) ,+ name +OFS ( pdg . c _ s t r ( ) ) ;( OFS . i s _ o p e n ( )PDGStorage&& OFSML . i s _ o p e n ( ) )PS (M,AA,headrsList ,{ctrl ) ;// postprocessingPS . getSDG ( ) ->d o T e m p l a t e ( ) ;SerializePDGss( OFS ) ;<< PS . getSDG ( ) ;OFS . c l o s e ( ) ;OFSML <<pdg ;OFSML <<'\n' ;OFSML . c l o s e ( ) ;// writing SDG to dotif ( ! DotGraph .
g e t V a l u e ( ) . empty ( ) )writePDG ( DotGraph . g e t V a l u e ( ) ,}elses t d : : i o s : : app ) ;= PDGFile . g e t V a l u e ( ) ;s t d : : r e p l a c e ( name . b e g i n ( ) ,pdg +=|PS . getSDG ( ) ) ;{25std : :"PDG: Can 't create file "<<pdg<<"\n" ;"Maybe directory "<<PDGFile . g e t V a l u e ( )<<" doesn 't exists\n" ;e r r s ( )<<e r r s ( )<<exit (0) ;}}// Create PDG for current module and dump it to filebool PDG : : runOnModule ( Module &M) {bool Changed = false ;I n i t i a l i z e A l i a s A n a l y s i s ( this ) ;*AAAliasAnalysis= &g e t A n a l y s i s <A l i a s A n a l y s i s > ( ) ;std : : s t r i n gml = PDGFile .
g e t V a l u e ( ) ;std : : s t r i n gtlif=( ! ml . empty ( ) )TemplateFile . getValue ( ) ;{// dumping current fileAA, ml + "/headrs.list" ,else if ( ! t l . empty ( ) ) {//if template matching is ONt l += "/module.list" ;d u m p T o F i l e (M,}ml +"/module.list" , "module" ) ;LoadPDG LPDG( t l ) ;LPDG . d e s e r i a l i z e P D G F r o m F i l e (NONS) ;autoifm1s = LPDG . g e t S i z e ( ) ;( m1s ==0){"Template PDGs count is 0. It is possible that -ggdb was notspecified during PDGs generation \n" ;return 0 ;e r r s ( )<<}"Template PDGs count is :"<<m1s<<"\n" ;e r r s ( )<<// just info about templates// LPDG. printSizs ();// Construct SDG for current compilation modulePDGStoragePS (M,AA,EMPTY) ;// Detect isomorphic subgraph for current SDGif ( A l g o r i t h m . g e t V a l u e ( ) != "" ) {s t d : : v e c t o r <s t d : : v e c t o r <DepGraphNode *> > r e s u l t ;if ( A l g o r i t h m .
g e t V a l u e ( ) == "TBS" ) {for ( LoadPDG : : i t e r a t o r i t = LPDG . b e g i n ( ) , e n d =i t ++)LPDG . e n d ( ) ;it!=end ;= LPDG . e n d ( ) ;it!=end ;{TraceBasedSlice( PS . getSDG ( ) ,* it,result ) ;}}elsefor( LoadPDG : : i t e r a t o ri t ++)it= LPDG . b e g i n ( ) ,end{// Fast check if ispomorphism is possibleE d g e S e t e s 1 ( PS . getSDG ( ) ) , e s 2 ( * i t ) ;if( ! es1 . i s C o n t a i n ( es2 ,es1 ) )continue ;26// Here should be algorithm of isomorphic subgraph detection}}// destroySDG function should be called for SDG destructionPS .