• Aucun résultat trouvé

Widening with Thresholds for Programs with Complex Control Graphs

N/A
N/A
Protected

Academic year: 2021

Partager "Widening with Thresholds for Programs with Complex Control Graphs"

Copied!
21
0
0

Texte intégral

(1)

HAL Id: inria-00606961

https://hal.inria.fr/inria-00606961

Submitted on 7 Jul 2011

HAL is a multi-disciplinary open access archive for the deposit and dissemination of sci- entific research documents, whether they are pub- lished or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers.

L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires publics ou privés.

Widening with Thresholds for Programs with Complex Control Graphs

Lies Lakhdar-Chaouch, Bertrand Jeannet, Alain Girault

To cite this version:

Lies Lakhdar-Chaouch, Bertrand Jeannet, Alain Girault. Widening with Thresholds for Programs with Complex Control Graphs. [Research Report] RR-7673, INRIA. 2011, pp.17. �inria-00606961�

(2)

a p p o r t

d e r e c h e r c h e

ISSN0249-6399ISRNINRIA/RR--7673--FR+ENG

Domaine Algorithmique, programmation, logiciels et architectures

Widening with Thresholds for Programs with Complex Control Graphs

Lies Lakhdar-Chaouch — Bertrand Jeannet — Alain Girault

N° 7673

Juillet 2011

(3)
(4)

Centre de recherche INRIA Grenoble – Rhône-Alpes 655, avenue de l’Europe, 38334 Montbonnot Saint Ismier

Téléphone : +33 4 76 61 52 00 — Télécopie +33 4 76 61 52 52

Lies Lakhdar-Chaouh ,Bertrand Jeannet ,Alain Girault

Domaine:

Équipe-ProjetPOP-ART

Rapport dereherhe 7673 Juillet 2011 17 pages

Abstrat: Thepreisionofananalysisbasedonabstratinterpretationdoesnot onlydepend

ontheexpressivenessoftheabstratdomain,butalso onthewayxpoint equationsaresolved:

exat solving is often not possible. The traditional solution is to solve iteratively abstrat

xpointequations,usingextrapolationwithawideningoperatortomaketheiterationsonverge.

Unfortunately, theextrapolationtoooften losesruialinformation for theanalysisgoal.

Alassialtehniqueforimprovingthepreisioniswideningwiththresholds,whihbounds

theextrapolation. Itsbenet strongly dependsonthe hoie ofrelevant thresholds. In thispa-

per we propose a semanti-based tehnique for automatially inferring suh thresholds, whih

appliesto anyontrol graph,be itintraproedural,interproedural or onurrent, withoutspe-

iassumptions ontheabstratdomain. Despite itstehnial simpliity,our tehnique isable

to inferthe relevant thresholds inmanypratial ases.

Key-words: Abstrat Interpretation, Numerial and Symboli Abstrat Domains, Convex

Polyhedra, Semanti EquationSolving, Widening

(5)

ontrle omplexe

Résumé: Lapréisiond'uneanalysefondéesurl'interprétationabstraitedépendnoseulement

de l'expressivité dudomaine abstrait, maisaussi de lafaçon dont les équations abstraitessont

résolues: lasolutionoptimalen'esteneetpastoujorsalulable. Latehniquetraditionnelleest

derésoudreitérativementleséquations depoint-xeabstraites,en eetuantdesextrapolations

à l'aide d'un opérateur d'élargissement pour faire onverger les itérations. Malheureusement,

es extrapolations induisent fréquemment la perte d'informations ruiales pour l'objetif de

l'analyse.

Une tehnique lassique pour améliorer la préision est l'élargissement ave seuil , qui

bornel'extrapolation. Soneaitédépendfortementduhoixdeseuilspertinents. Nouspropo-

sonsiiunetehnique denaturesémantiquepourinférerautomatiquement desseuilspertinents,

quis'appliqueànimportequelgraphedeontrle, qu'ilsoitintraproédural,interproédural ou

onurrent, sans hypothèse spéique sur le domaine abstrait. malgré sasimpliité tehnique,

ette tehnique infère lesseuils pertinentsdansbeauoup deas pratiques.

Mots-lés: Interprétationabstraite,Domaineabstraitsnumériquesetsymboliques,Polyèdres

onvexes,Résolution d'équations sémantiques, Élargissement

(6)

1 Introdution and Related Work

Many stati analysisproblems boil down to the omputation of theleast solutionof a xpoint

equation X = F(X), X C where C is a domain of onrete properties, and F a funtion

derived from the semantis of the analyzed program. Abstrat Interpretation [1 ℄ provides a

theoretialframeworkforreduingthisproblemtothesolvingofasimplerequationinadomain

A ofabstrat properties:

Y =G(Y), Y A (1)

Having performed this stati approximation, one is left with the problem of solving Eqn. (1).

The paper fouses on this problem. It onsiders the traditional iterative solving tehnique

with widening and narrowing, and fouses more speially on the widening with thresholds

tehnique. We rstreviewexistingtehniquesbeforepresentingour approah.

Exat equation solving. Some tehniques have been reently proposed for solving diretly

Eqn. (1 ) inthe ase where onrete properties are invariants on numerial variables. In [2, 3 ℄

lasses of equations on intervals are identied,for whih the leastsolution an be omputed in

polynomialtime. Poliyiteration methods,inspiredbygametheory,solveEqn.(1 )bysolvinga

suessionof simpler equations Y =Gπ(Y) indexedbya poliy π. Theyhave been applied for

instanetointervals[4,5℄andtemplatepolyhedra[6,7℄. However,suhapproahesareurrently

restritedtodomainsthatinferlower/upperboundsonaxedsetofnumerialexpressions. This

exludesnumerialabstratdomainslikeonvexpolyhedra[8℄ orsymboli abstratdomainsfor

sets ofwords[9 ℄ or terms[10℄. Hene, they donot make obsoletethelassial iterative method

desribed next.

b

b

b b

b

b

b

b

b

G(Y)Y

G(Y)Y G(Y) =Y

gfp(G)

lfp(G)

Y0

Y1

Y2

Y Z0

Z1

Z2

Figure1: Kleene iteration with

wideningand narrowing Approximateequationsolvingbywidening/narrowing.

Under the lassial hypothesis the sequene Y0 = ⊥, Yn+1 = G(Yn) onverges to lfp(G). However, this method is eetive

onlyifA doesnot ontaininniteasendingsequenes,whih

is not the ase in all the abstrat latties mentioned above.

Abstrat Interpretation proposes to extrapolate the limit by

usinga widening operator :A×AA. Oneomputesthe

asendingsequene

Y0=⊥, Yn+1 =Yn∇G(Yn) (2)

whih onverges within a bounded number of iterations to a

post-xpoint Y lfp(G), see Fig. 1. The approximations induedbywidening anbepartiallyreovered byperforming

afew desendingiterations dened bythe sequene

Z0 =Y, Zn+1 =G(Zn) (3)

Thisisthemostommoninstaneoftheoneptofnarrowing (see[11℄). Inpratie,desending

sequenes propagatesguards inthe Control FlowGraph (CFG)of theprogram.

The use of widening adds dynami approximations to the stati approximations indued

by thehoie of the abstrat domain. Although it isshown in[11 ℄ that abstrat domainswith

innitelyasendingsequenesandisoverpropertiesthatsimplerabstratdomainsannotinfer,

these dynami approximations often raise auray issues. For instane, for many numerial

abstrat domains (like intervals [12 ℄, otagons [13℄ and onvex polyhedra [8 ℄) the standard

wideningonsistsinkeepinginthe resultR=P∇QthenumerialonstraintsofP thatarestill

satised by Q. Despite thislear geometrial intuition, intheontext of program analysisit is

(7)

diult topreditand tokeepunderontrol thelossof information itindues. Moregenerally,

to the best of our knowledge, no widening operator is monotoni and widening is ultimately

a heuristi method. Moreover, as we will show in Setion 3, narrowing often fails to reover

important information lost by widening, even on simple examples. In the extreme ase where

thefuntion Gisextensive (i.e.,∀Y A, Y G(Y)),narrowing hasno eetat all.

Tehniques for ontrolling dynami approximations. Several tehniques have been de-

signed to address the widening problem. One approah is to propose improved widening oper-

ators, like [14, 15, 16 ℄. Other approahes are more global. For instane, abstrat aeleration

aimsat omputing preisely witha single formula theeet of aelerable yles intheCFG

[17 ℄, and relies on widening for more omplex yles. The guided stati analysis tehnique of

[18 ℄ alternates asendinganddesendingsequenes on aninreasinglylarger partofthesystem

of equations. Thismethodapplies to anyabstrat domain and itimproves theauray ofthe

analysis in many ases, but it relies ultimately on the eetiveness of narrowing, whih is far

frombeingguaranteed (see Setion3).

Wideningwiththresholds. Amongloaltehniques,wideningup-toorwideningwiththresh-

olds attemptstoboundtheextrapolationperformedbythestandardwideningoperator[8,19℄.

The idea is to parameterize with a nite set C of threshold onstraints, and to keep in the resultR =PCQthose onstraints c∈ C that arestill satisedbyQ: PCQ= (P∇Q)⊓ {c C | Q |= c}. In pratie, one extrapolates up to some threshold; in the next iteration, either thethreshold is still satised and the result isbetter than withthestandard widening, or it is

violated and oneextrapolatesupto theremaining thresholds.

Onsimple exampleswitharelevant hoie ofthresholds, wideningwiththresholds doesnot

improve uponstandard widening and narrowing. However, intheases where narrowing isnot

eetive, widening withthresholds maybehave muh better: similarly to abstrat aeleration

tehniques, widening with thresholds prevents from going too high in the lattie of properties

(seeFig.1)andfrompropagatinginaurateinvariantsintheCFGoftheprogram,whihannot

bestrengthenedlater bynarrowing. However,thebenetprovidedbywidening withthresholds

fullydependson the hoie ofthe thresholds.

Our ontribution: thresholds inferene. Thispaper developsa semanti-based tehnique

toinferautomatiallyrelevantthresholds,bypropagatingonstraintsintheCFGoftheprogram

inan adequateway.

After givingin Setion 2some preliminaries about iterative equation solving withwidening

and narrowing, Setion 3 applies it to several small examples to illustrate the strengths and

weaknessesof narrowing. Wealso analyzearefullythe problemof inferringrelevantthresholds

on these examples and we show that, although widening with thresholds is dened as a loal

improvementofthestandardwidening,therelevantthresholdsdependonmoreglobalproperties

of the program. After having progressively given the hints behind our inferene tehnique,

Setion 4formalizesitinageneriway,illustratesitontherunningexamples, anddisussesits

appliation to more omplexabstrat domains.

Setion5evaluatesitonanumberofexampleprogramsandomparesitw.r.t.botheieny

and preision to guided stati analysis [18℄ and poliy iteration [4 ℄. This omparison shows

that our tehniques is almost always as or more preise than the mentioned tehniques for

all the examples we tested. w.r.t. eieny, our tehnique is slightly slower for sequential,

intraproedural programs. We also disuss the less favorable ases of interproedural and/or

onurrent programs.

(8)

A strength of our approah is thatitan easily be ombined withother approahes aiming

at improving dynami approximations, in partiular abstrat aeleration [17℄, whih may be

more preisethan our inferenetehnique when it is appliable.

2 Preliminaries and Notations

Theequationstobesolved. Weassumeastatianalysisproblemformalizedasanequation

system

X(k)=F(k)(X) X= (X(1), . . . , X(K))CK (4)

where X(k) C is typially the onrete property assoiated with a node of the CFG of the

program. The tehnial assumptions are that (C,⊆) is a omplete lattie ordered by logial

impliation,andthefuntionsF(k)areontinuous. Intheaseofanimperativeprogramwithout

proedure all, we have an intraproedural CFG and Eqn. (4) an be rewritten into a system

X(k) =S

k;kFk;k(X(k)) where Fk;k is the semanti funtion assoiated to the CFG edge k ; k. In relational interproedural analysis however, the proedure return operation may ombine both the information at the all-site inthealler and at theexit-siteof theallee, see

for instane[20 , 21℄.

Weassumeanabstratdomain (A,⊑) onnetedtoC withamonotone onretizationfun- tionγ :AC,yielding thesystemof equations

Y(k)=G(k)(Y) Y = (Y(1), . . . , Y(K))AK (5)

derivedfromEqn.(4)inthesensethat∀k:γG(k)(Y)F(γ(Y(1)). . . γ(Y(K))). Thefuntions G(k) are assumed to be monotoni and A is assumed to be a lattie equipped with a widening

operator :A×AAsatisfying the tehnial assumptions desribed in[11 ℄.

Inalltheexamplesofthispaper,thestatianalysisproblemistheomputationofreahable

valuesofthenumerialvariablesofaprogram. Awillbetheonvexpolyhedradomain,equipped

withits standard wideningoperator,see [8 ℄for the full denition.

Solving by Kleene haoti iteration. In all the examples, in order to solve Eqn. (5), we

applythetehniqueofBourdonle[22 ℄,i.e.,haoti iterationswithwidening. Thatis,wefollow

theiterationorder1. . . K andweapplywidening tothesubsetW ofwideningnodesasfollows:

Y0(k) = Yn+1(k) = (

Yn(k)∇Y ifkW Y otherwise

where Y =G(k)(Yn+1(0) . . . Yn+1(k−1), Yn(k). . . Yn(K))

(6)

Thesubset W is suhthat anydependeny yleinEqn. (5)ontainsa nodeinW. Narrowing

by desending iteration (Eqn. (3)) isperformed similarly on apartitioned system. Inpratie,

onerstdeomposesthedependenygraphinduedbythesystemofequations(5)intostrongly

onneted omponents, and then one solves eah omponent using widening and narrowing

following alinearized orderompatible withthe topologial orderbetween omponents.

3 The widening/narrowing approah in pratie

Thissetionillustratesthewidening/narrowing approahfortheanalysisofnumerial variables

ofsmallexamples. Itpointsoutthe limitationsofnarrowing forreovering theinformationlost

by widening,and gives theintuitionabout howto infer relevant threshold onstraints. We end

thesetionwiththe rationale for theinferenemethod we proposeinSetion 4.

(9)

var i,j:int;

begin

i=0; j=10;

while i<=j do

i = i+2;

j = j-1;

done;

end

1

2

3 i= 0 j= 10

i≤j?

i=i+2 j=j−1 i≥j+1?

Asendingsequene

n Yn(2) Yn(3)

1 i= 0j= 10 2 i+2j= 200i≤2 3 i+2j= 200i≤4

3 i+2j= 200i i+2j= 2022≤3i

Desendingsequene

n Zn(2) Zn(3)

1 i+2j= 2003i≤26 i+2j= 2022≤3i≤26

Figure2: Example: single loop

3.1 Analysis of a simple loop program

Our introdutory example is the program depited on Fig. 2 . The double-line around a CFG

node indiates a widening node inW. Thetable on the right details theKleene iteration with

widening and narrowing (desending sequene), starting from at thetwo node 2 and 3. In

thesteps1and2,thewideningoperatorhasnoeet. Therowindexedby3'orrespondstothe

omputation of Y inEqn. (6). Instep3, wehave Y3(2) =Y2(2)∇Y3(2) and theeet of widening

isthelossoftheupperboundoni. Onedesendingstepdisoverstheonstrainti≤26/3,whih

omes fromthe postonditionof Y3(2) bytheloop:

∃i, j:

impliedbyY3(2)

z }| { i+2j= 20

looptransition

z }| {

i≤ji=i+2j=j−1

= (i= 20−2j ij+3 )

i20−2(i−3)

| {z }

= 3i 26

(7)

This examplealls fortwo important observations:

(1) The invariant Z(3) at point 3 an be rewritten into i+ 2j= 20823 i8 +23. This

means thati≤26/3 isthe right bound foriat node 2 ifone abstratsawaythearithmeti

properties.

(2) If one wants to use widening with thresholds, the guard of the loop ij is not a useful

thresholdonstraint. Starting fromstep 3,wewouldobtain

Y3(2) = Y2(2){i≤j}Y3(2) =i+2j= 200≤i≤j Y4(2) = G(Y3(2)) =i+2j= 200≤i≤j+3 Y4(2) = Y3(2){i≤j}Y4(2) =i+2j= 200≤i

Theeet ofusing thisthreshold onstraint allowsus to keep theonstraint i≤j at step3,

but this bound isviolated at step 4 bythe postonditionof theloop transition,hene this doesnot hange thenal result.

The important point here is that the important onstraint in a simple while loop is the

postondition of the guard of the loopby the loop body,herei≤j+3,see Eqn.(7 ).

3.2 Four problemati examples

Two non-deterministiloops. TheCFGofFig.3istypiallytheresultoftheasynhronous

parallel produt of two threads with a simple loop. It shows the limitation of desending se-

quenes. The asending sequene onverges to Y(2) = 0i0j. The desending sequene

(10)

1

2

3

i=j= 0 (a)

i≤9?

i=i+1

i≥10j≥10?

(b) j≤9?

j=j+1

Figure 3: Example: two non-

deterministi loops

begin

i=0;

while true do

if ? then

i=i+1;

if i>=100 then

i=0;

done;

end

1

2

3 i= 0

i=i+1

i≤99? i≥100?

i= 0

Figure4: Example: a singleloop withbreak

var i,j:int;

begin

i=0; j=0;

while i<=9 do

j=0;

while j<=9 do

j=j+1;

done;

i=i+1;

done;

end

1

2 3

4 i=j= 0

i≤9?

j= 0

j≥10?

i=i+1

j9?

j=j+1

i≥10?

Asendingsequene

n Yn(2) Yn(3)

1 i=j= 0 i=j= 0 2 i=j= 0 i= 00j1

2 i=j= 0 i= 00j 3 0≤i≤110i≤j 0i≤90≤j

3 0≤i 10i≤j 0i 0j 4 0≤i 0≤j 0i 0j

4 0≤i 0i 0j

Desendingsequene

n Zn(2) Zn(3)

1 0≤i 0≤j 0i 0j10 2 j10i 0j10 0i 0j10

Figure 5: Example: nested loop

failsto improve it:

Z1(2) = G1;2(Y(1)) G2;2(a)(Y(2)) G2;2(b)(Y(2))

= {i=j= 0} ⊔ {1≤i≤100≤j} ⊔ {0i0≤j≤10}

= {0i0j}

The problem is that, for both variables iand j, there is always one inoming edge in node 2

that propagates an invariant without an upper bound on it. As a result, no variable gets an

upperbound inthe result.

A single loop with break. Another example, inspired by a real ontroller, is depited on

Fig.4 . The dashedself-loopomes fromthenon-deterministi test ? modeling aninput from

the environment. When the then branh is not taken, nothing happens in the loop body.

It makes the transfer funtion on node 2 extensive: G(2)(Y) G2;2(Y(2)) = Y(2). Hene,

the desending sequene will never improve the invariant Y(2) = i0 found by the asending

sequene.

Nested loop. The nestedloop program ofFig. 5ontains two wideningnodes 2 and 3 and

raises some additional issues. The asending sequeneloses thetwo onstraints j10 (step 2)

and i10 (step 3) as expeted (it even loses 0j at step 4). The desending sequene rst

reovers j10 at point 3, but then failsto reoveri10 at point 2. Theproblem is similar

to the problemwiththe non-deterministi loopsofFig. 3:

ˆ at point 2, theinoming edge 3 ; 2 is not guardedby i≤9,and

ˆ at point 3 the self-loop 3 ; 3 isalso notguarded byi≤9.

Hene, i≤10isneitherreoveredatnode 2 nor 3. Onthis example,theguidedstatianalysis

of [18℄also failsto disoverthisbound.

Références

Documents relatifs

Abstract: This thesis deals with the study of mechanical wave propagation in dry or wet granular media, with the aim of relating the phenomena at the microscopic

La constatation la plus marquante faisait apparaître une répartition non uniforme du plomb dans les cheveux  : dans la partie la plus ancienne allant du 425 ème au 360 ème

As previously mentioned by Alpers and Brimhall ( 1988 ), we consider that the uplift of the Andes resulted in more precipitation in the Eastern Cordillera, enhanced convec- tive

70 Pour les adolescents, cet espace peut également être mis en lien avec les territoires de la possession de Goffman (1973) puisqu’ils considèrent notamment que la gestion de

We propose a model of such systems with non-Poisson arrivals, arbitrary number of servers and operating levels where each operating level may correspond to an arbitrary number

We propose a model of such systems with general arrivals, arbitrary number of servers and operating levels where each higher operating level may correspond to an arbitrary number

My ultimate goal is to put forward and defend a novel picture of our language architecture, according to which: semantic content is strictly poorer than the lexically encoded

Varying the update thresholds from one session to another allows reducing the update error rates, so the performance gets better over time in comparison to using a fixed or