From 506505e3d215fb18d51d509a9f6265f2e8aa01b9 Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:09:35 +0000 Subject: [PATCH 01/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20classes=20pattern=20and=20matcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../RegexMatches01/RegexMatches01.class | Bin 0 -> 1272 bytes .../RegexMatches01/RegexMatches01.java | 25 ++++++++++++++++++ regression/strings/RegexMatches01/test.desc | 8 ++++++ .../RegexMatches02/RegexMatches02.class | Bin 0 -> 1273 bytes .../RegexMatches02/RegexMatches02.java | 25 ++++++++++++++++++ regression/strings/RegexMatches02/test.desc | 8 ++++++ 6 files changed, 66 insertions(+) create mode 100644 regression/strings/RegexMatches01/RegexMatches01.class create mode 100644 regression/strings/RegexMatches01/RegexMatches01.java create mode 100644 regression/strings/RegexMatches01/test.desc create mode 100644 regression/strings/RegexMatches02/RegexMatches02.class create mode 100644 regression/strings/RegexMatches02/RegexMatches02.java create mode 100644 regression/strings/RegexMatches02/test.desc diff --git a/regression/strings/RegexMatches01/RegexMatches01.class b/regression/strings/RegexMatches01/RegexMatches01.class new file mode 100644 index 0000000000000000000000000000000000000000..4006de70b283584550ab36dbe0f60853d85c75b5 GIT binary patch literal 1272 zcmaJ=*-{fh6g{17l3^er5Ec;)iV&8`0)zlTc5nlv#1dJ27?L&&CK;TWSn?mf$Pe%= zRs~C|^xZdq2)#352}{`z-M9NL=iH@#pM3ubUe1oFJrVcO>BR%<>=Mz9hz~vJ zwWK}~{g8d|BkDy=L>vhL10rhCAz)CXC`kds3=N%%VQ}44wW2Yn8p?K_XBpTAgJ)bV zs^$cPGt%>l!8NO8IfH*uE%N13VVmnOEn`v?6t&3E6xm$dRX!-Oyi&}?R!v}q;w=qU{b)8glWu3n8locc?k=6 zBq4|fhPM9%p^8X&j3*2&7bToN>&v{ZYdS;S<+2EPD&ZL>83GqR&$oAZ#-uvgPbE{$ z$8@Whu@%KMxlV1WGOqOK2IETU2~x;tg+03`a^!~QR-Ue-P#c7T-9CyjSnWBxqv)&r zeTf${Jl%86{}h<~U2oMQ%^{5*O=30YeZ%AhQfMVgGgOJ7YOxg>Hh2F$L`WiO(Uok`u%iA=;bh)=np*)7^Uv_Qf(pGwmMx(FGq`&`Ppp z`UwuW>6{5VzQMT|bS?Gum*HNP%kX?g^auh;-ZFgFG3Gjgcz{r=D_B#8bby*4s9irs z-LJ#He=Hn_jnfN}WG~%(gjqv-fCvW(uMuG)*+tR>Sxys=TVxr4^8|hYZ31o!XpcI` p_s)4TLpE!mKIktaZ~(z|2$%CK#0$W)#H?U$IHV~n{kt}w@IN{HCpG{8 literal 0 HcmV?d00001 diff --git a/regression/strings/RegexMatches01/RegexMatches01.java b/regression/strings/RegexMatches01/RegexMatches01.java new file mode 100644 index 00000000000..79e05c1432d --- /dev/null +++ b/regression/strings/RegexMatches01/RegexMatches01.java @@ -0,0 +1,25 @@ +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class RegexMatches01 +{ + public static void main(String[] args) + { + Pattern expression = + Pattern.compile("W.*\\d[0-35-9]-\\d\\d-\\d\\d"); + + String string1 = "XXXX's Birthday is 05-12-75\n" + + "YYYY's Birthday is 11-04-68\n" + + "ZZZZ's Birthday is 04-28-73\n" + + "WWWW's Birthday is 12-17-77"; + + Matcher matcher = expression.matcher(string1); + + while (matcher.find()) + { + System.out.println(matcher.group()); + String tmp=matcher.group(); + assert tmp.equals("WWWW's Birthday is 12-17-77"); + } + } +} diff --git a/regression/strings/RegexMatches01/test.desc b/regression/strings/RegexMatches01/test.desc new file mode 100644 index 00000000000..45cc542b352 --- /dev/null +++ b/regression/strings/RegexMatches01/test.desc @@ -0,0 +1,8 @@ +FUTURE +RegexMatches01.class +--string-refine --unwind 100 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/RegexMatches02/RegexMatches02.class b/regression/strings/RegexMatches02/RegexMatches02.class new file mode 100644 index 0000000000000000000000000000000000000000..d696c5eb047587506e9d98de3ecc4d09b9b53ef4 GIT binary patch literal 1273 zcmZ`&SyK~15dJ0yn=A_nfp92jP=s)74z6&?4PJnhSR#iHOESV@lEvMPCI7=0`2#$Q zRl(9KefP~jg!XJW!r?s3^h|eu{q-@wPrm;I(2oTfHE8wWo{alw^WlLw+hueh>PIKK zgw!pg2dWhm2~QO~!vsU{!sq$cE>GK3DCenQ z>)E&|su^F_Y@3_Zr!wPGlWs6B)t*91X(PAiG)0Zx(B0D0^(fQ_Dd+T$F#5_pXLdAm zg}*QGe43ATUh_W{WU9fN%lhG?L@!g=(-k47|+ zEKEPa1uvb`A=fv!7eb!J?w%sNOKK4npAkEPM3S!vzc@xbN01K?Zt{dGi% Date: Wed, 22 Feb 2017 14:13:08 +0000 Subject: [PATCH 02/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20string=20methods=20replaceFirst,=20replaceAll=20and=20split?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../RegexSubstitution01.class | Bin 0 -> 2003 bytes .../RegexSubstitution01.java | 39 ++++++++++++++++++ .../strings/RegexSubstitution01/test.desc | 8 ++++ .../RegexSubstitution02.class | Bin 0 -> 1739 bytes .../RegexSubstitution02.java | 32 ++++++++++++++ .../strings/RegexSubstitution02/test.desc | 8 ++++ .../RegexSubstitution03.class | Bin 0 -> 1684 bytes .../RegexSubstitution03.java | 33 +++++++++++++++ .../strings/RegexSubstitution03/test.desc | 8 ++++ 9 files changed, 128 insertions(+) create mode 100644 regression/strings/RegexSubstitution01/RegexSubstitution01.class create mode 100644 regression/strings/RegexSubstitution01/RegexSubstitution01.java create mode 100644 regression/strings/RegexSubstitution01/test.desc create mode 100644 regression/strings/RegexSubstitution02/RegexSubstitution02.class create mode 100644 regression/strings/RegexSubstitution02/RegexSubstitution02.java create mode 100644 regression/strings/RegexSubstitution02/test.desc create mode 100644 regression/strings/RegexSubstitution03/RegexSubstitution03.class create mode 100644 regression/strings/RegexSubstitution03/RegexSubstitution03.java create mode 100644 regression/strings/RegexSubstitution03/test.desc diff --git a/regression/strings/RegexSubstitution01/RegexSubstitution01.class b/regression/strings/RegexSubstitution01/RegexSubstitution01.class new file mode 100644 index 0000000000000000000000000000000000000000..fe4106df4e88e5371dab6ade809873b87cf42302 GIT binary patch literal 2003 zcmZ`(NmCm~6#g1XOe2pC9u_OMu?Ml3MOa25i4BAxvt?m%5HVp1&PZy=;E_h289}(@ zl&YNa2ROP?rw5wBbFD z_c=b`xXp1VhzU%#pdV8lAIgtu1s??wl&Bewcnj`gmSaxAd=Lv*7@6?Pfg`wZ6=j%V6gcg}Q; zq$Sb}Y>T0J%FLSHG=pz&=stsg)=mqC)+IA5R`QvoaMmT56dA+JGIR}YFC7?%M$|I0 z`_Y8wnA!bF`S5(gGg1$ija(70;DLg#8TeGnD%%ex?7Wi_3#POdS`+)?+eAL;dZw3` zZrvKYDebBl!Z3q6XYTFYwemtA9;VN0@w{he49`sI>%#T)S;H0jqR0w|WH!0gv_mMi zOSCEsBvstNV7-;y-CY$aP|Ts4_wh6-OD|PLkCpvs+KE#Ph)40o!6vzKz1Z}l!z zW^i+s>FI{2r|e9|a3^#X7Bb|KzT*z7$ih~TQ}GCn3Rf!n&T>^HRZ@B{lR}3qGefYx z(CrNxM}emzkHb?bFS$sa-=JT~W;v;G%VM}ac($d_N`}sgXnMq>ykWTvo%J?K<(?d( z@v3Wr#IfrMN`lYMQ*fOnbEX}=M>FJ+yTZs!lE1~SIV~ohoCNJLOx5$0Vw|jxutNP7 z>uNdf1=Eok4iwG4;eFYv9O^)^!VEVWunyJJmfuw3rHQtpamO)^DK*@)OKNGS{?Tb) z>lX@xQuNHC(Qd7c(X2&Vj5<9nT+ip8`@$#gg6}E*QTCr`kgIQZhZUMUaz~ok; z{}KA?rjyYb7=8}+iv%J<|IJ0A4=otQO}Z15y#R-w&al?Br1_RdG`|)opn2&jloND} zXuN=y6P)`E!OiD5_eVriwezH3eu@iPtN$h1Hhqyq0T(wSnnutKDQ_>yN3;&Dldwg# zly^12`=+~_A47|1m$Xm;?<{}sV^98jRbr25mrt`xBUcKz8qvB7xVA!{qc3p10KJIs z8ui7ro;P1m7+s_Om=>|GQPtV{6OcARG^=59X~_IGb-jwgz*=8@d|y6qo4JVwJ0%M z1^)*F3U1NwHP+bQXzzNBF$H6xP>8r=)q;-~D+^rI`U@C1f#QDxzwa58n$wlyOTz&) NsWY-g-Yv#7{y%!!^?LvS literal 0 HcmV?d00001 diff --git a/regression/strings/RegexSubstitution01/RegexSubstitution01.java b/regression/strings/RegexSubstitution01/RegexSubstitution01.java new file mode 100644 index 00000000000..06b9e7aaa10 --- /dev/null +++ b/regression/strings/RegexSubstitution01/RegexSubstitution01.java @@ -0,0 +1,39 @@ +import java.util.Arrays; + +public class RegexSubstitution01 +{ + public static void main(String[] args) + { + String firstString = "DiffBlue ***"; + String secondString = "Automatic Test Case Generation"; + + firstString = firstString.replaceAll("\\*", "^"); + + assert firstString.equals("DiffBlue ^^^"); + + secondString = secondString.replaceAll("Automatic", "Automated"); + + System.out.printf( + "\"Automatic\" substituted for \"Automated\": %s\n", secondString); + secondString.equals("Automated Test Case Generation"); + + System.out.printf("Every word replaced by \"word\": %s\n\n", + firstString.replaceAll("\\w+", "word")); + + System.out.printf("Original String 2: %s\n", secondString); + secondString.equals("Automated Test Case Generation"); + + for (int i = 0; i < 3; i++) + secondString = secondString.replaceFirst("\\A", "automated"); + + assert secondString.equals("automatedautomatedautomatedAutomated Test Case Generation"); + + System.out.print("String split at commas: "); + String[] results = secondString.split(" \\s*"); + System.out.println(Arrays.toString(results)); + assert results[0].equals("automatedautomatedautomatedAutomated"); + assert results[1].equals("Test"); + assert results[2].equals("Case"); + assert results[3].equals("Generation"); + } +} diff --git a/regression/strings/RegexSubstitution01/test.desc b/regression/strings/RegexSubstitution01/test.desc new file mode 100644 index 00000000000..bc7ed3648f3 --- /dev/null +++ b/regression/strings/RegexSubstitution01/test.desc @@ -0,0 +1,8 @@ +FUTURE +RegexSubstitution01.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/RegexSubstitution02/RegexSubstitution02.class b/regression/strings/RegexSubstitution02/RegexSubstitution02.class new file mode 100644 index 0000000000000000000000000000000000000000..834c403b3b2d7d0856df177aaeb7f199af9ec69e GIT binary patch literal 1739 zcmZux&sQ5&6#gEQFpptc=pdL{pwkpAgwRk#t$;|%k5=VJZBT?_?Id}LLnoOyGoi9^ zrEB*ryQwa%=cJzYsC)kz_a0C6zDYtra?YH2Z|?o>z2E)jzW3*=7rz6TK}kb5rZ{eJ zOmn=&F{9yayu$IULhhgps}74sV2#{$O((!0o!=D5YN#Iek=!m%pNw>j=e*oPb+ z$?uOftYKYRHo9P9ljE+6Pc#f;O2s`58Ei51jaa@fyufzL{<7^`Sx4j<*e*loyj`|~ z1qNko{4<8glA9L{J!^JZY*b5G;cZDUIZBpYW*8W|zqW53SSiOU7gL$Qv&+Rf8F(%e zSh+{*Rwcx%_*4a1`Fzf4HtU1Gi)acFx=qeqb(HzA$f#vhc{}60MFsLa_%_R>w9zXXrYPXzfK_ z#g2|$+-FF}j{$MhZ}Jd%v*3DW(N+j;|n}!aiiFF+;n`2 zhYVL&4up4TK6bsl>4}PC*%y~h(IwX~7co1R^?%a&u-Wj3c9WIFcJ z)Ra}1MC5f?vg23-#}HgY=RxXLhk zoUYBLA(b4NSWAd>bD~x}&-G}=+Wb=$`#K)MIi+BoC)x@tK-l|PxM8AJzBZ}h!tdp@y@hIRi3uPYaxw`lmE8Lpj7*Yuy{)vz@Mp~L2+ z(w=7>5*Hr0b+^oOGN{R`ov>=i%%M})(;9{)hb|bJ*}U*=PvnnhgKmYON)EbRc5#L7 zr*66rS#L~E9qkk_dEn{&CVdUj%4m%yo`d}?fw)HR&d{i!3u73kJwe$BI3ncx$>>-! zl=TTCVnl1`TuU0N!D+Mp3|)p6`3>DWN-|S}zMVAA)o^}W+I#Bu38UAzK-kbN?M55C zvM|*71V+;6GhVBqfBid!J^lADi5{ro^`sH2;o=5;PX3BFYPj?agGU&cRHls~s&<6# zml)o8j>~_@b~?g#Hqb|Vm3rsYnuZ?eh~Yf7){7|^SS0^4t#{Cm9SqNdH8QH6h literal 0 HcmV?d00001 diff --git a/regression/strings/RegexSubstitution02/RegexSubstitution02.java b/regression/strings/RegexSubstitution02/RegexSubstitution02.java new file mode 100644 index 00000000000..476c0921553 --- /dev/null +++ b/regression/strings/RegexSubstitution02/RegexSubstitution02.java @@ -0,0 +1,32 @@ +import java.util.Arrays; + +public class RegexSubstitution02 +{ + public static void main(String[] args) + { + String firstString = "DiffBlue ***"; + String secondString = "Automatic Test Case Generation"; + + firstString = firstString.replaceAll("\\*", "^"); + + secondString = secondString.replaceAll("Automatic", "Automated"); + + System.out.printf( + "\"Automatic\" substituted for \"Automated\": %s\n", secondString); + secondString.equals("Automated Test Case Generation"); + + System.out.printf("Every word replaced by \"word\": %s\n\n", + firstString.replaceAll("\\w+", "word")); + + System.out.printf("Original String 2: %s\n", secondString); + secondString.equals("Automated Test Case Generation"); + + for (int i = 0; i < 3; i++) + secondString = secondString.replaceFirst("\\A", "automated"); + + System.out.print("String split at commas: "); + String[] results = secondString.split(" \\s*"); + System.out.println(Arrays.toString(results)); + assert results[0].equals("automatedautomatedautomatedaAutomated"); + } +} diff --git a/regression/strings/RegexSubstitution02/test.desc b/regression/strings/RegexSubstitution02/test.desc new file mode 100644 index 00000000000..eb2c03599a1 --- /dev/null +++ b/regression/strings/RegexSubstitution02/test.desc @@ -0,0 +1,8 @@ +FUTURE +RegexSubstitution02.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/RegexSubstitution03/RegexSubstitution03.class b/regression/strings/RegexSubstitution03/RegexSubstitution03.class new file mode 100644 index 0000000000000000000000000000000000000000..fa382774918546a8738294bd1b81a64513954537 GIT binary patch literal 1684 zcmZ`(Npl-T6#m*Hds>r8tc>kMB-oxfnw`$~&USz}6UgChUqG zOfo2=v4;$yX}2gCdNX!KEL6*R;VnxrDaw{zVK_Isp4qmZSV_mKY$bDnXIHjT^5W@S zU=iT6)W0A`8$psm{wpG+;Z9S$4wod!Xm5Y zh9B3FM?nSM5h&@{l8U|)N~hv89X7U)kZw3&(3%9&j>B+o^my+am&A^Xs7=M^Rm<@i z20CptQk#lVA9o}?x910k0bOXAv)$waYSw@P6IMAzRO%HvDkeWW5>#TC==9TI zlj>~!mh1nqt~Ytl*`7~9bl1)PC;FyUIX&I=N-$hM!E3D3ZSzixFHMh=OnaWSN2%d~ z+fYk8otKWr+BvxlYCSTC#;CX5veOPd7t~cn;oF`l9?lBQcu*w;y%lS?M2}a5UN;tr z%88?$0wyPz{@3UW(}A2p@t3+QhtQm4y%=8X|5Yx N`jo81je68K{{_$BnAQLQ literal 0 HcmV?d00001 diff --git a/regression/strings/RegexSubstitution03/RegexSubstitution03.java b/regression/strings/RegexSubstitution03/RegexSubstitution03.java new file mode 100644 index 00000000000..9ea91639e2c --- /dev/null +++ b/regression/strings/RegexSubstitution03/RegexSubstitution03.java @@ -0,0 +1,33 @@ +import java.util.Arrays; + +public class RegexSubstitution03 +{ + public static void main(String[] args) + { + String firstString = "DiffBlue ***"; + String secondString = "Automatic Test Case Generation"; + + firstString = firstString.replaceAll("\\*", "^"); + + assert firstString.equals("DiffBlue ^^^"); + + secondString = secondString.replaceAll("Automatic", "Automated"); + + System.out.printf( + "\"Automatic\" substituted for \"Automated\": %s\n", secondString); + secondString.equals("Automated Test Case Generation"); + + System.out.printf("Every word replaced by \"word\": %s\n\n", + firstString.replaceAll("\\w+", "word")); + + System.out.printf("Original String 2: %s\n", secondString); + secondString.equals("Automated Test Case Generation"); + + for (int i = 0; i < 3; i++) + secondString = secondString.replaceFirst("\\A", "automated"); + + System.out.print("String split at commas: "); + String[] results = secondString.split(" \\s*"); + System.out.println(Arrays.toString(results)); + } +} diff --git a/regression/strings/RegexSubstitution03/test.desc b/regression/strings/RegexSubstitution03/test.desc new file mode 100644 index 00000000000..20da1478b1a --- /dev/null +++ b/regression/strings/RegexSubstitution03/test.desc @@ -0,0 +1,8 @@ +FUTURE +RegexSubstitution03.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring From 9e6ea68c07e6d02c1d2d77d446e16a2fc106d950 Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:14:59 +0000 Subject: [PATCH 03/59] =?UTF-8?q?=C2=A0added=20character=20static=20method?= =?UTF-8?q?s=20for=20testing=20characters=20and=20converting=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StaticCharMethods01.class | Bin 0 -> 1067 bytes .../StaticCharMethods01.java | 16 +++++++++ .../strings/StaticCharMethods01/test.desc | 8 +++++ .../StaticCharMethods02.class | Bin 0 -> 644 bytes .../StaticCharMethods02.java | 8 +++++ .../strings/StaticCharMethods02/test.desc | 8 +++++ .../StaticCharMethods03.class | Bin 0 -> 614 bytes .../StaticCharMethods03.java | 8 +++++ .../strings/StaticCharMethods03/test.desc | 8 +++++ .../StaticCharMethods04.class | Bin 0 -> 614 bytes .../StaticCharMethods04.java | 8 +++++ .../strings/StaticCharMethods04/test.desc | 8 +++++ .../StaticCharMethods05.class | Bin 0 -> 1522 bytes .../StaticCharMethods05.java | 33 ++++++++++++++++++ .../strings/StaticCharMethods05/test.desc | 8 +++++ .../StaticCharMethods06.class | Bin 0 -> 917 bytes .../StaticCharMethods06.java | 19 ++++++++++ .../strings/StaticCharMethods06/test.desc | 8 +++++ 18 files changed, 140 insertions(+) create mode 100644 regression/strings/StaticCharMethods01/StaticCharMethods01.class create mode 100644 regression/strings/StaticCharMethods01/StaticCharMethods01.java create mode 100644 regression/strings/StaticCharMethods01/test.desc create mode 100644 regression/strings/StaticCharMethods02/StaticCharMethods02.class create mode 100644 regression/strings/StaticCharMethods02/StaticCharMethods02.java create mode 100644 regression/strings/StaticCharMethods02/test.desc create mode 100644 regression/strings/StaticCharMethods03/StaticCharMethods03.class create mode 100644 regression/strings/StaticCharMethods03/StaticCharMethods03.java create mode 100644 regression/strings/StaticCharMethods03/test.desc create mode 100644 regression/strings/StaticCharMethods04/StaticCharMethods04.class create mode 100644 regression/strings/StaticCharMethods04/StaticCharMethods04.java create mode 100644 regression/strings/StaticCharMethods04/test.desc create mode 100644 regression/strings/StaticCharMethods05/StaticCharMethods05.class create mode 100644 regression/strings/StaticCharMethods05/StaticCharMethods05.java create mode 100644 regression/strings/StaticCharMethods05/test.desc create mode 100644 regression/strings/StaticCharMethods06/StaticCharMethods06.class create mode 100644 regression/strings/StaticCharMethods06/StaticCharMethods06.java create mode 100644 regression/strings/StaticCharMethods06/test.desc diff --git a/regression/strings/StaticCharMethods01/StaticCharMethods01.class b/regression/strings/StaticCharMethods01/StaticCharMethods01.class new file mode 100644 index 0000000000000000000000000000000000000000..9236c2521e11657d1630d0ed02aee55588a90dac GIT binary patch literal 1067 zcmZuwO-~b16g{sUI_-3zP}*8SP!zSG@+E$@B3d-jfS6Q`;%eGH;9;2|ZwB4_CyZ=d zx^bf>Vl>f}F8oc#c<+SLrs+)P%)95^&+}&f{QLF;z&sW$3}7^Y6pmXsfiV*&Ef^SO z;}pX+Q%2mOF zK(sLNM8GI}bt#ZqR<3-oyIqy~5j)eywxe8uT;cihmh;k?ZaD77bS2Qr-6(QkZzXVQ zFIJqL1OIrb);P#)RlHqYlXn&8$&+88YUNEwugGB2tNSyvQ=HL823Z?v44Rm+F^f5J zZk4*#?Ej9|p0;rjb2dpuaEakE!xe_B4A&U0qiCaqB8}grsEHdk7I0Ibzg1VsTKV!T&UmmQxZBkS?b&Y=}}Z5FptCYQi#3rMwf-=Kr1W2;MFX<0v1 zkp$PmM}-w2)zZpdnWfGKC&Z@5XM51WI-NBX-%$T z2obu0-_g=1MD{Q^{1s8-9g^Q+JljXl&yYg3EC>1%72XN`ojP9aI_9R4SMkbefULk4v}{s5`U2w wnM^iASDqq<4<(%swF3sysW0f?gK4~n5&euvt7KDNPDO?7MLvXMVMinX0ZQ)T{r~^~ literal 0 HcmV?d00001 diff --git a/regression/strings/StaticCharMethods01/StaticCharMethods01.java b/regression/strings/StaticCharMethods01/StaticCharMethods01.java new file mode 100644 index 00000000000..d8e2f9d261b --- /dev/null +++ b/regression/strings/StaticCharMethods01/StaticCharMethods01.java @@ -0,0 +1,16 @@ +public class StaticCharMethods01 +{ + public static void main(String[] args) + { + char c = 0; + assert Character.isDefined(c)==true; + assert Character.isDigit(c)==false; + assert Character.isJavaIdentifierStart(c)==false; + assert Character.isJavaIdentifierPart(c)==true; + assert Character.isLetter(c)==false; + assert Character.isLetterOrDigit(c)==false; + assert Character.isLowerCase(c)==false; + assert Character.isUpperCase(c)==false; + assert Character.toUpperCase(c)==Character.toLowerCase(c); + } +} diff --git a/regression/strings/StaticCharMethods01/test.desc b/regression/strings/StaticCharMethods01/test.desc new file mode 100644 index 00000000000..4b633e92bcf --- /dev/null +++ b/regression/strings/StaticCharMethods01/test.desc @@ -0,0 +1,8 @@ +FUTURE +StaticCharMethods01.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/StaticCharMethods02/StaticCharMethods02.class b/regression/strings/StaticCharMethods02/StaticCharMethods02.class new file mode 100644 index 0000000000000000000000000000000000000000..78ad3dbdc778f1bd3920af2b50b3ca56d49e9763 GIT binary patch literal 644 zcmZvZ&rcIU6vw~QZ98SV(DK7tDWG80;z11IW@9jmghPQt!NhW!?oP^J*==U0_`h)S z=2=OAXrg!jCSrWEq0|G}?99A3?|t6)z4`O^$1eaIc;R9Kl?iY>bWz14yUcUcT;x#U zSa7k3C631ovvrXqQX3UV$(Bk)w=Y8m)?vsuRiw;Y2B)$5fg$V1p=2nvR3!I?r(LNJ zY%pD%3KcO_8b_@YaVFOKBI>QRjaE_bjZK_v8xefk6@%OOLNn;!lHGPZ)PdYqmQ$rT zqXPd}=v`@!<1l%>{>lY!!lMpJjDuSjO)D{HSu2SSW{c~z&Pq2p5Zw| zd7QZ4J&}Q-gt5yi5P^||DVq3jFp%08iS4xEullL86@MN%OaCSIX_hpJP$o*t@J^G} zGNcO{WQXK)dK-Y1tF|RNIbgO!TBpcbq@B^8dwB)+%?6@GYd&={N-blW&Ng%h8Tx<) zr}-V3b5v^AaOlr|LGdSYAFq)AZ3&r_Fhzw3OI98=5-~#-QEyOVC}8$Zz(!gLn4aO6 cD4c_5zar~gATvgd#8?CYy-h25F0J(7A5^q|OaK4? literal 0 HcmV?d00001 diff --git a/regression/strings/StaticCharMethods02/StaticCharMethods02.java b/regression/strings/StaticCharMethods02/StaticCharMethods02.java new file mode 100644 index 00000000000..658186e9603 --- /dev/null +++ b/regression/strings/StaticCharMethods02/StaticCharMethods02.java @@ -0,0 +1,8 @@ +public class StaticCharMethods02 +{ + public static void main(String[] args) + { + char c = 0; + assert Character.toUpperCase(c)!=Character.toLowerCase(c); + } +} diff --git a/regression/strings/StaticCharMethods02/test.desc b/regression/strings/StaticCharMethods02/test.desc new file mode 100644 index 00000000000..496814588a7 --- /dev/null +++ b/regression/strings/StaticCharMethods02/test.desc @@ -0,0 +1,8 @@ +FUTURE +StaticCharMethods02.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StaticCharMethods03/StaticCharMethods03.class b/regression/strings/StaticCharMethods03/StaticCharMethods03.class new file mode 100644 index 0000000000000000000000000000000000000000..264331b2fbec8488bb351cb190da21a20bc14000 GIT binary patch literal 614 zcmZuuT`vPc6g|^jyX{(9t&jTtd?*hp;Y}l?<;llGMS`d4?$D{)mD#QT!XNOA1R>$w zZxV5*K|RPMGxyG%d(OFc-ansT0jyxoK@tNgSQvCLguIPm2POt=j5rv@n2m9U+#HW0 zp<)>ZQAI|)))YPiJ7Ta(GLZ2agHf12U@*&}FBsC>G7!71^O{im8cYx8Tm}q-h2!l8 zzvRUx4^E5KSjpgYRTuVDWA2^p@QZJJvg9?tnVo9bQl8k7nkP@VSbF6;S34rEhkmrQ zyr>ynbi;L#f@5RC#U!Q(+>zS&@xQ55sHmfVcx+6&n87SVrc=0AYX~oRg{CULqaQ{Eqlh=H9lI4v1Vz0F`XHjWwWb`lAOQb)$(V0hIR>d1iU;fl+c zVWDx>x#ZvY=77iNn?0>$e7@ONJ^GpQX_W2&ZM(zTm1W z^hFY-pPC=lsO3CVwN(Jd_q7yVQ%c+%xr+!Ip+@UHC+1#Z0i=eiPWePBSC`xj;Xhj HIlXxS5x96E literal 0 HcmV?d00001 diff --git a/regression/strings/StaticCharMethods04/StaticCharMethods04.java b/regression/strings/StaticCharMethods04/StaticCharMethods04.java new file mode 100644 index 00000000000..70fa2be2f36 --- /dev/null +++ b/regression/strings/StaticCharMethods04/StaticCharMethods04.java @@ -0,0 +1,8 @@ +public class StaticCharMethods04 +{ + public static void main(String[] args) + { + char c = 0; + assert Character.isLetter(c)==true; + } +} diff --git a/regression/strings/StaticCharMethods04/test.desc b/regression/strings/StaticCharMethods04/test.desc new file mode 100644 index 00000000000..93eebbae1da --- /dev/null +++ b/regression/strings/StaticCharMethods04/test.desc @@ -0,0 +1,8 @@ +FUTURE +StaticCharMethods04.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StaticCharMethods05/StaticCharMethods05.class b/regression/strings/StaticCharMethods05/StaticCharMethods05.class new file mode 100644 index 0000000000000000000000000000000000000000..c58f3d328afb757005812bcbc2145c7350cb5c38 GIT binary patch literal 1522 zcmZuxOLH4V5dKD5?a1r3Ez6c45D^9PketK{kO=ULIBSO}v111XCw5+}rHQkNyz5%6 z4EzHQ965z5C{7&U5~oUbB^9{ym#9k7y^<|C<-_*OPIrIZ{dLd$`}Wn}04~Bd(1X(w zXS$F@&OiiXEY5ae80RF;8<057y74&j1}@;^I6jg1)F9tWEDC)1Ssb6U+ZP5VFd4@b zYo-m%;7f_i24-=DstAZR0e#AGonS^Fn$4{UXqHz|0(}dP zt8Uge*Oh;pjY+X-JFdV`_TIu%d)v-eZFeJI3Vg@im}JMEQec;#E!tb5JryMopDI^d z;6}--`(<_2VW<%@4V<#|#P%0e@WiXsE?gRCP!sRtm_UCRpdL8Ye5q`^uJR=;6LXkn zgR3UK!Zj14c#ojkxyFd=cn!~zxtj$59)O@uTR znZV1GDIL2^))SdiHA5iLhF)5Ks>*@HO%qF4HgOAIn<(M7Kyn|y?QP;4tVrB3aTlu{ zfetJ z<|NURJyOB_lCJtbD7rz|_##QKPWv{{GIh2MG!T+O_#MZDvBgGJPM{U&-Kl8$g{R!^ zkY5^%$DTjO4H1ZCi^ZHpP}_F3u9hBi&Q`8t#17o396gLjHd9B0>zvDG!zNoehtnn; zjcXSe%ytH9&GKQA!}+Gb+`L(G(XwH-v9N!fy;aN+dCiFp%OpzGhVuEQ6g%Nt=M=rK zJy=$it|ggPRL${KJFm2&=$@%5SwP9Z_VsLe~!WQFNml0-_iXV za&;H+f6{-F&yVy)=;KhMt^I=?bR~@jy4k;=@t>)^LCxRQ1izuMkIr8GO^jr;fq{a~Cxa~=0 && choice<3; + + switch (choice) + { + case 1: // convert digit to character + System.out.println("Enter a digit:"); + int digit = scanner.nextInt(); + System.out.printf("Convert digit to character: %s\n", + Character.forDigit(digit, radix)); + char tmp=Character.forDigit(digit, radix); + assert tmp=='t'; + break; + + case 2: // convert character to digit + System.out.println("Enter a character:"); + char character = scanner.next().charAt(0); + System.out.printf("Convert character to digit: %s\n", + Character.digit(character, radix)); + break; + } + } +} diff --git a/regression/strings/StaticCharMethods05/test.desc b/regression/strings/StaticCharMethods05/test.desc new file mode 100644 index 00000000000..e009650a853 --- /dev/null +++ b/regression/strings/StaticCharMethods05/test.desc @@ -0,0 +1,8 @@ +FUTURE +StaticCharMethods05.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StaticCharMethods06/StaticCharMethods06.class b/regression/strings/StaticCharMethods06/StaticCharMethods06.class new file mode 100644 index 0000000000000000000000000000000000000000..10f416854e6eeca224d6bab498a22308a30ec85c GIT binary patch literal 917 zcmZuwT~8B16g|_g-EOz^1ByiiilVfD6cDPW#7L?>wPI3ZB0f#GBP?!rad%7fr^p}R zSxk!2MBn{S8t-g@wh75*_U_zs&pmVQ?4N%>egW9TV+~16Yq*6Oxy;5fhk}ZE4YzSe z#X=kj+*NQ-Lmblz7Bv)6Qn17@zQ8?CxW4Jw-ZRtVElac+*d9Y{+q6yp2}8J8dczQ@ zIc>p^s++cW+3mE1`&xo2(cz}eFj;(8Kjg=}Y;k+P-1J@3-ml8SWYg!yhXy|i@Cue0 z)NRAMAlI5s*EPfoQ&Qy#>YGOGfV&OhA2@Aqt+Fafb)=D@QXMO}uVWQu1#3FivB5B5 ztQWZ5E*KjH?uvr=*yWa{;DJuQY!T;Z+IIX4h>kI&C_fOrbLqr$*L7U-<{CK)DmotG z5kq=VxZ64uhED~9EqMlR_=0GZV{UcD?tAK0td)jLy24b+?LfE3kSh)$`oz@|jbo@? z^RwrR4h_cXQqx=?Z#v~y1&4GjNZ|ubFi-xh;dqD!6u^%Ie{F- z68Z@tDh4X)o$mY%}; Rcu5pRNPjAiI2H82`5(=T#Owe7 literal 0 HcmV?d00001 diff --git a/regression/strings/StaticCharMethods06/StaticCharMethods06.java b/regression/strings/StaticCharMethods06/StaticCharMethods06.java new file mode 100644 index 00000000000..ca8ff1604ac --- /dev/null +++ b/regression/strings/StaticCharMethods06/StaticCharMethods06.java @@ -0,0 +1,19 @@ +public class StaticCharMethods06 +{ + public static void main(String[] args) + { + Character c1 = 'A'; + Character c2 = 'A'; + + if (c1.equals(c2)) + { + System.out.println("c1 and c2 are equal\n"); + assert true; + } + else + { + System.out.println("c1 and c2 are not equal\n"); + assert false; + } + } +} diff --git a/regression/strings/StaticCharMethods06/test.desc b/regression/strings/StaticCharMethods06/test.desc new file mode 100644 index 00000000000..6f351b2c7cf --- /dev/null +++ b/regression/strings/StaticCharMethods06/test.desc @@ -0,0 +1,8 @@ +FUTURE +StaticCharMethods06.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring From 0b056151819f54d99447251e4f4f3d2392b3ec30 Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:16:01 +0000 Subject: [PATCH 04/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20sringBuilder=20append=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringBuilderAppend01.class | Bin 0 -> 1860 bytes .../StringBuilderAppend01.java | 43 ++++++++++++++++++ .../strings/StringBuilderAppend01/test.desc | 8 ++++ .../StringBuilderAppend02.class | Bin 0 -> 1861 bytes .../StringBuilderAppend02.java | 43 ++++++++++++++++++ .../strings/StringBuilderAppend02/test.desc | 8 ++++ 6 files changed, 102 insertions(+) create mode 100644 regression/strings/StringBuilderAppend01/StringBuilderAppend01.class create mode 100644 regression/strings/StringBuilderAppend01/StringBuilderAppend01.java create mode 100644 regression/strings/StringBuilderAppend01/test.desc create mode 100644 regression/strings/StringBuilderAppend02/StringBuilderAppend02.class create mode 100644 regression/strings/StringBuilderAppend02/StringBuilderAppend02.java create mode 100644 regression/strings/StringBuilderAppend02/test.desc diff --git a/regression/strings/StringBuilderAppend01/StringBuilderAppend01.class b/regression/strings/StringBuilderAppend01/StringBuilderAppend01.class new file mode 100644 index 0000000000000000000000000000000000000000..b6202d6fc9ac4595ee3ca4131f90ffa63a33fd5a GIT binary patch literal 1860 zcmah}&vV;E7=3HYT3MD8;lxgyCQX1EoVNK@r%9WHlGJG+B}ogh+uEUkY|BN(l~dWy zfg=Yl%)o_HF1>Vyfdey8MqwzF87?pk!weTLTsZW`{{Va|$4N*t#HGHE)qA`9 z^WWb*0x*fPil>oMFsa~dfZq5rp~sNshX8qg{Q>dREm}3BP%%pkEYBd%S+-Tbz~D~~Ut^Hc)so53xnkMoTH{W^bTT5D0(T6{W{4#> zR&E{bP>qhaNRb$i3=eR=Sa$Mzjl|Gh1nJZRy2U6Fo4X0=> zS)y!Tv&6-QRVkUy!se!Fm&PYX#Sj`!AVED#R=HfLG{hY0X06W9b9e%~y%|CkqgEd( zG|FYu5#3+Yu#OCaFJTLo6>v?!bpba7ZMbfA12#fxc*epr1Y@}&` z7_-Aq^x5@b_E3Ing|x{ZNN%Lt)f=Sv@^ZV3{$##=xNZIZ9-AM-Mrf{?V{OMVWnPeS=gO?vOIYpQyHUDJLGQ5Jlgi1`^zRxOOi5UC9`HZW@&E$ z(uS@#C_o28o=&tux&fy5iXB1B4<Ii3z3ND31#mkqeCi*Vd9j^ zeuaciYNd#8CE{PzwQmDCzrK~tNxGTM1#~BylXWYb<9a!pQv}mxy-3J)gHX}yghB7U zs#l4JbUV8yO-XuwDxmWzxf{|nkI3hO-QefdhY02(>JCCPnxH$-X2S9CDHq{Lhl|eB zbbDmPh2A87*~L>HjY=*eO%`y`)npXy_E?O&hLKDCP5%`p^?KK(fkoajZhYRnjd36*myVO^CB1j529= z7dqZW1n;2>@1q+ZAc~I=!^h~sHhOUnaok5AKE*M7j($8Kd%nhTd`Bk!fFb-yR{laZ z{zhZ|PA2|AHvUQ8JSLa^!Z7pWBwe5g`-dLF9H%%=bBu6|GR7pIpJUAXk5HC^@x5g* m>G=(kZ_vfiHn{W&B>w~S?SE)%Nr(Xg@M-g6;Y@fsocR|#Be9hL literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderAppend01/StringBuilderAppend01.java b/regression/strings/StringBuilderAppend01/StringBuilderAppend01.java new file mode 100644 index 00000000000..26e164c02c9 --- /dev/null +++ b/regression/strings/StringBuilderAppend01/StringBuilderAppend01.java @@ -0,0 +1,43 @@ +public class StringBuilderAppend01 +{ + public static void main(String[] args) + { + Object objectRef = "diffblue"; + String string = "test"; + char[] charArray = {'v', 'e', 'r', 'i', 'f', 'i', 'c', 'a', 't', 'i', 'o', 'n'}; + boolean booleanValue = true; + char characterValue = 'Z'; + int integerValue = 7; + long longValue = 10000000000L; + float floatValue = 2.5f; + double doubleValue = 33.333; + + StringBuilder lastBuffer = new StringBuilder("last buffer"); + StringBuilder buffer = new StringBuilder(); + + buffer.append(objectRef) + .append("%n") + .append(string) + .append("%n") + .append(charArray) + .append("%n") + .append(charArray, 0, 3) + .append("%n") + .append(booleanValue) + .append("%n") + .append(characterValue) + .append("%n") + .append(integerValue) + .append("%n") + .append(longValue) + .append("%n") + .append(floatValue) + .append("%n") + .append(doubleValue) + .append("%n") + .append(lastBuffer); + + String tmp=buffer.toString(); + assert tmp.equals("diffblue%ntest%nverification%nver%ntrue%nZ%n7%n10000000000%n2.5%n33.333%nlast buffer"); + } +} diff --git a/regression/strings/StringBuilderAppend01/test.desc b/regression/strings/StringBuilderAppend01/test.desc new file mode 100644 index 00000000000..f1f89b629be --- /dev/null +++ b/regression/strings/StringBuilderAppend01/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringBuilderAppend01.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/StringBuilderAppend02/StringBuilderAppend02.class b/regression/strings/StringBuilderAppend02/StringBuilderAppend02.class new file mode 100644 index 0000000000000000000000000000000000000000..bf07da6a61302cc8589caf7a84d69ba8c0046853 GIT binary patch literal 1861 zcmah}&vV;E7=3HYT3MD8;W$5>CQX0}oVNMVI8E9ll%!4rDM?yL+|~{SWLqvOuAItt z4jegfVFoUoa_OZr3>=t&G73YX%y5BW7-qO|;liOe{s-V&IZi^FF_!iAN#D2MuHM_- zpa1^m5r7GlR6LE8f(Zp@L-Z!F9(fFDZV-^?=03akXzQo1I3^WLsR-kofRupq3Z_Ln zBVbm*3j!_(cu~NdfO!EI1*8Qm2)Go+02URzq~c{Paa>l>j}*r%DweUrvC7bK!mL&; zw`NzI>VjQ0^JS~Zz;X=otnJvf3k<>J&@~1rT`5`&?aQ`ft=8}4Eq7fcQ{awiI}BaP zjpf_smN{BBom-=8HP?1-&4`ZCwVGLYXT{v~^Es~2xExnGUZsy^P-Y9|-GS7#O5H73 zi?%4++bD6dZkLOeJHNSUImNN@5ix{@6ELV}(Jqzp<+_+d&8pTIx(`oaw>LwiY*uT7 z`Fg2jxuW}P8rHDR5HK9UG6Jp%xGvy^fUJO=fDHk!3%DuZ4GnMNEe+4$S%yq=5{4t@ zU^rWrYnSYTDHQdeDB#vD!!dG(Gi5ku#`b=OGd^RUm;nj_~L|iH(w^%SM_8NFME|Z2E363?EEr zj4?CxM4w#~W)9^ymq?5J{^UlwRlNaLGWV=Fz@y-(NOqT9TC6RkW(MYZdnv zAnoW{odR?+2B*GCHM_7$Q!o z>{m!=r&fvumSe#cUHdka4eDE&tfX6+Y)E%ASy{I;S+18dSw%2i)(eDOHwhKJMi}+-F_fL#NNW!ydYP)}wmp_E|#n&~rTz^^llu z`x3p|=uEW5j(OXW~q8z6 Date: Wed, 22 Feb 2017 14:17:03 +0000 Subject: [PATCH 05/59] =?UTF-8?q?=C2=A0added=20stringBuilder=20methods=20l?= =?UTF-8?q?ength,=20setLength,=20capacity=20and=20ensureCapacity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringBuilderCapLen01.class | Bin 0 -> 1092 bytes .../StringBuilderCapLen01.java | 18 ++++++++++++++++++ .../strings/StringBuilderCapLen01/test.desc | 8 ++++++++ .../StringBuilderCapLen02.class | Bin 0 -> 871 bytes .../StringBuilderCapLen02.java | 8 ++++++++ .../strings/StringBuilderCapLen02/test.desc | 8 ++++++++ .../StringBuilderCapLen03.class | Bin 0 -> 725 bytes .../StringBuilderCapLen03.java | 8 ++++++++ .../strings/StringBuilderCapLen03/test.desc | 8 ++++++++ .../StringBuilderCapLen04.class | Bin 0 -> 727 bytes .../StringBuilderCapLen04.java | 8 ++++++++ .../strings/StringBuilderCapLen04/test.desc | 8 ++++++++ 12 files changed, 74 insertions(+) create mode 100644 regression/strings/StringBuilderCapLen01/StringBuilderCapLen01.class create mode 100644 regression/strings/StringBuilderCapLen01/StringBuilderCapLen01.java create mode 100644 regression/strings/StringBuilderCapLen01/test.desc create mode 100644 regression/strings/StringBuilderCapLen02/StringBuilderCapLen02.class create mode 100644 regression/strings/StringBuilderCapLen02/StringBuilderCapLen02.java create mode 100644 regression/strings/StringBuilderCapLen02/test.desc create mode 100644 regression/strings/StringBuilderCapLen03/StringBuilderCapLen03.class create mode 100644 regression/strings/StringBuilderCapLen03/StringBuilderCapLen03.java create mode 100644 regression/strings/StringBuilderCapLen03/test.desc create mode 100644 regression/strings/StringBuilderCapLen04/StringBuilderCapLen04.class create mode 100644 regression/strings/StringBuilderCapLen04/StringBuilderCapLen04.java create mode 100644 regression/strings/StringBuilderCapLen04/test.desc diff --git a/regression/strings/StringBuilderCapLen01/StringBuilderCapLen01.class b/regression/strings/StringBuilderCapLen01/StringBuilderCapLen01.class new file mode 100644 index 0000000000000000000000000000000000000000..caf6da81f4b50a3500f4fec45cf9f42fdcba13d6 GIT binary patch literal 1092 zcmZuwTTc^F5dKbYyKEPFftHIPi&kwxxoEu>5d}?%RTD8r@aeQY)Wv06_d?=dF!2xY z;v>GQNl7HpcmI$t#yDr8v>-2YX6N$F%r~>Y{(k=fpom2cDU2&HR7_|H;am?AI4`xF zh6}i;;F1Ovyp4-Jw0iriq2D?Hjnkd)}Ozhu$r(Bf;tH62kq;)(X{`Q)IxS;qvOW{R$sC5I%< zq=iA_AVV@sUt{z#dZUwjU|(b)21&*OBbCMwhDn#9zbQ3D@8^Al*3#iUM9ND<`mjwTeMAzwMAZmI_9FHNIR$63*|E`K qN*F!js~8Xiq|%8Nk~>f$yNHCpA=;_d=1w9-5z-eW!(%}+Xa50k= zxt4Ur>!{xm{#zxci$0ew!%Fp}b;dvPy2IUGy&d|}?d_|;Y&+!k`&ayYtfvYY^aIY+D*F)USU|7!k%O_eF}A>vMOg*r*K zU!xDt%?oHcG!^uxT@grMbZ1YYuM8u)ppiJnI!#!XhL7dTs)OXkL77pYwMe@)vW#qU zYXtUL39(3PYJA9O5|^+{zLK^nG)8vw0F literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderCapLen02/StringBuilderCapLen02.java b/regression/strings/StringBuilderCapLen02/StringBuilderCapLen02.java new file mode 100644 index 00000000000..5397130cde4 --- /dev/null +++ b/regression/strings/StringBuilderCapLen02/StringBuilderCapLen02.java @@ -0,0 +1,8 @@ +public class StringBuilderCapLen02 +{ + public static void main(String[] args) + { + StringBuilder buffer = new StringBuilder("Diffblue is leader in automatic test case generation"); + assert buffer.toString().equals("Diffblue is leader in automatic test case generation"); + } +} diff --git a/regression/strings/StringBuilderCapLen02/test.desc b/regression/strings/StringBuilderCapLen02/test.desc new file mode 100644 index 00000000000..cf2a98acf6d --- /dev/null +++ b/regression/strings/StringBuilderCapLen02/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringBuilderCapLen02.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringBuilderCapLen03/StringBuilderCapLen03.class b/regression/strings/StringBuilderCapLen03/StringBuilderCapLen03.class new file mode 100644 index 0000000000000000000000000000000000000000..a14ea26291a431c2b0a62f01437efa88299aaa90 GIT binary patch literal 725 zcmZuvT~8B16g{_J+b#=~@>NlEi>L(?F`;h~qZUm}>PJ#z0zOT5hdQ{OCA+i!7+!qz zSxsmniN5=rjPcG2G%>u)y)*Zob5G8lUw^*;0MNmviz!@juu{cU7X@6ap@vnPU3YN9 zg=34pix$=#+$7Aei!_yqQL#>URVoIN3<c*iY%=VO)FSF4= zCU0yr7e+#9!czNP?@)XcTanPit-eW=9zL+Z>An%chZo`~?`LI%>P`@yk-PmkO9J^! zS*n$PuqT;{LYZ{MQBUgo+xIN3hZ)Qgmj54d)=TK@s)K_;lu2Kuek27G_)7aCGx10m z75GM`#t%d){h`z{;kQ^@)^!garaj!kZ9;Rx|M=XOr%4hggvCq6Ik@AYjSWJ50(~_& zl!0ML`*KSvk<>%;KDYKcdpbdOBVGra8Ol^8GQ7~h9-52`yo-I_U5%FvP`zoTb5;ad zfB3BPZIvT&EN_lMUu+}h_^jlQ#NYSqD#;E?ZJcXQRhA~VIml<39p%(a71^q_L!6Ii%7eYGuL}0E_JAr!)r}P=6;y08h TWapwRNf`z2k(Iuj&uab!BFvcu literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderCapLen03/StringBuilderCapLen03.java b/regression/strings/StringBuilderCapLen03/StringBuilderCapLen03.java new file mode 100644 index 00000000000..86ac16fcdf6 --- /dev/null +++ b/regression/strings/StringBuilderCapLen03/StringBuilderCapLen03.java @@ -0,0 +1,8 @@ +public class StringBuilderCapLen03 +{ + public static void main(String[] args) + { + StringBuilder buffer = new StringBuilder("Diffblue is leader in automatic test case generation"); + assert buffer.length()==51; + } +} diff --git a/regression/strings/StringBuilderCapLen03/test.desc b/regression/strings/StringBuilderCapLen03/test.desc new file mode 100644 index 00000000000..7095d79fe5f --- /dev/null +++ b/regression/strings/StringBuilderCapLen03/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringBuilderCapLen03.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringBuilderCapLen04/StringBuilderCapLen04.class b/regression/strings/StringBuilderCapLen04/StringBuilderCapLen04.class new file mode 100644 index 0000000000000000000000000000000000000000..7350cb80672ee89e07c8972ee8afefd266904144 GIT binary patch literal 727 zcmZuvU279T6g`u#-E6mQntsJZxZp&+BP74nR{pMJ?9?IonL>x{{Ya&wudR)aIoUyriTJthD949owIxaehQ@5$riew>Lwra>$?5d=~NJTu9V z8yN;hq$UV?DuRJfLepEKEbE33AJaZIahIVn;eUGR%f8l$W>~ydoP&ElTG(Q!O`xy) zCn7WiX?tkG?iBBNN|9)o?cjhLgel0Py6*D+7IZ9O1pf#TXZ3WxRL7^Uu4luxm6{|uGd z{wGYG!#Nzo{b_j$InNAXh#Vd Date: Wed, 22 Feb 2017 14:17:56 +0000 Subject: [PATCH 06/59] =?UTF-8?q?=C2=A0added=20stringBuilder=20methods=20c?= =?UTF-8?q?harAt,=20setCharAt,=20getChars=20and=20reverse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringBuilderChars01.class | Bin 0 -> 1413 bytes .../StringBuilderChars01.java | 28 ++++++++++++++++++ .../strings/StringBuilderChars01/test.desc | 8 +++++ .../StringBuilderChars02.class | Bin 0 -> 797 bytes .../StringBuilderChars02.java | 8 +++++ .../strings/StringBuilderChars02/test.desc | 8 +++++ .../StringBuilderChars03.class | Bin 0 -> 692 bytes .../StringBuilderChars03.java | 8 +++++ .../strings/StringBuilderChars03/test.desc | 8 +++++ .../StringBuilderChars04.class | Bin 0 -> 1018 bytes .../StringBuilderChars04.java | 18 +++++++++++ .../strings/StringBuilderChars04/test.desc | 8 +++++ .../StringBuilderChars05.class | Bin 0 -> 850 bytes .../StringBuilderChars05.java | 10 +++++++ .../strings/StringBuilderChars05/test.desc | 8 +++++ .../StringBuilderChars06.class | Bin 0 -> 856 bytes .../StringBuilderChars06.java | 9 ++++++ .../strings/StringBuilderChars06/test.desc | 8 +++++ 18 files changed, 129 insertions(+) create mode 100644 regression/strings/StringBuilderChars01/StringBuilderChars01.class create mode 100644 regression/strings/StringBuilderChars01/StringBuilderChars01.java create mode 100644 regression/strings/StringBuilderChars01/test.desc create mode 100644 regression/strings/StringBuilderChars02/StringBuilderChars02.class create mode 100644 regression/strings/StringBuilderChars02/StringBuilderChars02.java create mode 100644 regression/strings/StringBuilderChars02/test.desc create mode 100644 regression/strings/StringBuilderChars03/StringBuilderChars03.class create mode 100644 regression/strings/StringBuilderChars03/StringBuilderChars03.java create mode 100644 regression/strings/StringBuilderChars03/test.desc create mode 100644 regression/strings/StringBuilderChars04/StringBuilderChars04.class create mode 100644 regression/strings/StringBuilderChars04/StringBuilderChars04.java create mode 100644 regression/strings/StringBuilderChars04/test.desc create mode 100644 regression/strings/StringBuilderChars05/StringBuilderChars05.class create mode 100644 regression/strings/StringBuilderChars05/StringBuilderChars05.java create mode 100644 regression/strings/StringBuilderChars05/test.desc create mode 100644 regression/strings/StringBuilderChars06/StringBuilderChars06.class create mode 100644 regression/strings/StringBuilderChars06/StringBuilderChars06.java create mode 100644 regression/strings/StringBuilderChars06/test.desc diff --git a/regression/strings/StringBuilderChars01/StringBuilderChars01.class b/regression/strings/StringBuilderChars01/StringBuilderChars01.class new file mode 100644 index 0000000000000000000000000000000000000000..f2645ec7774fe7282656930ac6aaece797a417a8 GIT binary patch literal 1413 zcmZuw-%}G;6#j1Z#|_IOA-F=YDk`=cgP?-Z3Mvpp(gw9AYL%xYx!}@Gg1Z}MeD|?4 zed-I-nRYsz@mZXK8FBETZ=L=N^)GS6b2nhX^00T$J@>okJLfy+{`2w87JyOwXu!f5 zj<4hR#y|{q8@iE})>#7?404<^5XTwm8IsGeT+X-Q0xlXD!KmC`iX$ukm*cp?@vVWY z7~>dc=pJx_K=`3suLaX?;4FBe!oVIg=;Ln94X-mOcKQK>nyXg?LubLQiQA3pg78Zc zOb1oRtuY+2=L^fuGiTUyYD>e#(06M~WAb80F?7m5%{eO(p6cMZ#zAr8<7ID$!YI}o zep$@8GGMBCd8*-h72)TeIDT;c!jOz@q8BNKo-cWJpbUv=cX4sbYl!}WTXjQGkvDFb zID#G%6PV@;rWP07S%$+0mBVr0!~;B}8?8j{EG&z1NIf|~Nru>bj={1I z7C9c)n>55{r~i-H$Fqyn#nXo41z$vMW-*qQBTy#sCn+P<&Zmi8_e5uE;A1|86>KgLOV zU>3bSmgtp}LzV)X7^GB&XIVURjDr2%3id)_FLd^D``?U`m|aI_CZQ)v z^xuN#Oq|(s7EC1^<8njuU;`wC5cCWOJNk@+18};2hf~4z+ax*vH9p p>T|0`qn-d=$?kO=UIkZQLRDTvYo)x~Hc6==W=_cFo{lOS_yi#cGPD2y literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderChars01/StringBuilderChars01.java b/regression/strings/StringBuilderChars01/StringBuilderChars01.java new file mode 100644 index 00000000000..10265254980 --- /dev/null +++ b/regression/strings/StringBuilderChars01/StringBuilderChars01.java @@ -0,0 +1,28 @@ +public class StringBuilderChars01 +{ + public static void main(String[] args) + { + StringBuilder buffer = new StringBuilder("DiffBlue Limited"); + + assert buffer.toString().equals("DiffBlue Limited"); + assert buffer.charAt(0)!=buffer.charAt(4); + + char[] charArray = new char[buffer.length()]; + buffer.getChars(0, buffer.length(), charArray, 0); + + int i=0; + for (char character : charArray) + { + System.out.print(character); + assert character==buffer.charAt(i); + ++i; + } + + buffer.setCharAt(0, 'H'); + buffer.setCharAt(6, 'T'); + assert buffer.toString().equals("HiffBlTe Limited"); + + buffer.reverse(); + assert buffer.toString().equals("detimiL eTlBffiH"); + } +} diff --git a/regression/strings/StringBuilderChars01/test.desc b/regression/strings/StringBuilderChars01/test.desc new file mode 100644 index 00000000000..41dfe54abeb --- /dev/null +++ b/regression/strings/StringBuilderChars01/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringBuilderChars01.class +--string-refine --unwind 100 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/StringBuilderChars02/StringBuilderChars02.class b/regression/strings/StringBuilderChars02/StringBuilderChars02.class new file mode 100644 index 0000000000000000000000000000000000000000..bcfdcce9aa6e031c442128bd7dc67b6a8ef3e37b GIT binary patch literal 797 zcmZvaOH&g;5Xb+sdF*DhArBr2Dhe2M14@wM24yKhPf-uCtO8Dx?0|!tUEPNtCSSm_ zT9s5umEQeKmSxX|kOH|(_w4-p*S+2S`|ppR0Cuo#qJY~v?ig4yq2X>0dE8UpvVj#7 ztGKVDZX%~dYbGAxp$?m2w$8&)1d;T;@IZ#V>k5Z~9WiA0q$i`N3@N+ujv?Lh9l=m+ zOHaIx`&|*dRbqPRbLlZG*vIWN{+Tyj?wvL}Q6Rn3T@_g9M7;Om75|v%sX_*0ujgLC z&5j=jJ@Ha1)Z#d7KbEc|g4TN;gj?I2ifW;RGDG!xh6^b}=|G;G?7Oj8Zp*%mgrg!F z7G_Yiu#OFe@>K;%bUd=~7@G{WDfjuL9WR2w4;bcds!2!F!WN!T-f85U?wROC4DX_hnzM}#sE&gGxb0HT;4Xpl!( zp}i>3%CJ&RHHW+uC^O1*R_L}wmXXb@kHEevA!g~!CLbB?&m88-SJDoJYGl{Wp&eFI zBc$8kkQt!5F+{ea4`B?DKS%Cx1oM|dX$fkE!iW!(pmpe2pql~q2X!4)@@kj0>?BEn hawR{6HGrP}f^_OTGE>;3E(OUzv!1Ey7n5AK{sFA-s>%QW literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderChars02/StringBuilderChars02.java b/regression/strings/StringBuilderChars02/StringBuilderChars02.java new file mode 100644 index 00000000000..c5a2bb276f3 --- /dev/null +++ b/regression/strings/StringBuilderChars02/StringBuilderChars02.java @@ -0,0 +1,8 @@ +public class StringBuilderChars02 +{ + public static void main(String[] args) + { + StringBuilder buffer = new StringBuilder("DiffBlue Limited"); + assert buffer.toString().equals("DiffBlue Limitted"); + } +} diff --git a/regression/strings/StringBuilderChars02/test.desc b/regression/strings/StringBuilderChars02/test.desc new file mode 100644 index 00000000000..3a6bde6ef78 --- /dev/null +++ b/regression/strings/StringBuilderChars02/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringBuilderChars02.class +--string-refine --unwind 100 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringBuilderChars03/StringBuilderChars03.class b/regression/strings/StringBuilderChars03/StringBuilderChars03.class new file mode 100644 index 0000000000000000000000000000000000000000..d124e87d09212ea4e7e130ef347a2a79978fc31b GIT binary patch literal 692 zcmZuv-%ry}6#h=z?QW&O7{7*!A~5VA5fgcn7-48)GUZ{!1bph+3tsFxbKCmI@ZzJ- zYQhpp^xeP77|*T162r?q=k|QxcfNCOfBpIX1Hcy6U5sHt;8q27x%F&utJz#4boKVObwEBPo+UGmJxxD2<2^+sO%}h_FHcVPJ0kZ!emD!@^#+t zNqu0zT<8ZXArsnRmK_Q31OaxU#%MQ;dH*DbcV);eU9>m;Nugm+t literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderChars03/StringBuilderChars03.java b/regression/strings/StringBuilderChars03/StringBuilderChars03.java new file mode 100644 index 00000000000..f226901e113 --- /dev/null +++ b/regression/strings/StringBuilderChars03/StringBuilderChars03.java @@ -0,0 +1,8 @@ +public class StringBuilderChars03 +{ + public static void main(String[] args) + { + StringBuilder buffer = new StringBuilder("DiffBlue Limited"); + assert buffer.charAt(0)==buffer.charAt(4); + } +} diff --git a/regression/strings/StringBuilderChars03/test.desc b/regression/strings/StringBuilderChars03/test.desc new file mode 100644 index 00000000000..12f20189434 --- /dev/null +++ b/regression/strings/StringBuilderChars03/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringBuilderChars03.class +--string-refine --unwind 100 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringBuilderChars04/StringBuilderChars04.class b/regression/strings/StringBuilderChars04/StringBuilderChars04.class new file mode 100644 index 0000000000000000000000000000000000000000..41be0e006830ee6c5258b9a9dd7c23d0ab8554da GIT binary patch literal 1018 zcmZuwTTc@~6#k}rnRZzyw*{&eK~Y-@6r~mg(|Cje4dHW0>jj-eoi4FqsQnw!#$ zgm4SD4ctL2gm%Q`*(gWCK${F0Gcb+`jwD0Rh+VG>*K=ys`ifJxH_M{Pz}6Y`Ij8D) z^9)KX{*pn>)QW;3oO7z;X``|!+!qo|7Zuy7GW5kZay#~0J6X1?rDWc7ooZ=T2Daxt zyYOb!-u3YulSG)~E<( z|8>rx44o^^*4A>lA%=2J#qmT@M%*(og_Mc=NOMe^cz}l-GbUy+XQC5bCLV#>9B5@- zx{&0t>(*R`-pd$qESOlt5>;(QKHJ<81&?ICL=1+&Mux$PU9OW}7S)os?dzQ-bxOkX zdnY%R&2D6}Qp~?f<=@pkQ6YG(K?SX|q)sjQoRs&7u&^t$M8xOz?=ge6D?#*jv5d^B z7f9qKf1iyL#c->kOqu3`UbiUfjw_0Pl%YrU8gxO!v5sMyu`rD!>l~1RlBa;lw<6n1 zyC|)UR&DeM?4tz2BCGp{3?cNPpL_}Z0S!S~?PCPix|JiSxkMA%7i~46NM}rGLRaR; zX4Hs!lGc>8Zt0fx0aFpx(o<=E2yXEvf`m%2itA=Xv>FMZMEuBv{a$Kv@y1{rY5Kl5R=xYg`L*H1$00BG5i6a z)dUio=)1qk81F!VSo<>f&dj;zoVj;?{rUa_Km|_>EZ~NQ6&*JXL~u(kt8tiEli6(@ zcMPoKu7-OC42isNz(PU82E*dI?fcvdM6c@~2;XkH++koR4C=1vir^_j)GEATh*f(I zXGqjUm%j=-P3|=$m@YcD=rUxix3#wY$u7Be_pDS8JkdSdk%ja1z;3;NX@3~u$tHuo z+j1|+je0NiTKu_?RQYk)ekfdrd)0Tg=WlIqN>&poq#3f86)vC*$pdkEy6=X3wI(_u z;Et>)ns|VRCK5=R*hGmTbu@yxjVVsUmWfAr%#fRr?@fAg=y^SlVd*Mk8p6wnrGndQp`f(u3ZZpM8ZeoE%Zh&cm=a)rLEN;Wj)p`%PXSvu9hexs}*M_GPqu`==kq|)X9^L=Qs&xl38 VL7kCK>`D>^5%ZaR)U}c3^}k&QvyK1& literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderChars05/StringBuilderChars05.java b/regression/strings/StringBuilderChars05/StringBuilderChars05.java new file mode 100644 index 00000000000..120871f8a9d --- /dev/null +++ b/regression/strings/StringBuilderChars05/StringBuilderChars05.java @@ -0,0 +1,10 @@ +public class StringBuilderChars05 +{ + public static void main(String[] args) + { + StringBuilder buffer = new StringBuilder("DiffBlue Limited"); + buffer.setCharAt(0, 'H'); + buffer.setCharAt(6, 'T'); + assert buffer.toString().equals("HiffBllTe Limited"); + } +} diff --git a/regression/strings/StringBuilderChars05/test.desc b/regression/strings/StringBuilderChars05/test.desc new file mode 100644 index 00000000000..2bcbdbab934 --- /dev/null +++ b/regression/strings/StringBuilderChars05/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringBuilderChars05.class +--string-refine --unwind 100 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringBuilderChars06/StringBuilderChars06.class b/regression/strings/StringBuilderChars06/StringBuilderChars06.class new file mode 100644 index 0000000000000000000000000000000000000000..e3597f40f878e29533d15df6a564a8735982154e GIT binary patch literal 856 zcmZuvU2hUW6g|Vo?y}t$*nU8*RjO5iYN=ZLLSqzK;{)mgji%L?g&peD1$1_|KZZZx zvzkC+6MgqL8RH$G#Z+Eq?(Up>&bc4I{(S!dU>iFo=5STVs)1`JBDk)OTmlx>RCL3@ zO%v<5rQ@~8;V;8>gUbU2riZp8It)wsx3v@J)G2vR=eSf4r05)%RpM+taGD=pI3I_2vdLiV zHoY;qS?`9j$)5>DwLD6zgu-*VtiE@ozqPZeSS_SsGh{9+jG+vvJ<)1aypZQ=qAddM zs*DW_cX7``5-AItC^4j69?*L&#}B+pt0ly99a|Re;{ii%vM z)c!{#KFNI5IN{BJVKG0w8@lADT>4b(O1|(PWL!>}S`>6gnj}62NQi$#&ygDc6gr-N zNquCgT%egICq}Ct4W7p4a$iX9UQ|re3PO6IsUKmDmS~QajHR-wi4;XaO@vM7JbkUw z&FGF72Vh?m5DRo_!=DTZEMkdb1${@U5xR?Kh#cC{0b;d{KH_h_LhB(zp>7*}Bzl-R zgLyc>%umG^8S>ePQ5>h`)yRg90t{s6j{){u?Qxc(Hq)$ literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderChars06/StringBuilderChars06.java b/regression/strings/StringBuilderChars06/StringBuilderChars06.java new file mode 100644 index 00000000000..f3b3b6bc8d8 --- /dev/null +++ b/regression/strings/StringBuilderChars06/StringBuilderChars06.java @@ -0,0 +1,9 @@ +public class StringBuilderChars06 +{ + public static void main(String[] args) + { + StringBuilder buffer = new StringBuilder("DiffBlue Limited"); + buffer.reverse(); + assert buffer.toString().equals("detimiL eTlBffiiH"); + } +} diff --git a/regression/strings/StringBuilderChars06/test.desc b/regression/strings/StringBuilderChars06/test.desc new file mode 100644 index 00000000000..4a711edf496 --- /dev/null +++ b/regression/strings/StringBuilderChars06/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringBuilderChars06.class +--string-refine --unwind 100 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring From c7bcdf4635b25dc8b77415781fd8463200469c0a Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:18:42 +0000 Subject: [PATCH 07/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20stringBuilder=20constructors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringBuilderConstructors01.class | Bin 0 -> 797 bytes .../StringBuilderConstructors01.java | 13 +++++++++++++ .../strings/StringBuilderConstructors01/test.desc | 8 ++++++++ .../StringBuilderConstructors02.class | Bin 0 -> 711 bytes .../StringBuilderConstructors02.java | 8 ++++++++ .../strings/StringBuilderConstructors02/test.desc | 8 ++++++++ 6 files changed, 37 insertions(+) create mode 100644 regression/strings/StringBuilderConstructors01/StringBuilderConstructors01.class create mode 100644 regression/strings/StringBuilderConstructors01/StringBuilderConstructors01.java create mode 100644 regression/strings/StringBuilderConstructors01/test.desc create mode 100644 regression/strings/StringBuilderConstructors02/StringBuilderConstructors02.class create mode 100644 regression/strings/StringBuilderConstructors02/StringBuilderConstructors02.java create mode 100644 regression/strings/StringBuilderConstructors02/test.desc diff --git a/regression/strings/StringBuilderConstructors01/StringBuilderConstructors01.class b/regression/strings/StringBuilderConstructors01/StringBuilderConstructors01.class new file mode 100644 index 0000000000000000000000000000000000000000..c7052b38c1f2d4b0cf579a5014877469af80212a GIT binary patch literal 797 zcmaJ;-%ry}6#nkoty|a0Rt8K52#7j`ax##qp@0|O6-~Ds(^A~_ktedEyX<*t!4o!8;6fvvf-4e=} zQ`x+M1rsF&yJun%_YFK?7+-Xvh|5@nLG(gIPT%Jq13O?SY>7a`PZ+e;(i;Z76MCFs ztSbV(mz?yue67ILIB`V4Fxfin9y=eM4c`d{8@*VHVDMNCR(i4HzTb5|qLKQWJsedoJoKWqDwB8d(M}0rx z>c3^-7RD?rVVR+k4L-Y){Zh(MGBp2lw}BN4t5{>GW(!{RkGUI@{??9?InlaVe!=I# zAbywHxI_MB3pzeoPsVvX5|Vq@gvhTrp$7SWfO&ep3cWF_Hk1y^G!PBc=(Oo?h9aYw zUmk*eQ$UQE)^`_z)6+dT4#UPh5n1w-k9!26}Q$9^x+Ay(Af(~I}lDbuB7ib%p8h!OT pp&QrIHd75i%`Tt8I)$Nsg|7X8kzH~nQ!UFQXFXMB+)g>%`3wBgq3Qqt literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderConstructors01/StringBuilderConstructors01.java b/regression/strings/StringBuilderConstructors01/StringBuilderConstructors01.java new file mode 100644 index 00000000000..efb5524c2b8 --- /dev/null +++ b/regression/strings/StringBuilderConstructors01/StringBuilderConstructors01.java @@ -0,0 +1,13 @@ +public class StringBuilderConstructors01 +{ + public static void main(String[] args) + { + StringBuilder buffer1 = new StringBuilder(); + StringBuilder buffer2 = new StringBuilder(10); + StringBuilder buffer3 = new StringBuilder("diffblue"); + + assert buffer1.length()==0; + assert buffer2.length()==0; + assert buffer3.length()>0; + } +} diff --git a/regression/strings/StringBuilderConstructors01/test.desc b/regression/strings/StringBuilderConstructors01/test.desc new file mode 100644 index 00000000000..2c60f9bbbda --- /dev/null +++ b/regression/strings/StringBuilderConstructors01/test.desc @@ -0,0 +1,8 @@ +KNOWNBUG +StringBuilderConstructors01.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/StringBuilderConstructors02/StringBuilderConstructors02.class b/regression/strings/StringBuilderConstructors02/StringBuilderConstructors02.class new file mode 100644 index 0000000000000000000000000000000000000000..2bfe2e70d3b3e6c08aaebe6686cc1326c7249f56 GIT binary patch literal 711 zcmaJfvG^o5LlGTq_EN2)qisVR@1?^3_*$Iic&?04-togLakm#|+Ly1C zky^T>?Pe+rr0#G@sm}Z~*2&{1kBqp72~-Jlw-a44SUFIKhy5^<2D$3N!?=evtP>g| z&hzVzUuqp|!oq*jI(Xorg*Kr!5_sD`mVQc@Y5lw9l03^qnA`$fvbNhi+v-TG6Y>Ih ze1S}qmcdPJJhe3A08f9Pw^iW{0#s|5me{jFW)^(b__oNF*cLa2pf3i9Nj^*YBQd#- zDfSKY9aAl~%NMZr>h=(Y?pG8Cn0{Ed&rup+>;lf-5apjn$I5jkn8V_5S+U7qXqs Date: Wed, 22 Feb 2017 14:19:25 +0000 Subject: [PATCH 08/59] =?UTF-8?q?=C2=A0added=20stringBuilder=20methods=20i?= =?UTF-8?q?nsert,=20delete=20and=20deleteCharAt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringBuilderInsertDelete01.class | Bin 0 -> 1924 bytes .../StringBuilderInsertDelete01.java | 46 ++++++++++++++++++ .../StringBuilderInsertDelete01/test.desc | 8 +++ .../StringBuilderInsertDelete02.class | Bin 0 -> 1725 bytes .../StringBuilderInsertDelete02.java | 40 +++++++++++++++ .../StringBuilderInsertDelete02/test.desc | 8 +++ .../StringBuilderInsertDelete03.class | Bin 0 -> 1819 bytes .../StringBuilderInsertDelete03.java | 43 ++++++++++++++++ .../StringBuilderInsertDelete03/test.desc | 8 +++ 9 files changed, 153 insertions(+) create mode 100644 regression/strings/StringBuilderInsertDelete01/StringBuilderInsertDelete01.class create mode 100644 regression/strings/StringBuilderInsertDelete01/StringBuilderInsertDelete01.java create mode 100644 regression/strings/StringBuilderInsertDelete01/test.desc create mode 100644 regression/strings/StringBuilderInsertDelete02/StringBuilderInsertDelete02.class create mode 100644 regression/strings/StringBuilderInsertDelete02/StringBuilderInsertDelete02.java create mode 100644 regression/strings/StringBuilderInsertDelete02/test.desc create mode 100644 regression/strings/StringBuilderInsertDelete03/StringBuilderInsertDelete03.class create mode 100644 regression/strings/StringBuilderInsertDelete03/StringBuilderInsertDelete03.java create mode 100644 regression/strings/StringBuilderInsertDelete03/test.desc diff --git a/regression/strings/StringBuilderInsertDelete01/StringBuilderInsertDelete01.class b/regression/strings/StringBuilderInsertDelete01/StringBuilderInsertDelete01.class new file mode 100644 index 0000000000000000000000000000000000000000..7858a392c3fa16230e3ae30f6ebaf25aecdb7726 GIT binary patch literal 1924 zcmb7FOK%%h6#lLsbM48vnK*GAH!o94ahikQo|^=j3y zY_n3XE}2z5S279=Y>Po!Fw3TWp1~a(xys;4RSE_}=c-vY)@wI&hP5fkq`0Y@Wrp6^ z_Ua9NS069w<(=^j+cL{L^I~IQ!`Acft?BRA`5c$&T#hRouhC^0d<*$f^B{SnQnT{L zvMJ0)8zwH)%u>Oy(q-Y~l2I~jV`4Hc4pMLuFVOyiSuEyCHQ|YERBeXv({40vD0m$k zbT>^1n*uTdt_rv&;JSdUfGq*r0^U&YCf-tT0?#wdClc{QBB4#i&uEhqjgK~~t!TDY zGc>bkYP*I-LtYp0)Py@)%RRcXg17MwL*KrCi>=sSw5*DyKu1nN9$AKi*6o&pb zapNc`Fi>Pr_kFmWyJ6%hY~BBnzeB`^VFuTBimJn`XM`ahOCQL4!`S@Dfu%$K%s;)M zp>4ZiD3;z%wX+x%gmk(cWiXcBIzr#}2-<&?{YyvKUp_*=)K2fSE3NSN#GWNmSS90w znqI0hgklGR-^vH|vr?#cPwHLWTBLLj#M)j+YOtx{_bVk;qPK!NysEI&S&wRDvR>87WF^(iWVu?*WPL(XB{fgTRh`hM+Jyf4x~x`6 z?oi8_bY&3NR2&4{V*(nY=HOUM zlq3h8%}L1PKyArh2VE_hIKige%N=w#<*?sDPgCxb9fYn$=&0Vgz;_7mAruJ&`y52} z(D4w*$))}uBZ^A20it*o}D3N|G{qA$l9e7HhU-h_{|6=gPfGh=l<>cCiZR5PA0sS?Q5L}%n}mkbf0+V;+~A xW1ObIIC(npq->_^^#ODRhaE)sz&&5XpA5B`2V@uzBGw;ot_ueT4TX( zm|In=%)mAn={7$DquYs-1(>wR+PjS&Oy^JJt?y zu4z}xmXoiEBp0lzxNaLq6hz{ z`_DMG12gzGbEK`^>L)`gnct&YJJ{U#o~382447kb$hx87}kB>7)QYO8F0&@`(JhG=q6^SgS`o$23|JXfVB zOAoGWHEhQ!KfOZq&fF#$=)G>x+Zdtm3&8ZaxVyysVB*CPzD%=G8X1j&qxZqSCBkr+ zP;MMmc#xPUHc(W^y}M&qNH1eVnBBaMOn8CMXpy0MMW@O z)=Pw3HwhKpB@DLKRlQEUPp=hLrD;iDnhxlET8==P;bHkyFamyBeTZQ3KGaz)q4|$_ z=<|m)4e@O~Tty$QL4%19 zD(FWY1NabOe1t)KiU>YK6rW=Vw-CdZh~q0HaF;&J-(VQ`NVW$g&d(&?FC^Trbk1)i z+wUaYAEd^gq|0A8!WdqqKgh!Vp^3(kJ?FrkK* literal 0 HcmV?d00001 diff --git a/regression/strings/StringBuilderInsertDelete02/StringBuilderInsertDelete02.java b/regression/strings/StringBuilderInsertDelete02/StringBuilderInsertDelete02.java new file mode 100644 index 00000000000..d0e4923ad3c --- /dev/null +++ b/regression/strings/StringBuilderInsertDelete02/StringBuilderInsertDelete02.java @@ -0,0 +1,40 @@ +public class StringBuilderInsertDelete02 +{ + public static void main(String[] args) + { + Object objectRef = "diffblue"; + String string = "test"; + char[] charArray = {'v', 'e', 'r', 'i', 'f', 'i', 'c', 'a', 't', 'i', 'o', 'n'}; + boolean booleanValue = true; + char characterValue = 'K'; + int integerValue = 7; + long longValue = 10000000; + float floatValue = 2.5f; + double doubleValue = 33.333; + + StringBuilder buffer = new StringBuilder(); + + buffer.insert(0, objectRef) + .insert(0, "-") + .insert(0, string) + .insert(0, "-") + .insert(0, charArray) + .insert(0, "-") + .insert(0, charArray, 3, 3) + .insert(0, "-") + .insert(0, booleanValue) + .insert(0, "-") + .insert(0, characterValue) + .insert(0, "-") + .insert(0, integerValue) + .insert(0, "-") + .insert(0, longValue) + .insert(0, "-") + .insert(0, floatValue) + .insert(0, "-") + .insert(0, doubleValue); + + String tmp=buffer.toString(); + assert tmp.equals("33.333-2.5-10000000-7-K-true-ifi-verification-test--diffblue"); + } +} diff --git a/regression/strings/StringBuilderInsertDelete02/test.desc b/regression/strings/StringBuilderInsertDelete02/test.desc new file mode 100644 index 00000000000..f78bf3f983a --- /dev/null +++ b/regression/strings/StringBuilderInsertDelete02/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringBuilderInsertDelete02.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringBuilderInsertDelete03/StringBuilderInsertDelete03.class b/regression/strings/StringBuilderInsertDelete03/StringBuilderInsertDelete03.class new file mode 100644 index 0000000000000000000000000000000000000000..6e238d7caea3b3ed8af71e3eb7a942336512b1ad GIT binary patch literal 1819 zcmah}O>7%Q6#mBE-LW^DX5*j4Zho3V0VnMyX_7i^5{gr&0XIJd61R22-`ZZ6Ev^mg zbtEo`0~fe(tEvbIi3_NQNX)! zGe7=)?*V`rSSm&^6~J@=GctVvZr*rbN{s+YDs}7A2RlF9;W(uth$#Wd0A|H_TEH0r za{}fCEC_g3z*zy$2}lW86mU*JI*4H`1#n))GM?vnLB$}ZI5H|OV1;9qA$-iN)hx%g ztCiZ4T{H7#tH{8%7?cIOV!LM<{E5*^3{tvUv>19;?TWQtzn-_8P2o(2>!w{{=u2#` zUNd*hiLzO_I|TOToI5Hu%%%euV{Ex7+%Bc8jj)#hUE0LF*Sbb(nj7Hf>|aa_o{_Fhx-fk(1HRk3kQ;p7~74F!-y`d)yG z`D<2z4j%p=1s-v124?VWr%7MCQB#KTL}s6I&0zDR`#wFA&-~*Hn%0gBh7+0Xbf<_T z!XcCCU|Do7&s0wpEKH z{u`gvP^@?AX1T@?P3+UGEhAmzp1n>V4qzou*7 z$T`2hlg&xGmCebzlg%l*oy~E*l+6VM(-ply$aRx2pu2>@#&=b(67SM0*>x!?=_^TD z=Sd|3X_kkS)4>S%8TCGbxw}y3w7BL!?xD*c(mZtgPY7sI!^5FARTK|Btw~h!ptrf~ zp|{P+C)DD7+(Wp<`-2`LEgn-nL@&oRoyI;IWt|rF6Y&t6>;4MyT}0#Ep~D^qcF}bo zgOuaYx1w;qM&Ukc)L5n}EA*!a5&?R6g4l$LE9j!9M}vuOl+c4Jdhsqocn@KGfCxTB z6d$7xH_(qy5W{DP;|mL}PhG|@Q5IF56i;4m0tlF!dEPE&FTVB%pr%rtZddPBn=j_iU Date: Wed, 22 Feb 2017 14:20:06 +0000 Subject: [PATCH 09/59] =?UTF-8?q?=C2=A0added=20string=20methods=20equals,?= =?UTF-8?q?=20equalsIgnoreCase,=20compareTo=20and=20regionMatches?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringCompare01/StringCompare01.class | Bin 0 -> 1325 bytes .../StringCompare01/StringCompare01.java | 47 ++++++++++++++++++ regression/strings/StringCompare01/test.desc | 8 +++ .../StringCompare02/StringCompare02.class | Bin 0 -> 721 bytes .../StringCompare02/StringCompare02.java | 14 ++++++ regression/strings/StringCompare02/test.desc | 8 +++ .../StringCompare03/StringCompare03.class | Bin 0 -> 723 bytes .../StringCompare03/StringCompare03.java | 14 ++++++ regression/strings/StringCompare03/test.desc | 8 +++ .../StringCompare04/StringCompare04.class | Bin 0 -> 703 bytes .../StringCompare04/StringCompare04.java | 9 ++++ regression/strings/StringCompare04/test.desc | 8 +++ .../StringCompare05/StringCompare05.class | Bin 0 -> 642 bytes .../StringCompare05/StringCompare05.java | 11 ++++ regression/strings/StringCompare05/test.desc | 8 +++ 15 files changed, 135 insertions(+) create mode 100644 regression/strings/StringCompare01/StringCompare01.class create mode 100644 regression/strings/StringCompare01/StringCompare01.java create mode 100644 regression/strings/StringCompare01/test.desc create mode 100644 regression/strings/StringCompare02/StringCompare02.class create mode 100644 regression/strings/StringCompare02/StringCompare02.java create mode 100644 regression/strings/StringCompare02/test.desc create mode 100644 regression/strings/StringCompare03/StringCompare03.class create mode 100644 regression/strings/StringCompare03/StringCompare03.java create mode 100644 regression/strings/StringCompare03/test.desc create mode 100644 regression/strings/StringCompare04/StringCompare04.class create mode 100644 regression/strings/StringCompare04/StringCompare04.java create mode 100644 regression/strings/StringCompare04/test.desc create mode 100644 regression/strings/StringCompare05/StringCompare05.class create mode 100644 regression/strings/StringCompare05/StringCompare05.java create mode 100644 regression/strings/StringCompare05/test.desc diff --git a/regression/strings/StringCompare01/StringCompare01.class b/regression/strings/StringCompare01/StringCompare01.class new file mode 100644 index 0000000000000000000000000000000000000000..38f0d216e1cf640abd23b0356795e344fe3faa94 GIT binary patch literal 1325 zcmZ`(T~8BH5IwiucDH4hmMtx3(h@YTe`KcLU*+!l(~l5A%8&YU?j_snEJ|N3|YU+%&2v1U&abZ%zOvsq@V+zwUE;ED%jY@^vj%k%Ecg>2C zE%H1A+hp+0n`P6v&EQUqK4Os4R-Q8imd!F>t(LOfUKd~rlnk@X5J@~<-ZEYqlSQLk zm|Sygvs{=HiQ1ZD+jYE*E7UoIGM_6R^ZVDVs-5HaOu^RO$V^+MZNuhM(-VSI zMHmr=U@JcrcX-7S;TZYa)p)RvoKkIA$)sPVxACUgkC(E$TC7G-Dz+UTDTt zT*WmNA#^iDPfIPH=(A+omaXDCZm774Srv1b7v>hJ($ckz+bZs0;h&x#WVd+EA<5ea z#Sl)km(R;zRE=V#1<>G{8>Kk~8-PrqY}q_*ROtR~xd`gZHDq14&cI}7TsAL|P%DO$ zd&a43G?Dqgu}nr(jwLqFj0H{wOc!azXhHJ4V%j|4)RXqYsZxOUYZC*swK}ag3r58R z=*tai5)raJbn2rwqqk@50PLLrB1+axHfe60ih2np9eDTA^&Y-mbR5FJae$6b6xnOzPQ|1e)OHE=^l);#1}&()Jtb=R$CJYU zqtzcu3ja{VSqg58EU%|9gn$|VSQgDy8c>3LeVuQ?HZqA+F-*eMsfkxu@PVn z0Yi1>aQC|GmrBKo3j0Uf#k~NVXfPCKNpJcmBGi99U8PZ(N({+Nm+SDYNJy&D{=XmX zc9S|=m=U%{)P8E-KqOL$!PFG>Oiu`)-XCFwe$S_mWyPu~gH9Gm5c9Ma=(bEdqusuL z3HHGRqDZTgJ~HG`LYdAcl*6WEV6B|#l&$Uq>!Ia+M)p0N3zR;>KF8cwIER;TzZ;@V zO0+~>D04MXRnLOxc>!vY}zGCxsq)0ro)H>S?EQwu<;Oe(o^xY-M2txvFL#fE+dAG=9}&bf6w*}J6+EijpW_nzQZ$(0$nuE^& z1L<^HG}^+Fu|1*r)AU9nkxGmfu4rg_MgR?efNgp{pI(*~tELaySs+EM(psR?7DYxe zd;1*hgGoe@Rwun=$f1NX?M>>CZY_$9a;96hdUtH=uH}7(J%@9K(nn8;+j@W!u$jC04SR*7r<|isH*6Gia*~-G&LFxf0l}RNxhijj~wmu=d TB)_z2h_c88k4-ZhsrHrMId_!7 literal 0 HcmV?d00001 diff --git a/regression/strings/StringCompare03/StringCompare03.java b/regression/strings/StringCompare03/StringCompare03.java new file mode 100644 index 00000000000..fbd881efd48 --- /dev/null +++ b/regression/strings/StringCompare03/StringCompare03.java @@ -0,0 +1,14 @@ +public class StringCompare03 +{ + public static void main(String[] args) + { + String s3 = "Automatic Test Generation"; + String s4 = "automatic test generation"; + + // test regionMatches (ignore case) + if (!s3.regionMatches(true, 0, s4, 0, 5)) //false + assert true; + else + assert false; + } +} diff --git a/regression/strings/StringCompare03/test.desc b/regression/strings/StringCompare03/test.desc new file mode 100644 index 00000000000..fa518907143 --- /dev/null +++ b/regression/strings/StringCompare03/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringCompare03.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringCompare04/StringCompare04.class b/regression/strings/StringCompare04/StringCompare04.class new file mode 100644 index 0000000000000000000000000000000000000000..cb288719581cd9f599cc0f3c56b08cebad443698 GIT binary patch literal 703 zcmZ`%O>fgc5PcInw&OU|b(<1C3TqKtf94kP4~oX=AUVEs0&(4ibN* z7ml1MQX^3b?))bZvo38!1=4DFc0S&FGrK>2effxynRuAR_`D5Ud>)tNaPUXs*2_nC&EzgsF~- zd$F=4KG*f|pK#r8nN{q1g^s<{7H7uLGD2;c3B<07BM5uBZH@CV%O zCZjZzFO`Oxy(nuZ!()-kN3AUl=wS*z!M_g9%(={R9bP5a{UnKcAEbvGZg_ZzCZRDY zd3M?4i!@DAZsQu0jWrMJ*!YX*P47sCIicSCcW0IGLg-%dpPW}rG||u=@ThrEk<3&o zqbo@~pM1mtp7Q|~`MErPO!6DL6SfR63VhzD`8Lld@mXFUgFfp-1iV{?lTg77X4%%M zhg@p#xq6P$eqfAYc7pQmDXbIJH#g2;`?Zg#p2OK6qw-y2l?to?Cfj8eVzC7NCH!gX y?5To&V#UTBFLvF$($p%*f$6|KL-ho<`3a`+1=a-fQlG{tqvSo+T{H^HTfYIp^o!pB literal 0 HcmV?d00001 diff --git a/regression/strings/StringCompare04/StringCompare04.java b/regression/strings/StringCompare04/StringCompare04.java new file mode 100644 index 00000000000..c602594930f --- /dev/null +++ b/regression/strings/StringCompare04/StringCompare04.java @@ -0,0 +1,9 @@ +public class StringCompare04 +{ + public static void main(String[] args) + { + String s1 = new String("test"); + String s2 = "goodbye"; + assert s2.compareTo(s1)==13; //false + } +} diff --git a/regression/strings/StringCompare04/test.desc b/regression/strings/StringCompare04/test.desc new file mode 100644 index 00000000000..f1b2a9790cc --- /dev/null +++ b/regression/strings/StringCompare04/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringCompare04.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringCompare05/StringCompare05.class b/regression/strings/StringCompare05/StringCompare05.class new file mode 100644 index 0000000000000000000000000000000000000000..70bbad48ef69bb1c1417507aa918529a4e104d94 GIT binary patch literal 642 zcmZvZ-%k@k5XZlJ*Sl-4*Waa7u}Be3!32DOCkWA0eJc7;V^Vn9wwq>adq?)J{xSUn z;2BJ8A_>0xHxa_@X=x<9?99&0e&#!~e{O$W1K7nY7cQy}o+R{zJ7%yCq%WgG2D7pGl_Aj#`hp?XlD_yf8Fz*H zqKhdp=F(@VG)`JW{+;iPxIfrwM@ssGef==gj(G3e5kHOVNfbl!pf~ylciX{4^~6W1 zQRTnSn!)&#EAeJ;TLV30kY&g}gj458gpp3Kdq~4$s4i;W&8PaHRG>)r1GIw|9yaju zKk(=7Q1l{(rN-l<g&<33 zj&3!wjI6aa1G~_L$kS=ZL536xD3Y&BJM`2byM6_uQ#5Btv|bm@GuY=ST*8_neFeKS zgY#Q+jF?k_MZQH6Y`Qxr5wT9U5=B!mZcuVi&XC5Xdqul(YoJg}{zPgDCvlF1`2*I1 SI#;JD77XvLo}m&qUA_a4#C#3_ literal 0 HcmV?d00001 diff --git a/regression/strings/StringCompare05/StringCompare05.java b/regression/strings/StringCompare05/StringCompare05.java new file mode 100644 index 00000000000..8764cb5c99a --- /dev/null +++ b/regression/strings/StringCompare05/StringCompare05.java @@ -0,0 +1,11 @@ +public class StringCompare05 +{ + public static void main(String[] args) + { + String s1 = new String("test"); + if (s1 == "test") // false; they are not the same object + assert true; + else + assert false; + } +} diff --git a/regression/strings/StringCompare05/test.desc b/regression/strings/StringCompare05/test.desc new file mode 100644 index 00000000000..159809fac0f --- /dev/null +++ b/regression/strings/StringCompare05/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringCompare05.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring From 48a1df89abbf0de1d3cdda59fe82c3f06be5e139 Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:21:49 +0000 Subject: [PATCH 10/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20string=20method=20concat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringConcatenation01.class | Bin 0 -> 864 bytes .../StringConcatenation01.java | 17 +++++++++++++++++ .../strings/StringConcatenation01/test.desc | 8 ++++++++ .../StringConcatenation02.class | Bin 0 -> 719 bytes .../StringConcatenation02.java | 10 ++++++++++ .../strings/StringConcatenation02/test.desc | 8 ++++++++ .../StringConcatenation03.class | Bin 0 -> 1099 bytes .../StringConcatenation03.java | 17 +++++++++++++++++ .../strings/StringConcatenation03/test.desc | 8 ++++++++ .../StringConcatenation04.class | Bin 0 -> 899 bytes .../StringConcatenation04.java | 10 ++++++++++ .../strings/StringConcatenation04/test.desc | 8 ++++++++ 12 files changed, 86 insertions(+) create mode 100644 regression/strings/StringConcatenation01/StringConcatenation01.class create mode 100644 regression/strings/StringConcatenation01/StringConcatenation01.java create mode 100644 regression/strings/StringConcatenation01/test.desc create mode 100644 regression/strings/StringConcatenation02/StringConcatenation02.class create mode 100644 regression/strings/StringConcatenation02/StringConcatenation02.java create mode 100644 regression/strings/StringConcatenation02/test.desc create mode 100644 regression/strings/StringConcatenation03/StringConcatenation03.class create mode 100644 regression/strings/StringConcatenation03/StringConcatenation03.java create mode 100644 regression/strings/StringConcatenation03/test.desc create mode 100644 regression/strings/StringConcatenation04/StringConcatenation04.class create mode 100644 regression/strings/StringConcatenation04/StringConcatenation04.java create mode 100644 regression/strings/StringConcatenation04/test.desc diff --git a/regression/strings/StringConcatenation01/StringConcatenation01.class b/regression/strings/StringConcatenation01/StringConcatenation01.class new file mode 100644 index 0000000000000000000000000000000000000000..8a2ee685b444d098b7dac80fa33ad12df6776cf4 GIT binary patch literal 864 zcmZuvTW=CU7(D|EyDVD^ON)rb(pnJ;Et>SnHb$iyA83uin6y3(%d}a#U2u0X@vra) zd{z^hsL^+SlN!HS%EiX)W-j05%sFS~=bta%0qmfz!$4lcO${pv=qTv8g;ffgc5PcilS=(_*>b4;*1X3uFw1^^9POT7-f;gmb2tuNqHqN%%;@ZIyji!q$xXRIT z!LiJ->f#!%bF48etcf(0Nv7f`-Bqa=gmTEh_8H1MDpJ`42BY11#b9>hp=7A`R3xA0 z#{-$X)WvjgEL6l$Z@=jsiT7eN6w%>kKTA|}xUGS6{Y(UJ_r$2E=eWUO?*!pra$Cb>k=ynT&*1b@$#KP3z$Ts)T$dMxzfckuf-}U3GBqILxI74|9~5p0%in zhnu*?(3nYjG@bKFlEewa(tn$Av^{jN&QO~{Ukr|9KrPRuCSY<&zRN|J5?%Y;_!Gc( zhit6QXu2VJO->DEsuDRo6GR4OIUSJE`&gwbtI$QVT0@UTkpZTMr?p03P1+gl*7_;f zCtZknTFXU}On{FCigjs>5`lsHeyQghd!J#BvAE$|Cn%3m`3C;_6!wov`nGTUo7U8& zg1QciVvDHC^l(yO({JWrk+L32ztH4ZqPI@@`kBtHLJ%1hm^p28R9eNpjAj*eTnt>BK1 z72MU)4}-x7({yuC5*_!j$}rMncoa77iR(Hp!c>=Rz_2B}MQGBZqN&l$$QM>PMSp0h;6)0DI| zhT=Iqr{~=1;%e@Hdc=nouX`l;G*1{rCQJ9)xn3tHl8>swvs_XA+g-Ac-=Yh$;VyYR zO_m2(W<*Ykc2Q6f7^LqI{f*PgXpK)FgMF4j4AVCe9Fk{n5hJvh(63MsqqSm0HjU`k z5n@I>_5+EX=*(;zN~sO?ZLr%uLh=xUbB5MN>JX{#(07i}_iKhOV#bATOn?uOk+VoC zBoYY8BSrf-sZP+Nl5#0Y#bszzTZ$~$M?SlN=Tv7I8C)WC8j%yMC>ZU$xd0v(yc|>p i^c(3mGKWxNpAd_FL9&-KEM9WO5z!yY7L5gx#{U2gd-sO` literal 0 HcmV?d00001 diff --git a/regression/strings/StringConcatenation03/StringConcatenation03.java b/regression/strings/StringConcatenation03/StringConcatenation03.java new file mode 100644 index 00000000000..56d397b96dc --- /dev/null +++ b/regression/strings/StringConcatenation03/StringConcatenation03.java @@ -0,0 +1,17 @@ +public class StringConcatenation03 +{ + public static void main(String[] args) + { + String s1 = "Happy at"; + String s2 = " DiffBlue"; + + System.out.printf( + "Result of s1.concat(s2) = %s\n", s1.concat(s2)); + String tmp=s1.concat(s2); + assert tmp.equals("Happy at DiffBllue"); + + tmp=s1; + System.out.printf("s1 after concatenation = %s\n", s1); + assert tmp.equals("Happy at"); + } +} diff --git a/regression/strings/StringConcatenation03/test.desc b/regression/strings/StringConcatenation03/test.desc new file mode 100644 index 00000000000..26ccc899a87 --- /dev/null +++ b/regression/strings/StringConcatenation03/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringConcatenation03.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringConcatenation04/StringConcatenation04.class b/regression/strings/StringConcatenation04/StringConcatenation04.class new file mode 100644 index 0000000000000000000000000000000000000000..047d2b908ab423d6ea731ab22809263555c418d8 GIT binary patch literal 899 zcmZ`%U2hUm5IvU#c3HOa(H5~Ex@xOXT4)vZ0W=z_@qwxdM$`Iqfm^Z_c5!zx>0jXw z_-svRqEX-dPa5YgQfSmsyZP?OGmhc14?k9WX?zmTmbD7?fQ86+^h@ zv;{+=ZrS45pw|@cOBqZLJ#N_yncSQD5r5B1U2b*_NKT7--aHa5LY53{W5>V+Bp702#(=V5;1+H(WT%)%6LlWDuH!N+ z{I{718VhDQr5B`@Pw|5HDm0TI{dqUdqc4LF8LGLz zg`U-Z+-4>JANHttH{e~5($DftKs5NowEJ3@wu5Hd7M|sb_L&$oQhz`Xv>FGrWCraX zz>--hDcuxM*GSQsroUCPjBI4%6zro6#5|qRz)1tZ0v72mLp$VE$QIL~dSUMbN;(|= zipaiFXp9hjeFAleh0U}!LTrfm7wG$^h<}%yp@1_J6cQnhDBV Date: Wed, 22 Feb 2017 14:22:27 +0000 Subject: [PATCH 11/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20string=20class=20constructors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringConstructors01.class | Bin 0 -> 1008 bytes .../StringConstructors01.java | 19 ++++++++++++++++++ .../strings/StringConstructors01/test.desc | 8 ++++++++ .../StringConstructors02.class | Bin 0 -> 652 bytes .../StringConstructors02.java | 9 +++++++++ .../strings/StringConstructors02/test.desc | 8 ++++++++ .../StringConstructors03.class | Bin 0 -> 713 bytes .../StringConstructors03.java | 10 +++++++++ .../strings/StringConstructors03/test.desc | 8 ++++++++ .../StringConstructors04.class | Bin 0 -> 736 bytes .../StringConstructors04.java | 10 +++++++++ .../strings/StringConstructors04/test.desc | 8 ++++++++ .../StringConstructors05.class | Bin 0 -> 736 bytes .../StringConstructors05.java | 10 +++++++++ .../strings/StringConstructors05/test.desc | 8 ++++++++ 15 files changed, 98 insertions(+) create mode 100644 regression/strings/StringConstructors01/StringConstructors01.class create mode 100644 regression/strings/StringConstructors01/StringConstructors01.java create mode 100644 regression/strings/StringConstructors01/test.desc create mode 100644 regression/strings/StringConstructors02/StringConstructors02.class create mode 100644 regression/strings/StringConstructors02/StringConstructors02.java create mode 100644 regression/strings/StringConstructors02/test.desc create mode 100644 regression/strings/StringConstructors03/StringConstructors03.class create mode 100644 regression/strings/StringConstructors03/StringConstructors03.java create mode 100644 regression/strings/StringConstructors03/test.desc create mode 100644 regression/strings/StringConstructors04/StringConstructors04.class create mode 100644 regression/strings/StringConstructors04/StringConstructors04.java create mode 100644 regression/strings/StringConstructors04/test.desc create mode 100644 regression/strings/StringConstructors05/StringConstructors05.class create mode 100644 regression/strings/StringConstructors05/StringConstructors05.java create mode 100644 regression/strings/StringConstructors05/test.desc diff --git a/regression/strings/StringConstructors01/StringConstructors01.class b/regression/strings/StringConstructors01/StringConstructors01.class new file mode 100644 index 0000000000000000000000000000000000000000..c4e2ce34c8353a953b7168f15c4f774be9ab10b7 GIT binary patch literal 1008 zcmZuwTTc@~7(LVO?kw9vhviaGQLCusT2Q=Dh>=uHhy@>TO%|TE?LropR`+8389w(9 z=&PF0M2weLf0X*oaud>IbLN}xHs3ij`}@z=?*JCCWS}1fj%zxu8%SYXLP5d}2{(I? z!z~>}xtZXYG>}0-$CQp~ju`{9C~?d&42(Nr=mwG3YKD)!(5d-ugMn=_Xv<#Hiykth zixV#yluE1NGUTdW(_N4EYHsjCCR1R~@tO?7#jWbD^VTW(PIITU5d~gzXGs?JZbVM~ z)td7<$>*5oxJ`32=*xBg=m=w@6$f?qsV5tb9u`+TVPb#*S=_^YhLO{%m1D|Jf}j=9Bn@wSyXMD|&EYcGZ3d19SuCP_ zW`gInUAG>QkX`6Aq_!#yL&fgOsKu>{REX2Mx+*QreG@x=c&_B|h@}a-l-wzaicdF3 zx;Na=3*5#DCz3mgDL~h@i2^-?etIxWj7T-eN`pxi35RJnMk`4Kb+QBYNhTsss3lH@ z9*kg=Y)WNCsNfX)CG>BqofZwtR)lBSs@S${O#&A+%hrW&*+LUBAs4PyJwVDf(;X;l z(&|86m+Le+%8In6I?&2$VsYL9FKeHnw=p`1y y9Ap1~Kt7+RMwd?nUPzP#`pw)vL>pZB044ne`sozMV$1F-QrSoHO0FbBUi}BKugVGl literal 0 HcmV?d00001 diff --git a/regression/strings/StringConstructors01/StringConstructors01.java b/regression/strings/StringConstructors01/StringConstructors01.java new file mode 100644 index 00000000000..406653de694 --- /dev/null +++ b/regression/strings/StringConstructors01/StringConstructors01.java @@ -0,0 +1,19 @@ +public class StringConstructors01 +{ + public static void main(String[] args) + { + char[] charArray = {'d', 'i', 'f', 'f', 'b', 'l', 'u', 'e'}; + String s = new String("test"); + + String s1 = new String(); + String s2 = new String(s); + String s3 = new String(charArray); + String s4 = new String(charArray, 4, 4); + + assert s1.equals(""); + assert s2.equals("test"); + assert s3.equals("diffblue"); + assert s4.equals("blue"); + } +} + diff --git a/regression/strings/StringConstructors01/test.desc b/regression/strings/StringConstructors01/test.desc new file mode 100644 index 00000000000..ed57bdfdde5 --- /dev/null +++ b/regression/strings/StringConstructors01/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringConstructors01.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/StringConstructors02/StringConstructors02.class b/regression/strings/StringConstructors02/StringConstructors02.class new file mode 100644 index 0000000000000000000000000000000000000000..0cca7f99377fa26a1d5759ce91374e67278d1aea GIT binary patch literal 652 zcmZuv-%k@k5dP+R?Om@2Eu~H)P?s)4eX!QN}$N_l>jQ;DHCn z1lt}uSah&Nm|YP`B6X_bD0!h0F%0F1KnH}mcd+VX z4G;f6-^8qvU@;SUQ a9QzaO!Wrxd*o`CuQiSC{Gs5rWT+J(Rc7c@u literal 0 HcmV?d00001 diff --git a/regression/strings/StringConstructors02/StringConstructors02.java b/regression/strings/StringConstructors02/StringConstructors02.java new file mode 100644 index 00000000000..b20877b8106 --- /dev/null +++ b/regression/strings/StringConstructors02/StringConstructors02.java @@ -0,0 +1,9 @@ +public class StringConstructors02 +{ + public static void main(String[] args) + { + String s1 = new String(); + assert s1.equals(" "); + } +} + diff --git a/regression/strings/StringConstructors02/test.desc b/regression/strings/StringConstructors02/test.desc new file mode 100644 index 00000000000..c2a30b3534c --- /dev/null +++ b/regression/strings/StringConstructors02/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringConstructors02.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringConstructors03/StringConstructors03.class b/regression/strings/StringConstructors03/StringConstructors03.class new file mode 100644 index 0000000000000000000000000000000000000000..fba6b043267ffe1fb0c5a30968bb053eee927c71 GIT binary patch literal 713 zcmZuuT~8B16g{{5+3jM>Qn09~C~7~5n8+K%XsSLHeJC*jU)*jdWO3Qm*;#)~|A5bG zLK8{!-T$QV<7tlF8gV_v74i&;0uH{ReA}WO$v8dO(v5RN6-MuO!VhIVlOwp>QSuMm8)k)! z#LHMiEuXganTwJ|q%xU5di+qM`lzEpXk47Y%=2^hd+-(og4Lpm&si$#vq vK)=y-u*8Q$SI>!UmJERTz&l250>}Ie)A$B!hIvL(<5;NpPxUITa^&(~b%c;< literal 0 HcmV?d00001 diff --git a/regression/strings/StringConstructors03/StringConstructors03.java b/regression/strings/StringConstructors03/StringConstructors03.java new file mode 100644 index 00000000000..a2f6ced182a --- /dev/null +++ b/regression/strings/StringConstructors03/StringConstructors03.java @@ -0,0 +1,10 @@ +public class StringConstructors03 +{ + public static void main(String[] args) + { + String s = new String("test"); + String s2 = new String(s); + assert s2.equals("tesst"); + } +} + diff --git a/regression/strings/StringConstructors03/test.desc b/regression/strings/StringConstructors03/test.desc new file mode 100644 index 00000000000..5419e5ae48e --- /dev/null +++ b/regression/strings/StringConstructors03/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringConstructors03.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringConstructors04/StringConstructors04.class b/regression/strings/StringConstructors04/StringConstructors04.class new file mode 100644 index 0000000000000000000000000000000000000000..d7705f364f37fe5fe5d3d350a6b66c3325a6e54e GIT binary patch literal 736 zcmZuvT~8BH5IxiG?%i&Sy_AAQMMY6tAl8RI2{D?g2}#jlU6Z9x+xAKpm#yxHf5HF2 zAMjaCXd*`6{ZAU_7NKf2_p3* zJLs$UxdwCMzz-tALcQ17_uu->(2w?--82rOy$xMB(@p)st8M@F1TS!dha=dVgYb8M zr#s5xfqES1Zi^?CZ5}6$vq3tFlRK^3x^W5TP$tNKNp$>X2_?)B%zhYVs)Spp6KYfB zgHw%<;&>Djs{dmVXq2#uwZAx?_V?8wCFFW-f~fb}TU%O`rQT$Im=Nacf2ckIZ!~y& z4Evkr%}sbKFxWTIAqH6n@}$P0?V$F@Bjb+ literal 0 HcmV?d00001 diff --git a/regression/strings/StringConstructors04/StringConstructors04.java b/regression/strings/StringConstructors04/StringConstructors04.java new file mode 100644 index 00000000000..bd9828e6a5f --- /dev/null +++ b/regression/strings/StringConstructors04/StringConstructors04.java @@ -0,0 +1,10 @@ +public class StringConstructors04 +{ + public static void main(String[] args) + { + char[] charArray = {'d', 'i', 'f', 'f', 'b', 'l', 'u', 'e'}; + String s4 = new String(charArray, 4, 4); + assert s4.equals("bllue"); + } +} + diff --git a/regression/strings/StringConstructors04/test.desc b/regression/strings/StringConstructors04/test.desc new file mode 100644 index 00000000000..21394f70327 --- /dev/null +++ b/regression/strings/StringConstructors04/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringConstructors04.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringConstructors05/StringConstructors05.class b/regression/strings/StringConstructors05/StringConstructors05.class new file mode 100644 index 0000000000000000000000000000000000000000..8339e1ddab342a080fd8c8be285bde13134446f3 GIT binary patch literal 736 zcmZuvO>fgc5Ph52UdM6CHcd+k6etu(+KO-}5>hJ!3UEpZQZSO6lVfixx2^;J;2-cO z@&`BrQX^3Wcm5NI*_1YbxXkX(zM1#l?0*0G`73}eY+5Me631l=1zahigcTE4)!`b) zbqicwu3ET(n;dHl3u|7Q$|MU%arz`oy+I@c2DZmw?1XWcJ!B|0ny(nN_9&1Hl};GT z=lRh{+UI|trduN8Umeyf)yVZ6Vs3g>#6=O6BRucvs9TO^Lb-0`E| z{jJ_8Pki|-RNa7f@jk|B|TuZ5uY`7)n7n93Bp$T-vyU z219*@ethQhX_AZ*hT8v_IGQ%rvGEsAcW@y6jG@qPGw6+eTiG(?o7{_1hQ-DozE7ds zO`2b2M%|8R$TXrrrePw3b0svHET;>a@E%s_t;+O!@OZ_6qtA8WjUCg!x5xiz0AbO@xlCi=pEhDsVAyTvJ4jD-4lSVpik9>i5g|fU_a31Smaou o)Wvi4TT_|9e6@58YYeWvhgSRqZPxS5iRz=HU_VlR>r=|*UmKy5;Q#;t literal 0 HcmV?d00001 diff --git a/regression/strings/StringConstructors05/StringConstructors05.java b/regression/strings/StringConstructors05/StringConstructors05.java new file mode 100644 index 00000000000..49cc43f4269 --- /dev/null +++ b/regression/strings/StringConstructors05/StringConstructors05.java @@ -0,0 +1,10 @@ +public class StringConstructors05 +{ + public static void main(String[] args) + { + char[] charArray = {'d', 'i', 'f', 'f', 'b', 'l', 'u', 'e'}; + String s3 = new String(charArray); + assert s3.equals("diffkblue"); + } +} + diff --git a/regression/strings/StringConstructors05/test.desc b/regression/strings/StringConstructors05/test.desc new file mode 100644 index 00000000000..9804850d77e --- /dev/null +++ b/regression/strings/StringConstructors05/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringConstructors05.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring From f0cffa69e29879074adb565d01b6346d395bde9e Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:23:22 +0000 Subject: [PATCH 12/59] =?UTF-8?q?=C2=A0added=20string=20searching=20method?= =?UTF-8?q?s=20indexOf=20and=20lastIndexOf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringIndexMethods01.class | Bin 0 -> 1181 bytes .../StringIndexMethods01.java | 20 ++++++++++++++++++ .../strings/StringIndexMethods01/test.desc | 8 +++++++ .../StringIndexMethods02.class | Bin 0 -> 666 bytes .../StringIndexMethods02.java | 8 +++++++ .../strings/StringIndexMethods02/test.desc | 8 +++++++ .../StringIndexMethods03.class | Bin 0 -> 667 bytes .../StringIndexMethods03.java | 8 +++++++ .../strings/StringIndexMethods03/test.desc | 8 +++++++ .../StringIndexMethods04.class | Bin 0 -> 695 bytes .../StringIndexMethods04.java | 8 +++++++ .../strings/StringIndexMethods04/test.desc | 8 +++++++ .../StringIndexMethods05.class | Bin 0 -> 701 bytes .../StringIndexMethods05.java | 8 +++++++ .../strings/StringIndexMethods05/test.desc | 8 +++++++ 15 files changed, 92 insertions(+) create mode 100644 regression/strings/StringIndexMethods01/StringIndexMethods01.class create mode 100644 regression/strings/StringIndexMethods01/StringIndexMethods01.java create mode 100644 regression/strings/StringIndexMethods01/test.desc create mode 100644 regression/strings/StringIndexMethods02/StringIndexMethods02.class create mode 100644 regression/strings/StringIndexMethods02/StringIndexMethods02.java create mode 100644 regression/strings/StringIndexMethods02/test.desc create mode 100644 regression/strings/StringIndexMethods03/StringIndexMethods03.class create mode 100644 regression/strings/StringIndexMethods03/StringIndexMethods03.java create mode 100644 regression/strings/StringIndexMethods03/test.desc create mode 100644 regression/strings/StringIndexMethods04/StringIndexMethods04.class create mode 100644 regression/strings/StringIndexMethods04/StringIndexMethods04.java create mode 100644 regression/strings/StringIndexMethods04/test.desc create mode 100644 regression/strings/StringIndexMethods05/StringIndexMethods05.class create mode 100644 regression/strings/StringIndexMethods05/StringIndexMethods05.java create mode 100644 regression/strings/StringIndexMethods05/test.desc diff --git a/regression/strings/StringIndexMethods01/StringIndexMethods01.class b/regression/strings/StringIndexMethods01/StringIndexMethods01.class new file mode 100644 index 0000000000000000000000000000000000000000..f8086f133e6a279bb2247de2ef88906628d9fe73 GIT binary patch literal 1181 zcmZuv%Wl(95Ir}K+I1Y_IBnvT7AUlkHqZz3-SScaDN;)pMM#v@jeS#GQU}=%V#`k; zwHubKDN-td1bZZYgRelqT$eT?iDb>#bLN~oK6AhS{`?id9PVn!VN}KCeq?b)!x+XD zT-A`osQkDlLrI1S6_YZTWw@^5hRjnkOskktFstDvZYh{!$c^zJ5Ps-3yx@Tw@M>K+ z3~Yy?Z_V}G@D4+~H1U)nvEFb5LuSME#N+0ERrpV2GXeYD^%(M{=No(cHJ`3?Z+Ch- z^j&XvRT9(NA-7*{@>fy6f_VmY&946w*R~r?-xiNtDOEh7RXj($*%aZ6h7-)pPDxcA zc@!ANc{6P6^U$?J5rj4m#IEp!PlblZL&vSvs`aMOF@QljNXG&e8LakL_fP-zq3<_* zi7)9`#-a>MG*??;0V@(-WzgD3$Tli3%X0tOC=3I==2oz#<2J}ZqdmY@bx+vgf29*H zgW}5H-l~zKrOHHwAz7+KIaTLD7)H)7MEUpjJl&t}mQ3H)um) zlK|TE4o2y6<>782HJEF!Y z&ziA~Bg7ApFB^6X2}6C4)E6Y59i#8tDZmpgC|$r{*%%{6tOtRVR3qI9SY?A7#TNRF zd?$3GrS{M=wH8vwNGHK6o0_4tpm#(0vYD2gY$t~R5&UBNl&H5sX37%Jw;;7w?#A%(Zlaey?AsOJYV_z44lkYz=fY=(9?Ow1hgUl>*} zVil|*dMvA$Cz%Up>zs@B24u}_3+5q|#0MnepAc`)aJpKlmqbjzCojOoXv9l@0fmtI AQUCw| literal 0 HcmV?d00001 diff --git a/regression/strings/StringIndexMethods01/StringIndexMethods01.java b/regression/strings/StringIndexMethods01/StringIndexMethods01.java new file mode 100644 index 00000000000..da000057993 --- /dev/null +++ b/regression/strings/StringIndexMethods01/StringIndexMethods01.java @@ -0,0 +1,20 @@ +public class StringIndexMethods01 +{ + public static void main(String[] args) + { + String letters = "automatictestcasegenerationatdiffblue"; + + assert letters.indexOf('c')==8; + assert letters.indexOf('a', 1)==5; + assert letters.indexOf('$')==-1; + assert letters.lastIndexOf('c')==13; + assert letters.lastIndexOf('a', 25)==22; + assert letters.lastIndexOf('$')==-1; + assert letters.indexOf("diffblue")==29; + assert letters.indexOf("diffblue", 7)==29; + assert letters.indexOf("generation")==17; + assert letters.lastIndexOf("diffblue")==29; + assert letters.lastIndexOf("diffblue", 25)==-1; + assert letters.lastIndexOf("automatic")==0; + } +} diff --git a/regression/strings/StringIndexMethods01/test.desc b/regression/strings/StringIndexMethods01/test.desc new file mode 100644 index 00000000000..005d4459f12 --- /dev/null +++ b/regression/strings/StringIndexMethods01/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringIndexMethods01.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/StringIndexMethods02/StringIndexMethods02.class b/regression/strings/StringIndexMethods02/StringIndexMethods02.class new file mode 100644 index 0000000000000000000000000000000000000000..fe322fde894d06c831a4097040b85f7f2dbd88f0 GIT binary patch literal 666 zcmZuu&rcIU6#ibfyVEWUl!COVMN!bAi5SC8Vl=2plOl&26Y(_Noz}tauGyV6{w-WQ zdR7xiG|{_%lQF(ogvP|ndvD&n@5j9P`TOg40Nc3fqmEV$?K%Wjd|bpOfy+Kzv;;an zR&hn(Dq(S5=DEs@PLuqx&gC#x5rGZ}-i}VRc|dTwn=c5}-852!`Myrnvtlw-*>gM0 z7Za%y!gBXj|4_b@Td_>WTLY8nWPINOX9q@xZ}#Nda$aDKP}>RPzvTWPEwWHO)s|}I z6xK^3^?py8*J+gBy?4j51_&@q*pP)uC(`K9sN94yS7Vi^j2mepO{7PoVO*#HK4w@b zz%^Vaw5PTnoxSx*mZceC>3@O(>j5@!gV2~F_lJinH2<_tu>_&5-~AE6?e=<`Jzmlj zw;S_*c{`EHb*7?o1H2Sd@C7gT0Bih5b^bPLw5@fn9FTo6$2mTAI1^|0)(Pm79mG6G zuWS-S8(84lj`kT^;k??c^gqKnLhE)zR*z9_cpotH4erYmct0#hrR137c_!xQv5Y{I wPc_glbOaW;S~@qeU8(^KO>vCc5k&PPs?HZUQ?fHdmc&IRcxY{3D7BXV0QGx_?EnA( literal 0 HcmV?d00001 diff --git a/regression/strings/StringIndexMethods02/StringIndexMethods02.java b/regression/strings/StringIndexMethods02/StringIndexMethods02.java new file mode 100644 index 00000000000..5c2ea999dd0 --- /dev/null +++ b/regression/strings/StringIndexMethods02/StringIndexMethods02.java @@ -0,0 +1,8 @@ +public class StringIndexMethods02 +{ + public static void main(String[] args) + { + String letters = "automatictestcasegenerationatdiffblue"; + assert letters.indexOf('a', 1)==6; + } +} diff --git a/regression/strings/StringIndexMethods02/test.desc b/regression/strings/StringIndexMethods02/test.desc new file mode 100644 index 00000000000..cad6c487fae --- /dev/null +++ b/regression/strings/StringIndexMethods02/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringIndexMethods02.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringIndexMethods03/StringIndexMethods03.class b/regression/strings/StringIndexMethods03/StringIndexMethods03.class new file mode 100644 index 0000000000000000000000000000000000000000..e8733f571683a9351d676f8865818ef6c30d224d GIT binary patch literal 667 zcmZuv-)j>=5dJ22$t9O-o2I`~+ghusrV3WDZx&IiLL{{h5yASjx!c68mpi%L6aSXJ z_~^3=Ehy-_f0Kx_SKA=S!tCtKeBXRKyFY(_{SIIUH+56eC-Va3C$k201# ztogW%bq`kvb8Vru%#2DC{YYssh-E~eLqcU&CCc0ROPi15w6cw5wa*dSDQ!}u?`-%s-_luwkU zT0VnylSsbbm*#aE={t9CTh;&prU;uNH|bay6&k5cD6|~OL}naF6Ja7X91h}K2Jlhm zMggwk8lg3j_3-?zkFzYz2=o7I=%F286W0li3G!fYBt!F0=nPA!$3mMz^TCkE(dlk= zc}^4P9_KX=D3V%bGP=;fb1^w5c)o|&;Ag7w%Tc3c)wAb-?4{XG^J$HD;=O$H6!gg! zVuo#{2oggZm}TFVK1GQau-Yv3KEpZ2!mUR81g`r5^=~M@JVoV)WhfO4)7*$@*;cT^ yBAR@vf_~ZmGRNNhg@m1=7ckrOPEb9D=YE9ie1S6|JC|cg$|wa7tmuWJ*Ww>}&57Rt literal 0 HcmV?d00001 diff --git a/regression/strings/StringIndexMethods03/StringIndexMethods03.java b/regression/strings/StringIndexMethods03/StringIndexMethods03.java new file mode 100644 index 00000000000..83b710073b5 --- /dev/null +++ b/regression/strings/StringIndexMethods03/StringIndexMethods03.java @@ -0,0 +1,8 @@ +public class StringIndexMethods03 +{ + public static void main(String[] args) + { + String letters = "automatictestcasegenerationatdiffblue"; + assert letters.lastIndexOf('$')==1; + } +} diff --git a/regression/strings/StringIndexMethods03/test.desc b/regression/strings/StringIndexMethods03/test.desc new file mode 100644 index 00000000000..3dff0b27714 --- /dev/null +++ b/regression/strings/StringIndexMethods03/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringIndexMethods03.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringIndexMethods04/StringIndexMethods04.class b/regression/strings/StringIndexMethods04/StringIndexMethods04.class new file mode 100644 index 0000000000000000000000000000000000000000..69a8fe4d628343caa7e78dbb94db2c2836b7591c GIT binary patch literal 695 zcmZuv!EVz)5PcITw&S{KnzkW@6liH71&MOVjS7JZNEInPq(Y)SZR}0h;@HSuBfg~< zj+_Chl|X_!--HmeE@^~RS(=^Moq6x=TmSm=?FWD^Ha&P~xmd2k#Z?#AJhZXm;JODJ zEeAI|+{CJbHNwKW$TFE~mBiUom5D(lLjoNV>}?e*{fJ<7HeV6SJ4q-Bb3GNym-%=g z(*x7Y2VDv?CMjX@GHwUAecVBZP@hij4~}J^|JypBB{<4R-yaf| zI+wVy%l=Jqb|SW(jSFR_QW;(dV!w3G2kiSHR`~@zepITr%&j=Hz@DPUagM7MUWwPr z-80Z<(}+4pyVxXDF^>l4ru79%{P9Sm)cXSK1kHPm@+m6y_D9TohyD5t&QAkTDj;gi z#JC)7{(BrOaOHx2qwQdkv!x3S-GU65Z@8zZp1>)8LfQHXYYH~eV?Zh>`Hzk2X2Esk EFZ08aZ~y=R literal 0 HcmV?d00001 diff --git a/regression/strings/StringIndexMethods04/StringIndexMethods04.java b/regression/strings/StringIndexMethods04/StringIndexMethods04.java new file mode 100644 index 00000000000..1271bcaf36b --- /dev/null +++ b/regression/strings/StringIndexMethods04/StringIndexMethods04.java @@ -0,0 +1,8 @@ +public class StringIndexMethods04 +{ + public static void main(String[] args) + { + String letters = "automatictestcasegenerationatdiffblue"; + assert letters.indexOf("diffblue")==28; + } +} diff --git a/regression/strings/StringIndexMethods04/test.desc b/regression/strings/StringIndexMethods04/test.desc new file mode 100644 index 00000000000..758f22d2bf4 --- /dev/null +++ b/regression/strings/StringIndexMethods04/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringIndexMethods04.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringIndexMethods05/StringIndexMethods05.class b/regression/strings/StringIndexMethods05/StringIndexMethods05.class new file mode 100644 index 0000000000000000000000000000000000000000..a4f4f7674958e1569272f8ec1afd17e2acd9bfb2 GIT binary patch literal 701 zcmZuv&rcIU6#k~W-Q8}NQVK$=f}kL+CgK545~D#)niM&dn1HA0?z9eWcgfDI@o(Yc z(X*OBqKV%9n~d?zVrh(C-miJ@`@VTIKYo4r24EW>fxG?>sWTN;=@7H z#SI^;SaWfcVSb$}B{D73L_L*?4`LB9up^feFP?D3PL-^DEkZzqiZfcyP4&qDEB z8mQLAST~8pyFH;_r;)n<;GRJZFoPPy2G4am=30hYC>?SoMj{az71D(3NDhaCI2Qq` z2#95p6K8;RY%nyZ3ZG1_{VdDUjA7w_+%9eh*hHJ5KAqej9E(u@Rl1mEsK#9BLjL~H ztmNN~bUR&I;uLI`CKR{8*>SUdw$WXx?8Wfw>9*vgBuQW=%Pq0q0bhlyGTW2WS?@|2<=kOfvcY{$X zFly9Kz+@ewaWPMs2lmr^rv-|xT#DE(*nqi)cZSL-T>ArT>ocq=*hG*4DWeoTHnJBB GuBG4EL6lnn literal 0 HcmV?d00001 diff --git a/regression/strings/StringIndexMethods05/StringIndexMethods05.java b/regression/strings/StringIndexMethods05/StringIndexMethods05.java new file mode 100644 index 00000000000..f6de4ce541b --- /dev/null +++ b/regression/strings/StringIndexMethods05/StringIndexMethods05.java @@ -0,0 +1,8 @@ +public class StringIndexMethods05 +{ + public static void main(String[] args) + { + String letters = "automatictestcasegenerationatdiffblue"; + assert letters.lastIndexOf("diffblue", 25)==1; + } +} diff --git a/regression/strings/StringIndexMethods05/test.desc b/regression/strings/StringIndexMethods05/test.desc new file mode 100644 index 00000000000..d415ef1381e --- /dev/null +++ b/regression/strings/StringIndexMethods05/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringIndexMethods05.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring From b5d6a133e3957e1b0d9b2ed230f6327b18e5e5f8 Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:24:07 +0000 Subject: [PATCH 13/59] =?UTF-8?q?=C2=A0added=20string=20methods=20length,?= =?UTF-8?q?=20position,=20replace,=20toUpperCase,=20toLowerCase,=20and=20t?= =?UTF-8?q?rim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringMiscellaneous01.class | Bin 0 -> 1382 bytes .../StringMiscellaneous01.java | 32 ++++++++++++++ .../strings/StringMiscellaneous01/test.desc | 8 ++++ .../StringMiscellaneous02.class | Bin 0 -> 650 bytes .../StringMiscellaneous02.java | 8 ++++ .../strings/StringMiscellaneous02/test.desc | 8 ++++ .../StringMiscellaneous03.class | Bin 0 -> 821 bytes .../StringMiscellaneous03.java | 15 +++++++ .../strings/StringMiscellaneous03/test.desc | 8 ++++ .../StringMiscellaneous04.class | Bin 0 -> 1733 bytes .../StringMiscellaneous04.java | 40 ++++++++++++++++++ .../strings/StringMiscellaneous04/test.desc | 8 ++++ 12 files changed, 127 insertions(+) create mode 100644 regression/strings/StringMiscellaneous01/StringMiscellaneous01.class create mode 100644 regression/strings/StringMiscellaneous01/StringMiscellaneous01.java create mode 100644 regression/strings/StringMiscellaneous01/test.desc create mode 100644 regression/strings/StringMiscellaneous02/StringMiscellaneous02.class create mode 100644 regression/strings/StringMiscellaneous02/StringMiscellaneous02.java create mode 100644 regression/strings/StringMiscellaneous02/test.desc create mode 100644 regression/strings/StringMiscellaneous03/StringMiscellaneous03.class create mode 100644 regression/strings/StringMiscellaneous03/StringMiscellaneous03.java create mode 100644 regression/strings/StringMiscellaneous03/test.desc create mode 100644 regression/strings/StringMiscellaneous04/StringMiscellaneous04.class create mode 100644 regression/strings/StringMiscellaneous04/StringMiscellaneous04.java create mode 100644 regression/strings/StringMiscellaneous04/test.desc diff --git a/regression/strings/StringMiscellaneous01/StringMiscellaneous01.class b/regression/strings/StringMiscellaneous01/StringMiscellaneous01.class new file mode 100644 index 0000000000000000000000000000000000000000..4f63b35324bc7a9d90f2659386560f3732184be5 GIT binary patch literal 1382 zcmZux-*XdH6#j1Z$K7lfnx<^qRG~qrrW9Jx5VfgFNufsj18GMG`n26#%R;it?A|cL zgEKzxSJVe*c8U)7_``BGnAuZL=Xt33{@Z_tmz5W2N3q^g$C zvQ)2c*6M1Qj1*m+zNSo`noW{@u&<9MjWi8pLnJ{g8V91%9LhF1Xr6E5G+mwnx>YPU zrpAF*8Yl;&^c*AWB)u8EjdM@Iep7)c(9=ve8L}A1d$gud_K>cgO}= 0; count--) + { + System.out.printf("%c ", s1.charAt(count)); + assert s1.charAt(count) == s2.charAt(i); + ++i; + } + + // copy characters from string into charArray + s1.getChars(0, 5, charArray, 0); + i=0; + for (char character : charArray) + { + System.out.print(character); + assert s3.charAt(i) == character; + ++i; + } + + System.out.println(); + } +} diff --git a/regression/strings/StringMiscellaneous01/test.desc b/regression/strings/StringMiscellaneous01/test.desc new file mode 100644 index 00000000000..050c3e99e90 --- /dev/null +++ b/regression/strings/StringMiscellaneous01/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringMiscellaneous01.class +--string-refine --unwind 30 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/StringMiscellaneous02/StringMiscellaneous02.class b/regression/strings/StringMiscellaneous02/StringMiscellaneous02.class new file mode 100644 index 0000000000000000000000000000000000000000..f1d880c012a9bca0bd88834aef0e69b29beb6655 GIT binary patch literal 650 zcmZuvT~8B16g{`wcG_iuQoc$NErN=gh%vlLj08VIQuLw3M0}cVCuMLuYi4KtF}(Qb zvzkDniN5=rjPcGQG$v+~JNM4qbMBcl`}6nL?*O)ND?}ZOHMHswSPId`vcQ!P6)Xy@ zgt&@p0v*Eay38_VolZ^mL}#*}r~!cv3Ds?Fw0lGdHg3Nnly}pCB20I+Q7`gQU)clS z%m*W>4Pjy9P4`&7mz#++!_A(v+6*6h;AGFq`0c)YSM&?45^CFV@|Qg9rMZpOGwrF` z=dgX9#VTPQmFC&~2lqT}gb0&_rJdZRBk6S9IZ&DFJXc0pE>jaB#00ZPxQ;bKYpiAG z;(|}DO)X*mzf%O(Biz7ELSqbl**{jX`)BJM%=RS84Bb&-&mQ|S2JI$nDH}3SnYLKSEOkF4IKkZAQmG?6PcyQmF;3g4PP9mKvLyXk$vyHcg;DKum0(mSsY>F1u!T)-UK+ z;EQj4Ruh`2(RaVVZ}CCAyR{`IO(rw<&fI&>nKSeA&zJ82HtwIo97{Z7h*zqw7^J4# z=M3qV&$}g)(xEGY2Jz}xK~0B_86B&5z_2it+_>=Jh3B~*L+(l$ z3f6SgvCfd0w!Z8gb5oF+S6J|0;W;Ej?664&+uRw5qsZVrO3fp~YY>W5*{jlVdWzq) z>5<6dKKCt;_b-)_vm&4adZ7c9>7i5f2UunyydXt!u+T4>Gn6gT%4n5W&cHr~g_xx| z5p6PR&SH+@uyjPN30fQ3SSuTEtKa1P_@-1FLz4QNa!!7a>LQ6SBaN$(Siw@K}FswyHrK@JH8 zIR*34xWPzz`8PGGSh&2>Mx-5>%_hgtMo^?vNb%2*r@R-}3vp${^zG1ud?c&z7nhHw AM*si- literal 0 HcmV?d00001 diff --git a/regression/strings/StringMiscellaneous03/StringMiscellaneous03.java b/regression/strings/StringMiscellaneous03/StringMiscellaneous03.java new file mode 100644 index 00000000000..2adfe30f5d0 --- /dev/null +++ b/regression/strings/StringMiscellaneous03/StringMiscellaneous03.java @@ -0,0 +1,15 @@ +public class StringMiscellaneous03 +{ + public static void main(String[] args) + { + String s1 = "Automatic Test Generation"; + String s2 = "noitareneG tseT citamotuA"; + char[] charArray = new char[5]; + int i=0; + for (int count = s1.length() - 1; count >= 0; count--) + { + assert s1.charAt(count) != s2.charAt(i); + ++i; + } + } +} diff --git a/regression/strings/StringMiscellaneous03/test.desc b/regression/strings/StringMiscellaneous03/test.desc new file mode 100644 index 00000000000..f255272ed5b --- /dev/null +++ b/regression/strings/StringMiscellaneous03/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringMiscellaneous03.class +--string-refine --unwind 30 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringMiscellaneous04/StringMiscellaneous04.class b/regression/strings/StringMiscellaneous04/StringMiscellaneous04.class new file mode 100644 index 0000000000000000000000000000000000000000..c7f02bedbb23ef52f70e38b64db6957dcab1859a GIT binary patch literal 1733 zcmZ`(O;cM{7=BK^&ducl>4i{&qSt;U;iG_Jus~~RNGcjaB|ruIx+Ev`Vo2h>H+H)3 z!j(UOjWaIVjT`GsI-_IVxa!iM;L4>lZac;I-0+cfaFWS+&v`%2bDsBk^Zey6&j3uL zq@oL>3dR(SE4UiQ5GGViVv6H!6&#~syn|^4?{cK%`HYJ9a81Fi+{`JMm+N%}H{|-h zf}3((P;g7erR8Q(S{aV4ire^rq3@FEIKpwG<3o;*7?k;9<>(5vP;1ylk+o#Op;q#;&m7}0x4eK7j zY*qr)uz|a@UtG#&Z{^lA8a|Qx9#=T-uBZyzl+0_`l&9en+#0s9O-wjbhUpllQM_l` zX3-V4VcNF&z_?D&`V^mO_#9to_)>BbJ(D#K;%o=S4#=%Y>iroVWAJUKsrlmThFNi_ zY@)5Jt+&o4NgZtr6dpLP*e9LT8ZITY;;q`m9g=`ccL{TUj)B`PR;5zX>112g790xc z^H}Z7Bq()Rr_3B2QatzKD>Ny+r{YOhX!?kel5i|rlui^$ zBjYy6L8G^Yx9DG>i~b&1WKe3EEI*hW1o|~-H%u#|H8}DV>?bl9r2rxCkW_^WxJb4E z__mI@Bsazy03}Q0lIz#-+T(?_tx>4?mz2zTo1f@9M;vqZ|K_e zk4DOoY!h0ciSE0{o7sR@FB%KzJ)N1OP4u>TBc0x{CeF2a^-k}26Mb#o{!TAdj?M<3 zAgm8Gao(Q_#e%au#-F7We<~aeN0lEi9^=vQbV~KWosX)zFB)oM@cUC59){S%FnfIX zC)H^pCdu`AVh;iyfh(4T14imvDW{BQAx@j(ZXzaRCMlb4!;9KbU4t;opD1O8M z{=gufBZj}IqkmHe|DkUF3xjpz0*m7!8zFlVS6B*hT%wycpuU8`ak=#!7=^D{!Iu7bpgj;1}q0O$0fCSE%L4?IS||1*N8&py_a RgcO8NyD62Iq>T?F{{f+OeIx(? literal 0 HcmV?d00001 diff --git a/regression/strings/StringMiscellaneous04/StringMiscellaneous04.java b/regression/strings/StringMiscellaneous04/StringMiscellaneous04.java new file mode 100644 index 00000000000..e9fe0292317 --- /dev/null +++ b/regression/strings/StringMiscellaneous04/StringMiscellaneous04.java @@ -0,0 +1,40 @@ +public class StringMiscellaneous04 +{ + public static void main(String[] args) + { + String s1 = "diffblue"; + String s2 = "TESTGENERATION"; + String s3 = " automated "; + + assert s1.equals("diffblue"); + assert s2.equals("TESTGENERATION"); + assert s3.equals(" automated "); + + System.out.printf( + "Replace 'f' with 'F' in s1: %s\n\n", s1.replace('f', 'F')); + String tmp=s1.replace('f', 'F'); + assert tmp.equals("diFFblue"); + + tmp=s1.toUpperCase(); + assert tmp.equals("DIFFBLUE"); + + tmp=s2.toLowerCase(); + assert tmp.equals("testgeneration"); + + tmp=s3.trim(); + assert tmp.equals("automated"); + + // test toCharArray method + char[] charArray = s1.toCharArray(); + System.out.print("s1 as a character array = "); + + int i=0; + for (char character : charArray) + { + assert character=="diffblue".charAt(i); + ++i; + } + + System.out.println(); + } +} diff --git a/regression/strings/StringMiscellaneous04/test.desc b/regression/strings/StringMiscellaneous04/test.desc new file mode 100644 index 00000000000..737ab3b0f8c --- /dev/null +++ b/regression/strings/StringMiscellaneous04/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringMiscellaneous04.class +--string-refine --unwind 30 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring From ccf841023104395719722775ab7fa3ddc047a81d Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:24:57 +0000 Subject: [PATCH 14/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20string=20startsWith=20and=20endsWith?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringStartEnd01/StringStartEnd01.class | Bin 0 -> 1082 bytes .../StringStartEnd01/StringStartEnd01.java | 31 ++++++++++++++++++ regression/strings/StringStartEnd01/test.desc | 8 +++++ .../StringStartEnd02/StringStartEnd02.class | Bin 0 -> 810 bytes .../StringStartEnd02/StringStartEnd02.java | 15 +++++++++ regression/strings/StringStartEnd02/test.desc | 8 +++++ .../StringStartEnd03/StringStartEnd03.class | Bin 0 -> 808 bytes .../StringStartEnd03/StringStartEnd03.java | 15 +++++++++ regression/strings/StringStartEnd03/test.desc | 8 +++++ 9 files changed, 85 insertions(+) create mode 100644 regression/strings/StringStartEnd01/StringStartEnd01.class create mode 100644 regression/strings/StringStartEnd01/StringStartEnd01.java create mode 100644 regression/strings/StringStartEnd01/test.desc create mode 100644 regression/strings/StringStartEnd02/StringStartEnd02.class create mode 100644 regression/strings/StringStartEnd02/StringStartEnd02.java create mode 100644 regression/strings/StringStartEnd02/test.desc create mode 100644 regression/strings/StringStartEnd03/StringStartEnd03.class create mode 100644 regression/strings/StringStartEnd03/StringStartEnd03.java create mode 100644 regression/strings/StringStartEnd03/test.desc diff --git a/regression/strings/StringStartEnd01/StringStartEnd01.class b/regression/strings/StringStartEnd01/StringStartEnd01.class new file mode 100644 index 0000000000000000000000000000000000000000..37d2596a6c101908d347169dcc750faae76deffd GIT binary patch literal 1082 zcmaJ=O-~bH5PshM?y}gj*a`>;idsNEt*C%R1DKc~Ca#ebPuuPW7t5CHE*?xg$!{>q z#l#CY6E!JDBF3v{{R8?ZJc0ABKr1#T?Y{HQ%ri63GrM1RKkfj?VO)oaE*0GxPHQ-$ zp-0164d-+SIG;cYSrxrHbaZLx)Avx#y?)=(H!42;5WD2a8 zqQLW)COELsitOT}+xBXluVR!zn=F?0i|bZ-EhxG-JzgsP2S$J(n)RLGkwIS3KpGi_ z)Y0lRV&sMqpI7AuH6+(6=fhpxh+RVD8n}p@fo2?MXsOn@aX@`G2+9F5rD{C&5`*A6 z2F8%1zDI{raoNBXT>WdLJB4Mp7?GZJRAA6UPAOdQqKCvXTSq7oJX6PitCs?r>pT0{ zWOexI5)mYn{i}SOfpD z510N2uQoqcL9zy2uQ{hK#MJM`D#=7##Yt!wp-*T64VWT(28~!i5_wX!Ou9ZHO`nqe zj1+xNBE6srZ%D8Ygxn_k3+ej}opj@0tg(k4C@R|N$M~OwZ~X+P=;V!=iBX!xt;nAiwWAn literal 0 HcmV?d00001 diff --git a/regression/strings/StringStartEnd01/StringStartEnd01.java b/regression/strings/StringStartEnd01/StringStartEnd01.java new file mode 100644 index 00000000000..c1bc4bac328 --- /dev/null +++ b/regression/strings/StringStartEnd01/StringStartEnd01.java @@ -0,0 +1,31 @@ +public class StringStartEnd01 +{ + public static void main(String[] args) + { + String[] strings = {"tested", "testing", "passed", "passing"}; + + int i=0; + for (String string : strings) + { + if (string.startsWith("te")) + ++i; + } + assert i==2; + + i=0; + for (String string : strings) + { + if (string.startsWith("ste", 2)) + ++i; + } + assert i==1; + + i=0; + for (String string : strings) + { + if (string.endsWith("ed")) + ++i; + } + assert i==2; + } +} diff --git a/regression/strings/StringStartEnd01/test.desc b/regression/strings/StringStartEnd01/test.desc new file mode 100644 index 00000000000..a5463d5b5ea --- /dev/null +++ b/regression/strings/StringStartEnd01/test.desc @@ -0,0 +1,8 @@ +KNOWNBUG +StringStartEnd01.class +--string-refine --unwind 30 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/StringStartEnd02/StringStartEnd02.class b/regression/strings/StringStartEnd02/StringStartEnd02.class new file mode 100644 index 0000000000000000000000000000000000000000..f7b535e4848e94bf5bb0cddd7f7684014d04f7a7 GIT binary patch literal 810 zcmZuvO-~b16g_Xg-gG*pWw6*nQNgMOEJZ?C2oeq8s^Ve{P+U#h2@aMinR)dW@F!$r z;)abIHGxDU?)@A730LBMqtHl5X5PDV-?{hPbKd;;{pA$EJZ3Enpu{m|;)aQvCT^J+ zH!)#B!R-`mlsWELuq5WLg?p%QOfn3Wy*TzG5p=_NHHf`t$8R&RZ3bg02m`UqpjIX~ z7_^mc+h@qugV0~^?KS=Ag#^>Vo)?4+!v-W#%@t7)?kvi}j4Qm>>u276 zg6EiGFqc}Lf6Xno+lyNM(?GV$|1G0}NUVkJ*|{0n(Z(PghTP@uG@|fhA?M{XAVNy* zOFc3rgCwO0-^MiV+sGovQ0Vu0axQ%>in&au6Y@6OpJAm#bCP{+KMo?leK8W5AbNB_?r&q9?r(sundJ&n1Vt*Cw1w6o z`WmC1(XLOOfPIueT%*-Uk_;*2F-)<9et-r}`xgHOrJ*{i+t3`%ZRn2fHVnsb>*}NF z_3G(@rY`7tJ+Hk-shZd49vVf%;m0uF!Z=XafzFQ3ettsg5V?}}4(YG38Yf79m+VTy zJ^_QL;*(w32AqR~IMny)k2wniD07UPxMJd}iEAb% zOiWr(a6JPX6^UJx=2S6?=^y*FOHF+{A0Ye&X$> zc#dfXbE)0=*W7Zuy{Ii72eMW1Zy6Ot$y(^o-J6viZ4AO;D4g$3BPJqF74MY|sJvt!oH!(rCH$a!n3L{biMJkvyh1MbZ z8mFDnu1_Cg$LOtFN1fCf(c3;qpCQ*~6gsX3b4)E(Vz8jj&M)CV)` zwc`a%UC@hqQG1Vat*GCcZ=kgR literal 0 HcmV?d00001 diff --git a/regression/strings/StringStartEnd03/StringStartEnd03.java b/regression/strings/StringStartEnd03/StringStartEnd03.java new file mode 100644 index 00000000000..79479f9535b --- /dev/null +++ b/regression/strings/StringStartEnd03/StringStartEnd03.java @@ -0,0 +1,15 @@ +public class StringStartEnd03 +{ + public static void main(String[] args) + { + String[] strings = {"tested", "testing", "passed", "passing"}; + + int i=0; + for (String string : strings) + { + if (string.endsWith("ed")) + ++i; + } + assert i==3; + } +} diff --git a/regression/strings/StringStartEnd03/test.desc b/regression/strings/StringStartEnd03/test.desc new file mode 100644 index 00000000000..e6d8c460709 --- /dev/null +++ b/regression/strings/StringStartEnd03/test.desc @@ -0,0 +1,8 @@ +KNOWNBUG +StringStartEnd03.class +--string-refine --unwind 15 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring From 846f168afca388414ab315eae1c5d1db83c39566 Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:25:48 +0000 Subject: [PATCH 15/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20string=20valueOf=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../StringValueOf01/StringValueOf01.class | Bin 0 -> 1565 bytes .../StringValueOf01/StringValueOf01.java | 41 ++++++++++++++++++ regression/strings/StringValueOf01/test.desc | 8 ++++ .../StringValueOf02/StringValueOf02.class | Bin 0 -> 749 bytes .../StringValueOf02/StringValueOf02.java | 9 ++++ regression/strings/StringValueOf02/test.desc | 8 ++++ .../StringValueOf03/StringValueOf03.class | Bin 0 -> 748 bytes .../StringValueOf03/StringValueOf03.java | 9 ++++ regression/strings/StringValueOf03/test.desc | 8 ++++ .../StringValueOf04/StringValueOf04.class | Bin 0 -> 688 bytes .../StringValueOf04/StringValueOf04.java | 9 ++++ regression/strings/StringValueOf04/test.desc | 8 ++++ .../StringValueOf05/StringValueOf05.class | Bin 0 -> 686 bytes .../StringValueOf05/StringValueOf05.java | 9 ++++ regression/strings/StringValueOf05/test.desc | 8 ++++ .../StringValueOf06/StringValueOf06.class | Bin 0 -> 687 bytes .../StringValueOf06/StringValueOf06.java | 9 ++++ regression/strings/StringValueOf06/test.desc | 8 ++++ .../StringValueOf07/StringValueOf07.class | Bin 0 -> 916 bytes .../StringValueOf07/StringValueOf07.java | 10 +++++ regression/strings/StringValueOf07/test.desc | 8 ++++ .../StringValueOf08/StringValueOf08.class | Bin 0 -> 694 bytes .../StringValueOf08/StringValueOf08.java | 9 ++++ regression/strings/StringValueOf08/test.desc | 8 ++++ .../StringValueOf09/StringValueOf09.class | Bin 0 -> 702 bytes .../StringValueOf09/StringValueOf09.java | 9 ++++ regression/strings/StringValueOf09/test.desc | 8 ++++ .../StringValueOf10/StringValueOf10.class | Bin 0 -> 722 bytes .../StringValueOf10/StringValueOf10.java | 9 ++++ regression/strings/StringValueOf10/test.desc | 8 ++++ 30 files changed, 203 insertions(+) create mode 100644 regression/strings/StringValueOf01/StringValueOf01.class create mode 100644 regression/strings/StringValueOf01/StringValueOf01.java create mode 100644 regression/strings/StringValueOf01/test.desc create mode 100644 regression/strings/StringValueOf02/StringValueOf02.class create mode 100644 regression/strings/StringValueOf02/StringValueOf02.java create mode 100644 regression/strings/StringValueOf02/test.desc create mode 100644 regression/strings/StringValueOf03/StringValueOf03.class create mode 100644 regression/strings/StringValueOf03/StringValueOf03.java create mode 100644 regression/strings/StringValueOf03/test.desc create mode 100644 regression/strings/StringValueOf04/StringValueOf04.class create mode 100644 regression/strings/StringValueOf04/StringValueOf04.java create mode 100644 regression/strings/StringValueOf04/test.desc create mode 100644 regression/strings/StringValueOf05/StringValueOf05.class create mode 100644 regression/strings/StringValueOf05/StringValueOf05.java create mode 100644 regression/strings/StringValueOf05/test.desc create mode 100644 regression/strings/StringValueOf06/StringValueOf06.class create mode 100644 regression/strings/StringValueOf06/StringValueOf06.java create mode 100644 regression/strings/StringValueOf06/test.desc create mode 100644 regression/strings/StringValueOf07/StringValueOf07.class create mode 100644 regression/strings/StringValueOf07/StringValueOf07.java create mode 100644 regression/strings/StringValueOf07/test.desc create mode 100644 regression/strings/StringValueOf08/StringValueOf08.class create mode 100644 regression/strings/StringValueOf08/StringValueOf08.java create mode 100644 regression/strings/StringValueOf08/test.desc create mode 100644 regression/strings/StringValueOf09/StringValueOf09.class create mode 100644 regression/strings/StringValueOf09/StringValueOf09.java create mode 100644 regression/strings/StringValueOf09/test.desc create mode 100644 regression/strings/StringValueOf10/StringValueOf10.class create mode 100644 regression/strings/StringValueOf10/StringValueOf10.java create mode 100644 regression/strings/StringValueOf10/test.desc diff --git a/regression/strings/StringValueOf01/StringValueOf01.class b/regression/strings/StringValueOf01/StringValueOf01.class new file mode 100644 index 0000000000000000000000000000000000000000..8103d7fb901728c98fd932908491f85aef3bfe16 GIT binary patch literal 1565 zcmZ`(TXzdl6#h;!lQWrwP9tekq!+4Er57o!-lS5cRV|tzEsIGrVThDm`Wrm?0e$ht zT9y}=RkN^o@nG>Yc=98#PkNgnomuPbea^SN< z83hSJCls6&bduwoiu0J_m}c11u9r$iv1~3EN)u*D&*Y6P16yG5jF<(pJjURTc3x$W z63bbGp>D=37_*fJ8KamK!UR0f%>qM1baCdMzM}W!^}?N=`Et=L+!+>%yXMRK(*2A2 z!>T;T1&$eV&2f=I8ClA2cv0t>-tyqe8rf{_4aiO%YGcdLGo8NN@dda zV-|CMw4#mdWX)VIL&APs!exf=b|mAQ>76YWmy1H_3Z+ECf}LlOb9%l+db3DU-bulv zh#3$JMepnD-TK7QHBvs_eL}F;sYbC_cPthYyEN72pQt$&{8+>d25mc@xy(IdsZ52h zQ7#78V!|Q4Zjphnte2u%=S1iKm8MvXM-@tiAr!U2>+Xg-siEQMVq$8lrfw*@u)}$6 zU!mwucBXf*Gr7b0M9uS#S}EAF+88e?`F3Fwd75OZPu3`zMI*b_cN)KPg#a4k1+>v^ zYM~3qw6K^Q;@n_ju4rwiU4$qjDj#_V_DTri5Url-A%hnkI7~c=y1bC+DuUhCl#g=S ztz}bbNi$PvS<9u;9@U*MJ<526+(jDJ8&% z)GiCkknc6Ts|Ypu0_qxktMGk*Km887K6iOM7Ixe4Iw!v0f@VYOooK{Dz=rN|q9Msb z&<2N`aD!~2!3H-v;YMyDY=fJea9FXh*9Px%!cD4${Wh38VbKLwwF?F86RklH^`j4* zUQh*t)RR%D7>5s&)Q@TGrYE2dcTtar2;eb-c!Cg~p%E_;#ux0xce3+?TKx;n%!O9w zr6;6~o|Y)uSsWeg91gQvh|&)l4DTN@rgC(09AS(}E;mOP$5Egq5@{A6g>h_ag8HkY k0@Md0YiM2tm!3m%zkzofgc5PcgvUdM5pZJL%8D4zwAwh)AJYlT1oE=}nnxRTqG6K^UP*8zX@&fmx% z;0#DD0t9#d6Np)dHhf%WcW36kdGq%B&re?gv~kyhg(V9Yaj66omrX3I#}$sN77Q$L zT(fW;H#lxG%&&M!BI7g|Mah#O@%o|k8Q30!u^B```jA0uGL3FU8fHS?+8@$~1UgiB9D;&2N%*{dgo8Rh< zvUnh$1&XaULGF5CCU=JSAKX)%HfAtOFdMgV$3_`8L&*<@!(pG=Y&6hhs86RqK3nN& z9FJlW{SPU}s*N?QGl(f@r++91DMMku^H+X?W#GpXP5G*w=Ksr*W%70Ag$ct#u;fJAD~S+&$duJMHK8uYS#<-$oemIOqV+V literal 0 HcmV?d00001 diff --git a/regression/strings/StringValueOf02/StringValueOf02.java b/regression/strings/StringValueOf02/StringValueOf02.java new file mode 100644 index 00000000000..a730af26c02 --- /dev/null +++ b/regression/strings/StringValueOf02/StringValueOf02.java @@ -0,0 +1,9 @@ +public class StringValueOf02 +{ + public static void main(String[] args) + { + char[] charArray = {'d', 'i', 'f', 'f', 'b', 'l', 'u', 'e'}; + String tmp=String.valueOf(charArray); + assert tmp.equals("difffblue"); + } +} diff --git a/regression/strings/StringValueOf02/test.desc b/regression/strings/StringValueOf02/test.desc new file mode 100644 index 00000000000..00835385bc8 --- /dev/null +++ b/regression/strings/StringValueOf02/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringValueOf02.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringValueOf03/StringValueOf03.class b/regression/strings/StringValueOf03/StringValueOf03.class new file mode 100644 index 0000000000000000000000000000000000000000..886aedc6b1d40d822d3bebede947ebfa4dabde7d GIT binary patch literal 748 zcmZWm%Wl&^6g?9=9>;N;X_}T4D9-{(TL=;rn^p)EK&q6qi{MIbR(3L}TwDkI=nwE0 z`2p5|)FMEz=bu2_Nod1kb7$s0&N=tY_n)7>0@%P^3l^3vT*RdUOk6gxtR7c5u39j# z#Bt5Sb==^%$uPg-C5epFU>GG&gT(Vg*=Jz;48~Rv1?eLOtybS-(3``)WGJ$VQPW3Lf<(Ltk=#zAzjsRm~{sn>hi_Fj$qIaWAsF_>Gu@Hf8I z8D?=$J`WUHWiq+vg_+zP+<$OSVcM9%ERET?jXO4qu!(ly`=N~*>I~H>@sqP{p2hJn zCcXdQaje={!#abQ4(p`|HdGbGo^v%XA%SoY6FlT~R(1+sjfzR0AH1emC*mFcE|?8Gd^61|q`WOU|N zPr=@)MhJ?=ILT1J9LjW8t#6>yFt8)cFL_rJeaF>B;JA4)a9l$LE_}x|Md-M~5E(@- zq|;h6jE~5*-$NUrvR>9tkRPG=8HRfb{!MY_#++rsCn0DM`$KTFN%}lxieNv`=BRKi pP-^j9`^H!#FjqEDP#A&hZ=q`+piME)_E0!^M!zEmC*nI literal 0 HcmV?d00001 diff --git a/regression/strings/StringValueOf03/StringValueOf03.java b/regression/strings/StringValueOf03/StringValueOf03.java new file mode 100644 index 00000000000..0c51518b300 --- /dev/null +++ b/regression/strings/StringValueOf03/StringValueOf03.java @@ -0,0 +1,9 @@ +public class StringValueOf03 +{ + public static void main(String[] args) + { + char[] charArray = {'d', 'i', 'f', 'f', 'b', 'l', 'u', 'e'}; + String tmp=String.valueOf(charArray, 3, 3); + assert tmp.equals("fbbl"); + } +} diff --git a/regression/strings/StringValueOf03/test.desc b/regression/strings/StringValueOf03/test.desc new file mode 100644 index 00000000000..19921a8e98f --- /dev/null +++ b/regression/strings/StringValueOf03/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringValueOf03.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringValueOf04/StringValueOf04.class b/regression/strings/StringValueOf04/StringValueOf04.class new file mode 100644 index 0000000000000000000000000000000000000000..5a0d670146c1cc44317c411ef7e8ef77c246899c GIT binary patch literal 688 zcmZWmT~8B16g{`Q-D#JFmQt{a6j6j0jrha^bh!~ zCSWwtcmI>dJ6oZCWRjWtdG5JqzW@CE6+jF3eE6vOxQ-h|6tGypP3tTP)O~oU2`u}# zg%yF@gt=82$I2vn7{yO@EPJ6E5U5M=+B(w7BZAXt9uVB^;Xn~eJ33M?(&L^o`?i=9 z$5Kaxg~schBY7q_Lm3@zb`qnb!!6r5-AQEs?XEn@>ILo)3hjRQ8{F>+x&k$7D=6^GK_7(AL%jVR+CjMO$Kd;EHw)?P_Z^@ za7C8&Nm5R*&RwkVkNNzKRIb@o*>b=dVutS$drSNhzxj;|(0f~mGT&YnBor}=3fs2y zC34&hEIaMRPsr_lfHOk%e#JdUeuSwn@LpX&e6t|A45R{=?L2!P1fM!{nd3+i^aFJg psB&Qbib^Y+3Cvas=O~UK+;?!Dk8mc4m$WPj;|7l{`GsuYwO{$qh?F%VLI@Z{1QawuOFY1dlm!*^1ab&P6?mE?BQ>yWU_baV`2(KS zDzLN)?))bxdp1H)FZ0pe@Ad09bA9{s62LNExo}Z&F^R`{=P6LXmscpfOjJK@9?CPhs$Bm0xt=bLCf{KIo^k1H)N&%kO@>h)UZe> z4nW(jL)DJ|3iV+Gan_eX7_T;J|Ifw_snbOIktukP?o+PT*uuh~QNw4S*`wPa=ms++ qQ0Bn+y_V&)DKJ{fog?3au)n~zzQY7y# literal 0 HcmV?d00001 diff --git a/regression/strings/StringValueOf05/StringValueOf05.java b/regression/strings/StringValueOf05/StringValueOf05.java new file mode 100644 index 00000000000..03854f575b0 --- /dev/null +++ b/regression/strings/StringValueOf05/StringValueOf05.java @@ -0,0 +1,9 @@ +public class StringValueOf05 +{ + public static void main(String[] args) + { + char characterValue = 'T'; + String tmp=String.valueOf(characterValue); + assert tmp.equals("A"); + } +} diff --git a/regression/strings/StringValueOf05/test.desc b/regression/strings/StringValueOf05/test.desc new file mode 100644 index 00000000000..ccb5b3dc440 --- /dev/null +++ b/regression/strings/StringValueOf05/test.desc @@ -0,0 +1,8 @@ +KNOWNBUG +StringValueOf05.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringValueOf06/StringValueOf06.class b/regression/strings/StringValueOf06/StringValueOf06.class new file mode 100644 index 0000000000000000000000000000000000000000..e9a8065210a235df735a15b77a18eaf94156a2fd GIT binary patch literal 687 zcmZWnT~8B16g_u$yVEWUEu~-;5m3+;3HU(dfre;M5)+Vz8WP}X+74uJ+3J4qWBLbp zMiVfa=)3<(!=0^Am6!Rr_nvdlJu^RlfBg<%1y4PAsCu}Idj;e%na6!|nG$&5!9`VI z+QSTH1s)Q{=42eJDAC<8ex+mC3RH(c`vkY4L!GP>>{@-7;B0g|ics9rp?aI1v{dxY z6m#N4>X0x|JJ>pwr*b)v;n8w4iFA0hW`M)ZM7G~=%MV$-z#~Gw(GLEQd(CbdwbiCJ zRFyt#R|cutIehkf$q@P&#t6fF%wgWg5PX8Qy6WRGo)D^oo-eNlc^yUFh^79=CQ$QH z#{!`=0PVDnRXh17)Q1toXSjSg0i!7M z*_1Y6F&LOBiN@p?Slgdq_fT0ZI~U0HF!T-X-X+8j!(wGDWjK7!G0J5b{7ZNp<46JY t3)3V};lTKfmX)k2Fj~%EpwNSG&fwUeVGkIubs3f%EdPa3Kan-Oa|N)_hcf^G literal 0 HcmV?d00001 diff --git a/regression/strings/StringValueOf06/StringValueOf06.java b/regression/strings/StringValueOf06/StringValueOf06.java new file mode 100644 index 00000000000..b13a3899f0f --- /dev/null +++ b/regression/strings/StringValueOf06/StringValueOf06.java @@ -0,0 +1,9 @@ +public class StringValueOf06 +{ + public static void main(String[] args) + { + int integerValue = 7; + String tmp=String.valueOf(integerValue); + assert tmp.equals("77"); + } +} diff --git a/regression/strings/StringValueOf06/test.desc b/regression/strings/StringValueOf06/test.desc new file mode 100644 index 00000000000..c78afa98f2f --- /dev/null +++ b/regression/strings/StringValueOf06/test.desc @@ -0,0 +1,8 @@ +KNOWNBUG +StringValueOf06.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringValueOf07/StringValueOf07.class b/regression/strings/StringValueOf07/StringValueOf07.class new file mode 100644 index 0000000000000000000000000000000000000000..36e9401884cee02e9c9682975e101417a17d58e4 GIT binary patch literal 916 zcmZWoZBr6a6n-u&yRfW+h(s?WmKInF7G?!CI#wSV(`ImNv`-6MnYCrt_Qje03V)!_ z*$g%{)%Si!f1{>z7ZJ(*aPQf3pYxn^pL6c7zh8d*Y8>#UNAwz&a8JQ~jRacOki-Oowp1Q|8XjPUAv=s+8%XfnacqY!`ClCh z9%^`m$0G^*m{HdU*W(>h%=SHoslFbDU3yJoc!cMAr^=ul_3uZB!pq`C(WogwX`_ME zkV8SU&rmB|3_34@Ns7MMflk>`1k(HntU?Mf%L!t{s`Uolf8L=VjpkTogK}cH_*SZ=c Gz4i~F)WtRc literal 0 HcmV?d00001 diff --git a/regression/strings/StringValueOf07/StringValueOf07.java b/regression/strings/StringValueOf07/StringValueOf07.java new file mode 100644 index 00000000000..c4c44435d22 --- /dev/null +++ b/regression/strings/StringValueOf07/StringValueOf07.java @@ -0,0 +1,10 @@ +public class StringValueOf07 +{ + public static void main(String[] args) + { + long longValue = 10000000000L; + System.out.printf("long = %s\n", String.valueOf(longValue)); + String tmp=String.valueOf(longValue); + assert tmp.equals("100000000000"); + } +} diff --git a/regression/strings/StringValueOf07/test.desc b/regression/strings/StringValueOf07/test.desc new file mode 100644 index 00000000000..7b19c4ff67b --- /dev/null +++ b/regression/strings/StringValueOf07/test.desc @@ -0,0 +1,8 @@ +KNOWNBUG +StringValueOf07.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringValueOf08/StringValueOf08.class b/regression/strings/StringValueOf08/StringValueOf08.class new file mode 100644 index 0000000000000000000000000000000000000000..356ddbbb9d4b840183665cc3543a33134f8f4808 GIT binary patch literal 694 zcmZWnT~8BH5IwWq_I8)WmZe}pu@z8TBtQ%%CJ=)Gc>;N;ArYQ#+bg-aY;`~QG5rHP zqX`&I^xglYaqbqVA1`y~&dfP8bMF1|>&rI)t5|d~f+>5W4!D@c9S08X7BOQk_XKJ# z1f~S)F79JiV2&_8FXLE6iSC8*mX2jRP+bBY5DM!$)X8%~uF>2l*qgnsB9wM?s9vQf zZ56#X#hf^iIwVXs4tI{_say_Zc(mL~A{`#B8Q^Fuk)3zD@_kk>Fi$A1cY-T&x7ACd zj@s6SsxpA>%OF*IZ&#iz8A1=YP-2*e2YBeg!zlNBvh;Mt!y_~Z)nV5c*Q>mYqF%(q z{=+BG^ss=(gz^xy*FILANIyZ$FV_V3A z#9$xe?3>aSECvI0-`bk{jNI-=*nLzM{rm+AeT;mCcyo#3cf(?3EIw@Z^NcE>$X}(# yw!#qy^b<8pV1fgaH?yo}O@T4rxq#b;u+L!UKEWO`Ue9G%^02%OGyUzXVf8mK-iSK@ literal 0 HcmV?d00001 diff --git a/regression/strings/StringValueOf08/StringValueOf08.java b/regression/strings/StringValueOf08/StringValueOf08.java new file mode 100644 index 00000000000..539c60e5a9f --- /dev/null +++ b/regression/strings/StringValueOf08/StringValueOf08.java @@ -0,0 +1,9 @@ +public class StringValueOf08 +{ + public static void main(String[] args) + { + float floatValue = 2.5f; + String tmp=String.valueOf(floatValue); + assert tmp.equals("2.50"); + } +} diff --git a/regression/strings/StringValueOf08/test.desc b/regression/strings/StringValueOf08/test.desc new file mode 100644 index 00000000000..a7d90b1b9ef --- /dev/null +++ b/regression/strings/StringValueOf08/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringValueOf08.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/strings/StringValueOf09/StringValueOf09.class b/regression/strings/StringValueOf09/StringValueOf09.class new file mode 100644 index 0000000000000000000000000000000000000000..e852bce13a4efeac1af59da4f7f6ac6010aa2498 GIT binary patch literal 702 zcmZWnT~8B16g{`y-D#J_mQt{yC{>ge1x(6|ftVW5_<-YC}JM;bL=TiWySaRWE#%VU+zCP`L`{?2_uH@lj zHixU`a!p{)MGi9pRTtNBLtvgTIWMC~g|Y4h(WZ`M+gDuz?Gv1J9q9NzAzQ2O5v+|~ zR}l(ZI#AomQCo$(CYb|AQU`?T+Ow@g*_SK63=URWaj1iXH3J-P#j^9_iF}#n3*02+ z);s=ha<|n>!j5{R4OMvv+mn8xcAnq8w`>SK6i{TChg(?iFpdiZ(P%6;czLLyPN<9u zKRD~=VHoy8*82~oz@mrSxI-w8Ks)V2)rtRd4PjiVKNLfls%_T)?~v!DUM13xOu`@G zA>~?~2U!>u+VFYWJgcsXbf~)LVtGVy!T}!jKC1j^9zQ7+E2djMWx*^cvYp`DEbqj- zy?6q8XA)6j>!eOX9+N2Z*`)3w1B>@+8JWimpI~jjhdn@fspK3(3^4Wuxu++{e>F6j zl%|vdY_<+l@t@%@GsV$7=m+Mq0@LiccrIo&tqM$(++&OlAgnjAvL9fN7|(t3&iEl0tMVnGpGK+uFYh|!=t6?mwU08iU?C5OjV@AmjH{R2L$ z2^dZE-T$O<_6ih@FSE0=^L_Kp%>MlS^*ewythgv)+QDrXcQ8{#5qBNb&1F_#&V|6V zz&#iDF)#3dFflKaM8!JjN6CvIk)2TW2y{RwYy?rDpAzzo<{rV??DrI*+zKMKlb&=` z{K_Qr!-)(c!c^n1bu3TiYABSY}F zW7ho-ufURrWjrEOMxfo!vFhr-LPHoqoDLNc78=+393s}6*FqPq^8nTRRE7y*@_z`P zaCuaDGvqb!5PK>KV%57+&$H7hKkyC?Fvr_0@s_DlGtIM?2bs~Zt?+GzPvX;FJO_O= zi5O>F$b!UR9~11G)Yr%{7?|~Qt)(x>Z-0U{Ky}%-&rlek^bKPF9L^8JlFL|pSnS)3 zD!}1yRA*b|ND1@{b%9BNDGuGdQnQwo1;+j28QcMc^#NA?GprHkr82`~Bj-Ic`fFLq GTYmttSCRDq literal 0 HcmV?d00001 diff --git a/regression/strings/StringValueOf10/StringValueOf10.java b/regression/strings/StringValueOf10/StringValueOf10.java new file mode 100644 index 00000000000..044586124a7 --- /dev/null +++ b/regression/strings/StringValueOf10/StringValueOf10.java @@ -0,0 +1,9 @@ +public class StringValueOf10 +{ + public static void main(String[] args) + { + Object objectRef = "test"; // assign string to an Object reference + String tmp=String.valueOf(objectRef); + assert tmp.equals("tesst"); + } +} diff --git a/regression/strings/StringValueOf10/test.desc b/regression/strings/StringValueOf10/test.desc new file mode 100644 index 00000000000..5de3d5aade7 --- /dev/null +++ b/regression/strings/StringValueOf10/test.desc @@ -0,0 +1,8 @@ +FUTURE +StringValueOf10.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring From 47dbc2ed91d6391b7c2dd20994e3eb9d0f7d33c9 Mon Sep 17 00:00:00 2001 From: Lucas Cordeiro Date: Wed, 22 Feb 2017 14:26:42 +0000 Subject: [PATCH 16/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20string=20class=20substring=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- regression/strings/SubString01/SubString01.class | Bin 0 -> 829 bytes regression/strings/SubString01/SubString01.java | 13 +++++++++++++ regression/strings/SubString01/test.desc | 8 ++++++++ regression/strings/SubString02/SubString02.class | Bin 0 -> 744 bytes regression/strings/SubString02/SubString02.java | 9 +++++++++ regression/strings/SubString02/test.desc | 8 ++++++++ regression/strings/SubString03/SubString03.class | Bin 0 -> 734 bytes regression/strings/SubString03/SubString03.java | 9 +++++++++ regression/strings/SubString03/test.desc | 8 ++++++++ 9 files changed, 55 insertions(+) create mode 100644 regression/strings/SubString01/SubString01.class create mode 100644 regression/strings/SubString01/SubString01.java create mode 100644 regression/strings/SubString01/test.desc create mode 100644 regression/strings/SubString02/SubString02.class create mode 100644 regression/strings/SubString02/SubString02.java create mode 100644 regression/strings/SubString02/test.desc create mode 100644 regression/strings/SubString03/SubString03.class create mode 100644 regression/strings/SubString03/SubString03.java create mode 100644 regression/strings/SubString03/test.desc diff --git a/regression/strings/SubString01/SubString01.class b/regression/strings/SubString01/SubString01.class new file mode 100644 index 0000000000000000000000000000000000000000..861bf6905d377ed4734838615a71b208ff4870df GIT binary patch literal 829 zcmZuvT~8B16g|_g-EOybTS~1UA`044q+oc17!frgDf&=D0zS=dhh}iQtNY=zzoUP^ zXEiB_Ci?Dw(s*YpZ4D-yosVQkHhm$g3&0zXjEn^cfW!cdqoqoHkL3)^II8vN2e7Y-3; zuEypW@?mU;NedX}8;8xSouU4UcQJQEMVNudqPtBRK&^53|H#tR!+}fVBWh2CG7!B< zJ=F6kCV*yliWPbdMS3O7s;kz}E)BAcGW{!bTB4QFnq9vD`=p4Nqkk^Bq+(FTJna?r z1BIq(eNstvT2^(0^wDQzhNx~-vLob%D13u>4zP0`_5|Mu>^jFZGJA)3;1`ePVnkaR`(vg%Qjlw9H3j(qE97ieDC?gtADP Mk5#ERlH3b_0AX3L1ONa4 literal 0 HcmV?d00001 diff --git a/regression/strings/SubString01/SubString01.java b/regression/strings/SubString01/SubString01.java new file mode 100644 index 00000000000..c99db9b7308 --- /dev/null +++ b/regression/strings/SubString01/SubString01.java @@ -0,0 +1,13 @@ +public class SubString01 +{ + public static void main(String[] args) + { + String letters = "automatictestcasegenerationatdiffblue"; + + String tmp=letters.substring(20); + assert tmp.equals("erationatdiffblue"); + + tmp=letters.substring(9, 13); + assert tmp.equals("test"); + } +} diff --git a/regression/strings/SubString01/test.desc b/regression/strings/SubString01/test.desc new file mode 100644 index 00000000000..8eea70cf458 --- /dev/null +++ b/regression/strings/SubString01/test.desc @@ -0,0 +1,8 @@ +KNOWNBUG +SubString01.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/SubString02/SubString02.class b/regression/strings/SubString02/SubString02.class new file mode 100644 index 0000000000000000000000000000000000000000..d758b7baf0b6929136ac7bc16c5f232333cb203d GIT binary patch literal 744 zcmZWn!EVz)5Ph3Cv17X=b<>gp1yWi_+CmZPtrY?lkdV@H2m-Y|t?g~J#j(L&^D+4W z&VZCkAit?(=psgg;YJ(C&tBM~yNLx$>(jHPZKJ8H@dV z=!^8V22)_jWz4Y9IqIG8k9;%Y@nEyBQW+1nb>d84@!;Jae_!BDtTI?TLG+K@?k9N~ zh!;{*HTt!;=^6+9jcvMZEVh5otPu+Sur1NIwj6Z7 zU}4e1vV#?@T4*!Owt1F`RLLaHp2>{+kq8;s2}5O1#!@|IFgo4W4Ca0k3Wi2c#^NX+ z`XYU$lPNIdGG0s4}3e~@nE~JQW+0+bz!})c<}a+zbo=BtTEVoLG%~g=_h#_ zh!;{rdHvj$vB_ zMV+Cn1SPxZpv%yjQhRza@AEWGQij@5|EJMea@qdVZL)EJVD*NM%!jy zOOHyH0j8Cr)1%iC-Hh(?#yQw0oroDaD}|FtqlsCvb?Pyd8g#dtrQW7j_3C37ho51N zFt^n#k5L(+_6^qYIqV-AsZ<~}VUk^@$_f#%unHS< Date: Wed, 22 Feb 2017 14:27:30 +0000 Subject: [PATCH 17/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20StringTokenizer=20object=20used=20to=20tokenize=20strings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../strings/TokenTest01/TokenTest01.class | Bin 0 -> 1409 bytes .../strings/TokenTest01/TokenTest01.java | 24 ++++++++++++++++++ regression/strings/TokenTest01/test.desc | 8 ++++++ .../strings/TokenTest02/TokenTest02.class | Bin 0 -> 870 bytes .../strings/TokenTest02/TokenTest02.java | 17 +++++++++++++ regression/strings/TokenTest02/test.desc | 8 ++++++ 6 files changed, 57 insertions(+) create mode 100644 regression/strings/TokenTest01/TokenTest01.class create mode 100644 regression/strings/TokenTest01/TokenTest01.java create mode 100644 regression/strings/TokenTest01/test.desc create mode 100644 regression/strings/TokenTest02/TokenTest02.class create mode 100644 regression/strings/TokenTest02/TokenTest02.java create mode 100644 regression/strings/TokenTest02/test.desc diff --git a/regression/strings/TokenTest01/TokenTest01.class b/regression/strings/TokenTest01/TokenTest01.class new file mode 100644 index 0000000000000000000000000000000000000000..70e112fbafba43a04d1e0f208ed307c70c3dedac GIT binary patch literal 1409 zcmZuxOLNm!6#i}`>&l8kVh2M^5)cI%2Ld4v0@!H^gaDy=bjBGvz)G<%K_E*(l9^%8 z8ur=1uwm0p>5O4uNY^l|;P23;=gRRTj5qi7o%5Z?ccjn%z262fja362$8;Rmal*jQ z7)c_BQ5`2aP8k@(X#;04orH9M*W^B(<;Fx95XG`ubzftt7K}lS5BwOE_|4?{q zB8<*XoRNGc4q|}euw9M(iXAy6D>Fh}y(2nB(}>#3fv27^x>} z`S&d0ii+@}FmIhG8*BH470EcEWd|Z}P}o-LtLqO$DdMIoG zU2gPkAqf1y#0@MmB%5iPxQXAWJ2G3^WWEeWd&b>urE)BpSjNhpOzKS}jXHFeArWr6 z4pEQfI`qAxM_ZA_Ct)Niq^(~iicFos@yCBB*&>Q7>`H+l)v9*Ui^PTq82Dq`t%}uq zQt`#nw$Qs4gQN6Cary#T-+&wgIw@dsE@{ouZJ2gO zd*b9r%r zEKl#Np?3@G4fkR7;Ybw~#`BG@es`|HOWLqV9en>??T;6GH*~ zUrccv<~Xtg6P)(?jnRow%fDlS9)^a7b|{qEg2`Ej)f8wtRsu++`)k<01+Kn^s{9S3 Vm2*QZ88?A0^OBVGC|$bn)Bmw>Ko|f3 literal 0 HcmV?d00001 diff --git a/regression/strings/TokenTest01/TokenTest01.java b/regression/strings/TokenTest01/TokenTest01.java new file mode 100644 index 00000000000..2180bc94c1d --- /dev/null +++ b/regression/strings/TokenTest01/TokenTest01.java @@ -0,0 +1,24 @@ +import java.util.StringTokenizer; + +public class TokenTest01 +{ + public static void main(String[] args) + { + String sentence = "automatic test case generation"; + String[] tokens = sentence.split(" "); + System.out.printf("Number of elements: %d\nThe tokens are:\n", + tokens.length); + assert tokens.length==4; + + int i=0; + for (String token : tokens) + { + System.out.println(token); + if (i==0) assert token.equals("automatic"); + else if (i==1) assert token.equals("test"); + else if (i==2) assert token.equals("case"); + else if (i==3) assert token.equals("generation"); + ++i; + } + } +} diff --git a/regression/strings/TokenTest01/test.desc b/regression/strings/TokenTest01/test.desc new file mode 100644 index 00000000000..02a11e8e392 --- /dev/null +++ b/regression/strings/TokenTest01/test.desc @@ -0,0 +1,8 @@ +FUTURE +TokenTest01.class +--string-refine --unwind 30 +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/TokenTest02/TokenTest02.class b/regression/strings/TokenTest02/TokenTest02.class new file mode 100644 index 0000000000000000000000000000000000000000..09f38782aa153f91c4836a3c3b5a75cd604e2f76 GIT binary patch literal 870 zcmZuvO-~b16g{u=@ut&3O0m#d!Gb8IAgzS3076uRjYSu2OvKf6`qB)vGdMH#7w{{( zGHzI_5fV*s@5Vo5toId5G3jF7y!Y<8=bm%#`}ybFC4hB2Hen%W;I4rg6SKG%hl#v_ zIeD1pxNpKhj$^^Z13ctdWSCsA!%zf~>wDpIH?-?5(O_VQ4Ena~xzP@TQdoM;pzit& z!7yHNJ@K;Bu8W{1!4zoQuE#J{cw0HL-`k~@?KMl)C~&>zmP{P0Mz(W&V4w8y90iUg z24mZ4{o^;QekX9mzAM?1HUC(6H4#STwN=SyVH`<@S-TVYZ98(Ed_=*#V}~N&6rKp^ z&Zqh;PrMe2Shg^RTMP+`4#E~z@Q5KZ6!>)DdM^n4fY3MUa;#b?p-gIq39sr$!ilJ1 zBW(T$yt2-qg(oeS5*7<1`ZAJ47wWVCo$BnY_e)lc^()TzxjD%*NU{{2pcguZXC!)$_Af|sn$RUEJxqghOmR%p z%H&5DexpbiJxW)HF-kCyxpuqWw*^e3%yT5V;OZGv Date: Wed, 22 Feb 2017 14:28:21 +0000 Subject: [PATCH 18/59] =?UTF-8?q?=C2=A0added=20test=20cases=20related=20to?= =?UTF-8?q?=20validate=20data=20from=20user=20using=20the=20ValidateInput?= =?UTF-8?q?=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lucas Cordeiro --- .../strings/Validate01/Validate01.class | Bin 0 -> 1415 bytes regression/strings/Validate01/Validate01.java | 30 ++++++++++++++ .../strings/Validate01/ValidateInput01.class | Bin 0 -> 880 bytes .../strings/Validate01/ValidateInput01.java | 38 ++++++++++++++++++ regression/strings/Validate01/test.desc | 8 ++++ .../strings/Validate02/Validate02.class | Bin 0 -> 1187 bytes regression/strings/Validate02/Validate02.java | 22 ++++++++++ .../strings/Validate02/ValidateInput02.class | Bin 0 -> 880 bytes .../strings/Validate02/ValidateInput02.java | 38 ++++++++++++++++++ regression/strings/Validate02/test.desc | 8 ++++ 10 files changed, 144 insertions(+) create mode 100644 regression/strings/Validate01/Validate01.class create mode 100644 regression/strings/Validate01/Validate01.java create mode 100644 regression/strings/Validate01/ValidateInput01.class create mode 100644 regression/strings/Validate01/ValidateInput01.java create mode 100644 regression/strings/Validate01/test.desc create mode 100644 regression/strings/Validate02/Validate02.class create mode 100644 regression/strings/Validate02/Validate02.java create mode 100644 regression/strings/Validate02/ValidateInput02.class create mode 100644 regression/strings/Validate02/ValidateInput02.java create mode 100644 regression/strings/Validate02/test.desc diff --git a/regression/strings/Validate01/Validate01.class b/regression/strings/Validate01/Validate01.class new file mode 100644 index 0000000000000000000000000000000000000000..a5a99f5efc122f3706a204ede0e0d0bfb70352c9 GIT binary patch literal 1415 zcmZuxQBxaL6#gzGxtGmCl7&#x+IH2dDYOA>C?#NROiN1*2?}D8T4$DIEnAY^%U06~^Hkq^ce)rsSzw@1Q_wRpx{}VtSUn#hNX@MDm zYXa8=assmga{}`UKE#a?WRT}rP!PwoL~cs6ID%VP5-2EG#)?EflIFHF9}C=(@1npb z0ws>S3hrT*<37Xq6~psP*S8$oyK8yIPTOoTum(eH#j-8`Hp6iC>NZ29< zO0TnHx?9qj7CMGyGfZY5m7f~VjM=tfKbhV1UCVy5EH{pB`bKka-RK7X91l3w7{p4m zeH>rebb4;nT(xAh#J174T83}V&F5q|6_;?CIMix2vh{kML2EP``WiiYksf{F=B*`S zTm9}E$0h3Vqk*?;xfCu|t=(8GuF`ok`TU}MI3B9_6lE1};UdG-fO9bv;-2d|u8MW( zR6&`es$v755xF({nWU#1t(I$g9>?b@HnFAR3+cNp&6g-MBtysVt*+iA;Z)QlJ`v*G zUB@^*(o>E#%dfgT)n6%9P1@B`A-ou_8gr#haY{wc?! zio7B4nmlc8o*@b4(XQ8o>5F{ie%_pHbU1#2o;Y+IeqHB=bIg>oYNzc z>7$^QGrK|U;S(j(=qwZYAfMAP1Mf#gLi4H(?SJ95VZEIHdNMz*R@DRixwhUtPs_BA*P7}pXp=d z0I8Qy4)D_-h}U03{p(sEqapZh2wv}F>;Pjgk5z-kuJ&U&`=4CXbv*ds3wllXz+{D>+1OgnzTc^s0o&q>NF6g>;^F9i@B?{U2U z|35I1N~blA)7c-Klp!DJ4WzWpE1W+7j~pU0{2P=3`LHDNkSK=KJF;-uAh)ak0T3ZI AF#rGn literal 0 HcmV?d00001 diff --git a/regression/strings/Validate01/Validate01.java b/regression/strings/Validate01/Validate01.java new file mode 100644 index 00000000000..3443cd30588 --- /dev/null +++ b/regression/strings/Validate01/Validate01.java @@ -0,0 +1,30 @@ +public class Validate01 +{ + public static void main(String[] args) + { + String firstName = "XXX"; + String lastName = "YYY"; + String address = "ZZZ IIII AAAA 5689"; + String city = "Oxford"; + String state = "Oxfordshire"; + String zip = "OX37AF"; + String phone = "+4477777"; + + if (!ValidateInput01.validateFirstName(firstName)) + assert false; + else if (!ValidateInput01.validateLastName(lastName)) + assert false; + else if (!ValidateInput01.validateAddress(address)) + System.out.println("Invalid address"); + else if (!ValidateInput01.validateCity(city)) + assert false; + else if (!ValidateInput01.validateState(state)) + assert false; + else if (!ValidateInput01.validateZip(zip)) + System.out.println("Invalid zip code"); + else if (!ValidateInput01.validatePhone(phone)) + System.out.println("Invalid phone number"); + else + System.out.println("Valid input. Thank you."); + } +} diff --git a/regression/strings/Validate01/ValidateInput01.class b/regression/strings/Validate01/ValidateInput01.class new file mode 100644 index 0000000000000000000000000000000000000000..5efab9300fcd9f0ac4b50c6e91c370bb287cb27e GIT binary patch literal 880 zcma)(O;6iE5Qg6gBsRw2@DV6b2(%RPAs49Vp(?6`kSZZXfRu_uJ`S7M0;9x1_9hZ3 z{G(oa0f_@Ypg*eW7;vCyrPha?nRlMuoqhf5_w5~kZLAqEFsEbQzyeWx zGP%;3=!uP%@J}|%GVuJ9&-n@=9kV47qgE{KI!@q*A;FB5Jx^W`#^SOp`4YltTvxpF zXWgUIj?Z1A-022Qo+TP>`uK6QegC{GH@DtLLzx(bNf@v0+Ld}$*!?ILG_0CiP~EaW)w%d^Wj{+< z*ygVF;tA~Gle347Gq)-Kk{-+^Xl)^zr*4Q9jPTEnJ{@cxOkT&hTI5I^lZ6}5Pfpkp zUQ_oX@g@st&LcF7#J#E&CKJ~f`tbrzGCZMzhZV5F@T3Y(DqxG@DHWVjz!`?8{}-NT aIHQ6!#mQNQXH>ARfLGb7S#~IaSAPH|Ae`<1 literal 0 HcmV?d00001 diff --git a/regression/strings/Validate01/ValidateInput01.java b/regression/strings/Validate01/ValidateInput01.java new file mode 100644 index 00000000000..961b02f2d30 --- /dev/null +++ b/regression/strings/Validate01/ValidateInput01.java @@ -0,0 +1,38 @@ +public class ValidateInput01 +{ + public static boolean validateFirstName(String firstName) + { + return firstName.matches("[A-Z][a-zA-Z]*"); + } + + public static boolean validateLastName(String lastName) + { + return lastName.matches("[a-zA-z]+(['-][a-zA-Z]+)*"); + } + + public static boolean validateAddress(String address) + { + return address.matches( + "\\d+\\s+([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)"); + } + + public static boolean validateCity(String city) + { + return city.matches("([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)"); + } + + public static boolean validateState(String state) + { + return state.matches("([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)") ; + } + + public static boolean validateZip(String zip) + { + return zip.matches("\\d{5}"); + } + + public static boolean validatePhone(String phone) + { + return phone.matches("[1-9]\\d{2}-[1-9]\\d{2}-\\d{4}"); + } +} diff --git a/regression/strings/Validate01/test.desc b/regression/strings/Validate01/test.desc new file mode 100644 index 00000000000..e797b2735aa --- /dev/null +++ b/regression/strings/Validate01/test.desc @@ -0,0 +1,8 @@ +FUTURE +Validate01.class +--string-refine +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/strings/Validate02/Validate02.class b/regression/strings/Validate02/Validate02.class new file mode 100644 index 0000000000000000000000000000000000000000..1d9ddd04737b9414e691eb9c5a1576b5d60823e6 GIT binary patch literal 1187 zcmZuw*;3O`82(PTgf!4LEEW|B3djyZ*%2rOv8+O*%=+h>yYxa4pV2 zM`!fjSMXib{{%{5hLg-$zVk2NzntHHzyAb~Kt@6fxI`h%n5kO(AcRtj&8e#Wjf1-qwN;- zJOj%zgysy>aOWBPJ-s^&fs~ck86xY3sc)8xySly2h3TTG874zZ&&Tyc?N}QwXy*R# zmTMd4{w!Cl-*UCw(S}y?7C$0f2d-f%El z1-}?2HRt6k?!}`TW~uBBsp|HDW*(_0R(Xg)s)Z_GUB(7B$wZA?X7^Cfxm2Qi5_?DR zD%rPkm*(C^MhWrw6TxIYZ|jc3(A;xRm8jZsRWe1f-nD+>xO$P=z$z1&<|}o>8h%R^ zcFDD_6=#X0$NMhKAe6XJf!gC>T1L)_$Pw!zH9&0~Lf%(Qpn~slPzO8Ab*x zh+HF44|&oWs33L?DIOH&@{P3RTznpvc|>R*B;q0Z1mYy3p5_?B6p)N=It`)$QzW;5 zD0O2D@1Wolg|4F+?WEm~;6D-!2~Y)e-2Q=BOcBWB)0>+4J4~ez)lchoaeGW%NvRJV!|Pix-4)Uvyc^ z=F2DIOssc=-(IiC!1LRm3spiUX3HW*tytQ1oWKo3f*C7&p8QT2iOY)QO9;bpUG+|% zbPtYuK6i~uuOGB{mT0tzqleMH`lo&QVe@@7l!;-Ogx9rQyV|G;`#g$84a+80kReRp zYv+wpzP4r$h*F_QSgkvyddQ83ZKaDrRu2bhfiVAXBvp5Qe7q#g);8=<4K6k>?I$S< zTimr?Jb^uYboN{G#BIrE(!JRPtt({f*bT9OSNyZ1PY0U^lh+Zh<~S0^RPhS*ixakl z*Yur8yvag_^9ao$ai?m Date: Mon, 27 Feb 2017 00:18:27 +0000 Subject: [PATCH 19/59] cleanup aa-path-symex and aa-symex --- src/aa-path-symex/Makefile | 15 - src/aa-path-symex/build_goto_trace.cpp | 1 - src/aa-path-symex/build_goto_trace.h | 1 - src/aa-path-symex/path_symex.cpp | 1257 ------------------------ src/aa-path-symex/path_symex.h | 1 - src/aa-path-symex/path_symex_state.cpp | 799 --------------- src/aa-path-symex/path_symex_state.h | 350 ------- src/aa-symex/Makefile | 68 -- src/aa-symex/path_search.cpp | 517 ---------- src/aa-symex/path_search.h | 119 --- 10 files changed, 3128 deletions(-) delete mode 100644 src/aa-path-symex/Makefile delete mode 120000 src/aa-path-symex/build_goto_trace.cpp delete mode 120000 src/aa-path-symex/build_goto_trace.h delete mode 100644 src/aa-path-symex/path_symex.cpp delete mode 120000 src/aa-path-symex/path_symex.h delete mode 100644 src/aa-path-symex/path_symex_state.cpp delete mode 100644 src/aa-path-symex/path_symex_state.h delete mode 100644 src/aa-symex/Makefile delete mode 100644 src/aa-symex/path_search.cpp delete mode 100644 src/aa-symex/path_search.h diff --git a/src/aa-path-symex/Makefile b/src/aa-path-symex/Makefile deleted file mode 100644 index 9d3c4d96074..00000000000 --- a/src/aa-path-symex/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -SRC = path_symex_state.cpp path_symex.cpp build_goto_trace.cpp - -INCLUDES= -I .. - -include ../config.inc -include ../common - -CLEANFILES = aa-path-symex$(LIBEXT) - -all: aa-path-symex$(LIBEXT) - -############################################################################### - -aa-path-symex$(LIBEXT): $(OBJ) - $(LINKLIB) diff --git a/src/aa-path-symex/build_goto_trace.cpp b/src/aa-path-symex/build_goto_trace.cpp deleted file mode 120000 index a8d26f1b4bd..00000000000 --- a/src/aa-path-symex/build_goto_trace.cpp +++ /dev/null @@ -1 +0,0 @@ -../path-symex/build_goto_trace.cpp \ No newline at end of file diff --git a/src/aa-path-symex/build_goto_trace.h b/src/aa-path-symex/build_goto_trace.h deleted file mode 120000 index 3183a6b0910..00000000000 --- a/src/aa-path-symex/build_goto_trace.h +++ /dev/null @@ -1 +0,0 @@ -../path-symex/build_goto_trace.h \ No newline at end of file diff --git a/src/aa-path-symex/path_symex.cpp b/src/aa-path-symex/path_symex.cpp deleted file mode 100644 index f503f25c6e1..00000000000 --- a/src/aa-path-symex/path_symex.cpp +++ /dev/null @@ -1,1257 +0,0 @@ -/*******************************************************************\ - -Module: Concrete Symbolic Transformer - -Author: Daniel Kroening, kroening@kroening.com - Alex Horn, alex.horn@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include -#include -#include - -#include - -#include - -#include "path_symex.h" - -// #define DEBUG - -#ifdef DEBUG -#include -#endif - -class path_symext -{ -public: - inline path_symext() - { - } - - void operator()( - path_symex_statet &state, - std::list &furter_states); - - void operator()(path_symex_statet &state); - - void do_goto( - path_symex_statet &state, - bool taken); - - void do_assert_fail(path_symex_statet &state) - { - const goto_programt::instructiont &instruction= - *state.get_instruction(); - - state.record_step(); - state.next_pc(); - exprt guard=state.read(not_exprt(instruction.guard)); - state.history->guard=guard; - } - -protected: - void do_goto( - path_symex_statet &state, - std::list &further_states); - - void function_call( - path_symex_statet &state, - const code_function_callt &call, - std::list &further_states) - { - exprt f=state.read(call.function()); - function_call_rec(state, call, f, further_states); - } - - void function_call_rec( - path_symex_statet &state, - const code_function_callt &function_call, - const exprt &function, - std::list &further_states); - - void return_from_function( - path_symex_statet &state, - const exprt &return_value); - - void symex_malloc( - path_symex_statet &state, - const exprt &lhs, - const side_effect_exprt &code); - - void assign( - path_symex_statet &state, - const exprt &lhs, - const exprt &rhs); - - inline void assign( - path_symex_statet &state, - const code_assignt &assignment) - { - assign(state, assignment.lhs(), assignment.rhs()); - } - - void assign_rec( - path_symex_statet &state, - exprt::operandst &guard, // instantiated - const exprt &ssa_lhs, // instantiated, recursion here - const exprt &ssa_rhs); // instantiated - - static bool propagate(const exprt &src); -}; - -/*******************************************************************\ - -Function: path_symext::propagate - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -bool path_symext::propagate(const exprt &src) -{ - // propagate things that are 'simple enough' - if(src.is_constant()) - return true; - else if(src.id()==ID_member) - return propagate(to_member_expr(src).struct_op()); - else if(src.id()==ID_index) - return false; - else if(src.id()==ID_typecast) - return propagate(to_typecast_expr(src).op()); - else if(src.id()==ID_symbol) - return true; - else if(src.id()==ID_address_of) - return true; - else if(src.id()==ID_plus) - { - forall_operands(it, src) - if(!propagate(*it)) - return false; - return true; - } - else if(src.id()==ID_array) - { - forall_operands(it, src) - if(!propagate(*it)) - return false; - return true; - } - else if(src.id()==ID_vector) - { - forall_operands(it, src) - if(!propagate(*it)) - return false; - return true; - } - else if(src.id()==ID_if) - { - const if_exprt &if_expr=to_if_expr(src); - if(!propagate(if_expr.true_case()) || - !propagate(if_expr.false_case())) - return false; - - return true; - } - else if(src.id()==ID_array_of) - { - return propagate(to_array_of_expr(src).what()); - } - else if(src.id()==ID_union) - { - return propagate(to_union_expr(src).op()); - } - else - { - return false; - } -} - -/*******************************************************************\ - -Function: path_symext::assign - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symext::assign( - path_symex_statet &state, - const exprt &lhs, - const exprt &rhs) -{ - if(rhs.id()==ID_side_effect) // catch side effects on rhs - { - const side_effect_exprt &side_effect_expr=to_side_effect_expr(rhs); - const irep_idt &statement=side_effect_expr.get_statement(); - - if(statement==ID_malloc) - { - symex_malloc(state, lhs, side_effect_expr); - return; - } - else if(statement==ID_nondet) - { - // done in statet:instantiate_rec - } - else - throw "unexpected side-effect on rhs: "+id2string(statement); - } - - // read the address of the lhs, with propagation - exprt lhs_address=state.read(address_of_exprt(lhs)); - - // now SSA the lhs, no propagation - exprt ssa_lhs= - state.read_no_propagate(dereference_exprt(lhs_address)); - - // read the rhs - exprt ssa_rhs=state.read(rhs); - - // start recursion on lhs - exprt::operandst _guard; // start with empty guard - assign_rec(state, _guard, ssa_lhs, ssa_rhs); -} - -/*******************************************************************\ - -Function: path_symext::symex_malloc - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -inline static typet c_sizeof_type_rec(const exprt &expr) -{ - const irept &sizeof_type=expr.find(ID_C_c_sizeof_type); - - if(!sizeof_type.is_nil()) - { - return static_cast(sizeof_type); - } - else if(expr.id()==ID_mult) - { - forall_operands(it, expr) - { - typet t=c_sizeof_type_rec(*it); - if(t.is_not_nil()) - return t; - } - } - - return nil_typet(); -} - -void path_symext::symex_malloc( - path_symex_statet &state, - const exprt &lhs, - const side_effect_exprt &code) -{ - if(code.operands().size()!=1) - throw "malloc expected to have one operand"; - - // increment dynamic object counter - unsigned dynamic_count=++state.var_map.dynamic_count; - - exprt size=code.op0(); - typet object_type=nil_typet(); - - { - exprt tmp_size=state.read(size); // to allow constant propagation - - // special treatment for sizeof(T)*x - if(tmp_size.id()==ID_mult && - tmp_size.operands().size()==2 && - tmp_size.op0().find(ID_C_c_sizeof_type).is_not_nil()) - { - object_type=array_typet( - c_sizeof_type_rec(tmp_size.op0()), - tmp_size.op1()); - } - else - { - typet tmp_type=c_sizeof_type_rec(tmp_size); - - if(tmp_type.is_not_nil()) - { - // Did the size get multiplied? - mp_integer elem_size=pointer_offset_size(tmp_type, state.var_map.ns); - mp_integer alloc_size; - if(elem_size<0 || to_integer(tmp_size, alloc_size)) - { - } - else - { - if(alloc_size==elem_size) - object_type=tmp_type; - else - { - mp_integer elements=alloc_size/elem_size; - - if(elements*elem_size==alloc_size) - object_type= - array_typet(tmp_type, from_integer(elements, tmp_size.type())); - } - } - } - } - - if(object_type.is_nil()) - object_type=array_typet(unsigned_char_type(), tmp_size); - - // we introduce a fresh symbol for the size - // to prevent any issues of the size getting ever changed - - if(object_type.id()==ID_array && - !to_array_type(object_type).size().is_constant()) - { - exprt &size=to_array_type(object_type).size(); - - symbolt size_symbol; - - size_symbol.base_name="dynamic_object_size"+std::to_string(dynamic_count); - size_symbol.name="symex::"+id2string(size_symbol.base_name); - size_symbol.is_lvalue=true; - size_symbol.type=tmp_size.type(); - size_symbol.mode=ID_C; - - assign(state, - size_symbol.symbol_expr(), - size); - - size=size_symbol.symbol_expr(); - } - } - - // value - symbolt value_symbol; - - value_symbol.base_name= - "dynamic_object"+std::to_string(state.var_map.dynamic_count); - value_symbol.name="symex_dynamic::"+id2string(value_symbol.base_name); - value_symbol.is_lvalue=true; - value_symbol.type=object_type; - value_symbol.type.set("#dynamic", true); - value_symbol.mode=ID_C; - - address_of_exprt rhs; - - if(object_type.id()==ID_array) - { - rhs.type()=pointer_typet(value_symbol.type.subtype()); - index_exprt index_expr(value_symbol.type.subtype()); - index_expr.array()=value_symbol.symbol_expr(); - index_expr.index()=from_integer(0, index_type()); - rhs.op0()=index_expr; - } - else - { - rhs.op0()=value_symbol.symbol_expr(); - rhs.type()=pointer_typet(value_symbol.type); - } - - if(rhs.type()!=lhs.type()) - rhs.make_typecast(lhs.type()); - - assign(state, lhs, rhs); -} - -/*******************************************************************\ - -Function: path_symext::assign_rec - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symext::assign_rec( - path_symex_statet &state, - exprt::operandst &guard, - const exprt &ssa_lhs, - const exprt &ssa_rhs) -{ - // const typet &ssa_lhs_type=state.var_map.ns.follow(ssa_lhs.type()); - - #ifdef DEBUG - std::cout << "assign_rec: " << ssa_lhs.pretty() << std::endl; - // std::cout << "ssa_lhs_type: " << ssa_lhs_type.id() << std::endl; - #endif - - if(ssa_lhs.id()==ID_symbol) - { - // These are expected to be SSA symbols - assert(ssa_lhs.get_bool(ID_C_SSA_symbol)); - - const symbol_exprt &symbol_expr=to_symbol_expr(ssa_lhs); - const irep_idt &full_identifier=symbol_expr.get(ID_C_full_identifier); - - #ifdef DEBUG - const irep_idt &ssa_identifier=symbol_expr.get_identifier(); - std::cout << "SSA symbol identifier: " << ssa_identifier << std::endl; - std::cout << "full identifier: " << full_identifier << std::endl; - #endif - - var_mapt::var_infot &var_info=state.var_map[full_identifier]; - assert(var_info.full_identifier==full_identifier); - - // increase the SSA counter and produce new SSA symbol expression - var_info.increment_ssa_counter(); - symbol_exprt new_lhs=var_info.ssa_symbol(); - - #ifdef DEBUG - std::cout << "new_lhs: " << new_lhs.get_identifier() << std::endl; - #endif - - // record new state of lhs - { - // reference is not stable - path_symex_statet::var_statet &var_state=state.get_var_state(var_info); - var_state.ssa_symbol=new_lhs; - } - - // rhs nil means non-det assignment - if(ssa_rhs.is_nil()) - { - path_symex_statet::var_statet &var_state=state.get_var_state(var_info); - var_state.value=nil_exprt(); - } - else - { - // consistency check - if(!base_type_eq(ssa_rhs.type(), new_lhs.type(), state.var_map.ns)) - { - #ifdef DEBUG - std::cout << "ssa_rhs: " << ssa_rhs.pretty() << std::endl; - std::cout << "new_lhs: " << new_lhs.pretty() << std::endl; - #endif - throw "assign_rec got different types"; - } - - // record the step - state.record_step(); - path_symex_stept &step=*state.history; - - if(!guard.empty()) - step.guard=conjunction(guard); - step.full_lhs=ssa_lhs; - step.ssa_lhs=new_lhs; - step.ssa_rhs=ssa_rhs; - - // propagate the rhs? - path_symex_statet::var_statet &var_state=state.get_var_state(var_info); - var_state.value=propagate(ssa_rhs)?ssa_rhs:nil_exprt(); - } - } - else if(ssa_lhs.id()==ID_member) - { - #ifdef DEBUG - std::cout << "assign_rec ID_member" << std::endl; - #endif - - const member_exprt &ssa_lhs_member_expr=to_member_expr(ssa_lhs); - const exprt &struct_op=ssa_lhs_member_expr.struct_op(); - - const typet &compound_type= - state.var_map.ns.follow(struct_op.type()); - - if(compound_type.id()==ID_struct) - { - // We flatten the top-level structs, so this one is inside an - // array or a union. - - exprt member_name(ID_member_name); - member_name.set( - ID_component_name, - ssa_lhs_member_expr.get_component_name()); - - with_exprt new_rhs(struct_op, member_name, ssa_rhs); - - assign_rec(state, guard, struct_op, new_rhs); - } - else if(compound_type.id()==ID_union) - { - // rewrite into byte_extract, and do again - exprt offset=from_integer(0, index_type()); - - byte_extract_exprt - new_lhs(byte_update_id(), struct_op, offset, ssa_rhs.type()); - - assign_rec(state, guard, new_lhs, ssa_rhs); - } - else - throw "assign_rec: member expects struct or union type"; - } - else if(ssa_lhs.id()==ID_index) - { - #ifdef DEBUG - std::cout << "assign_rec ID_index" << std::endl; - #endif - - throw "unexpected array index on lhs"; - } - else if(ssa_lhs.id()==ID_dereference) - { - #ifdef DEBUG - std::cout << "assign_rec ID_dereference" << std::endl; - #endif - - throw "unexpected dereference on lhs"; - } - else if(ssa_lhs.id()==ID_if) - { - #ifdef DEBUG - std::cout << "assign_rec ID_if" << std::endl; - #endif - - const if_exprt &lhs_if_expr=to_if_expr(ssa_lhs); - exprt cond=lhs_if_expr.cond(); - - // true - guard.push_back(cond); - assign_rec(state, guard, lhs_if_expr.true_case(), ssa_rhs); - guard.pop_back(); - - // false - guard.push_back(not_exprt(cond)); - assign_rec(state, guard, lhs_if_expr.false_case(), ssa_rhs); - guard.pop_back(); - } - else if(ssa_lhs.id()==ID_byte_extract_little_endian || - ssa_lhs.id()==ID_byte_extract_big_endian) - { - #ifdef DEBUG - std::cout << "assign_rec ID_byte_extract" << std::endl; - #endif - - const byte_extract_exprt &byte_extract_expr= - to_byte_extract_expr(ssa_lhs); - - // assignment to byte_extract operators: - // turn into byte_update operator - - irep_idt new_id; - - if(ssa_lhs.id()==ID_byte_extract_little_endian) - new_id=ID_byte_update_little_endian; - else if(ssa_lhs.id()==ID_byte_extract_big_endian) - new_id=ID_byte_update_big_endian; - else - assert(false); - - byte_update_exprt new_rhs(new_id); - - new_rhs.type()=byte_extract_expr.op().type(); - new_rhs.op()=byte_extract_expr.op(); - new_rhs.offset()=byte_extract_expr.offset(); - new_rhs.value()=ssa_rhs; - - const exprt new_lhs=byte_extract_expr.op(); - - assign_rec(state, guard, new_lhs, new_rhs); - } - else if(ssa_lhs.id()==ID_struct) - { - const struct_typet &struct_type= - to_struct_type(state.var_map.ns.follow(ssa_lhs.type())); - const struct_typet::componentst &components= - struct_type.components(); - - // split up into components - const exprt::operandst &operands=ssa_lhs.operands(); - - assert(operands.size()==components.size()); - - for(std::size_t i=0; i &further_states) -{ - #ifdef DEBUG - std::cout << "function_call_rec: " << function.pretty() << std::endl; - #endif - - if(function.id()==ID_symbol) - { - const irep_idt &function_identifier= - to_symbol_expr(function).get_identifier(); - - // find the function - locst::function_mapt::const_iterator f_it= - state.locs.function_map.find(function_identifier); - - if(f_it==state.locs.function_map.end()) - throw - "failed to find `"+id2string(function_identifier)+ - "' in function_map"; - - const locst::function_entryt &function_entry=f_it->second; - - loc_reft function_entry_point=function_entry.first_loc; - - // do we have a body? - if(function_entry_point==loc_reft()) - { - // no body - - // this is a skip - if(call.lhs().is_not_nil()) - assign(state, call.lhs(), nil_exprt()); - - state.next_pc(); - return; - } - - // push a frame on the call stack - path_symex_statet::threadt &thread= - state.threads[state.get_current_thread()]; - thread.call_stack.push_back(path_symex_statet::framet()); - thread.call_stack.back().current_function=function_identifier; - thread.call_stack.back().return_location=thread.pc.next_loc(); - thread.call_stack.back().return_lhs=call.lhs(); - thread.call_stack.back().saved_local_vars=thread.local_vars; - - - const code_typet &code_type=function_entry.type; - - const code_typet::parameterst &function_parameters=code_type.parameters(); - - const exprt::operandst &call_arguments=call.arguments(); - - // now assign the argument values to parameters - for(std::size_t i=0; iguard=not_exprt(guard); - function_call_rec( - further_states.back(), call, if_expr.false_case(), further_states); - } - - // do the true-case in 'state' - { - state.record_branch_step(true); - state.history->guard=guard; - function_call_rec(state, call, if_expr.true_case(), further_states); - } - } - } - else - // NOLINTNEXTLINE(readability/throw) as message is correctly uppercase - throw "TODO: function_call "+function.id_string(); -} - -/*******************************************************************\ - -Function: path_symext::return_from_function - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symext::return_from_function( - path_symex_statet &state, - const exprt &return_value) -{ - path_symex_statet::threadt &thread=state.threads[state.get_current_thread()]; - - // returning from very last function? - if(thread.call_stack.empty()) - { - state.disable_current_thread(); - } - else - { - // update statistics - state.recursion_map[thread.call_stack.back().current_function]--; - - // set PC to return location - thread.pc=thread.call_stack.back().return_location; - - // assign the return value - if(return_value.is_not_nil() && - thread.call_stack.back().return_lhs.is_not_nil()) - assign(state, thread.call_stack.back().return_lhs, return_value); - - thread.call_stack.pop_back(); - } -} - -/*******************************************************************\ - -Function: path_symext::do_goto - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symext::do_goto( - path_symex_statet &state, - std::list &further_states) -{ - const goto_programt::instructiont &instruction= - *state.get_instruction(); - - if(instruction.is_backwards_goto()) - { - // we keep a statistic on how many times we execute backwards gotos - state.unwinding_map[state.pc()]++; - } - - const loct &loc=state.locs[state.pc()]; - assert(!loc.branch_target.is_nil()); - - exprt guard=state.read(instruction.guard); - - if(guard.is_true()) // branch taken always - { - state.record_branch_step(true); - state.set_pc(loc.branch_target); - return; // we are done - } - -#ifdef PATH_SYMEX_FORK - pid_t pid=-1; -#endif - - if(!guard.is_false()) - { - // branch taken case - -#ifdef PATH_SYMEX_FORK - pid=fork(); - if(pid==0) - { - // "state" is stored in "further_states" - assert(!further_states.empty()); - - // child process explores paths starting from the - // new state thereby partitioning the search space - std::list::iterator - s_it=further_states.begin(), s_end=further_states.end(); - while(s_it!=s_end) - { - if(&(*s_it)!=&state) - // iterators in std::list are stable - s_it=further_states.erase(s_it); - else - ++s_it; - } - - assert(further_states.size()==1); - - // branch not taken case - state.record_branch_step(false); - state.set_pc(loc.branch_target); - state.history->guard=guard; - } -#endif - -#ifdef PATH_SYMEX_FORK - // forking failed so continue as if PATH_SYMEX_FORK were undefined - if(pid==-1) // NOLINT(readability/braces) -#endif - { -#ifdef PATH_SYMEX_LAZY_STATE - // lazily copy the state into 'further_states' - further_states.push_back(path_symex_statet::lazy_copy(state)); - further_states.back().record_true_branch(); -#else - // eagerly copy the state into 'further_states' - further_states.push_back(state); - further_states.back().record_branch_step(true); - further_states.back().set_pc(loc.branch_target); - further_states.back().history->guard=guard; -#endif - } - } - -#ifdef PATH_SYMEX_FORK - // parent process (regardless of any possible fork errors) - // should finish to explore all current 'further_states' - if(pid!=0) // NOLINT(readability/braces) -#endif - { - // branch not taken case - exprt negated_guard=not_exprt(guard); - state.record_branch_step(false); - state.next_pc(); - state.history->guard=negated_guard; - } -} - -/*******************************************************************\ - -Function: path_symext::do_goto - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symext::do_goto( - path_symex_statet &state, - bool taken) -{ - state.record_step(); - - const goto_programt::instructiont &instruction= - *state.get_instruction(); - - if(instruction.is_backwards_goto()) - { - // we keep a statistic on how many times we execute backwards gotos - state.unwinding_map[state.pc()]++; - } - - exprt guard=state.read(instruction.guard); - - if(taken) - { - // branch taken case - const loct &loc=state.locs[state.pc()]; - assert(!loc.branch_target.is_nil()); - state.set_pc(loc.branch_target); - state.history->guard=guard; - } - else - { - // branch not taken case - exprt negated_guard=not_exprt(guard); - state.next_pc(); - state.history->guard=negated_guard; - } -} - -/*******************************************************************\ - -Function: path_symext::operator() - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symext::operator()( - path_symex_statet &state, - std::list &further_states) -{ - const goto_programt::instructiont &instruction= - *state.get_instruction(); - - #ifdef DEBUG - std::cout << "path_symext::operator(): " << instruction.type - << std::endl; - #endif - - switch(instruction.type) - { - case END_FUNCTION: - // pop the call stack - state.record_step(); - return_from_function(state, nil_exprt()); - break; - - case RETURN: - // pop the call stack - { - state.record_step(); - exprt return_val=instruction.code.operands().size()==1? - instruction.code.op0():nil_exprt(); - return_from_function(state, return_val); - } - break; - - case START_THREAD: - { - const loct &loc=state.locs[state.pc()]; - assert(!loc.branch_target.is_nil()); - - state.record_step(); - state.next_pc(); - - // ordering of the following matters due to vector instability - path_symex_statet::threadt &new_thread=state.add_thread(); - path_symex_statet::threadt &old_thread= - state.threads[state.get_current_thread()]; - new_thread.pc=loc.branch_target; - new_thread.local_vars=old_thread.local_vars; - } - break; - - case END_THREAD: - state.record_step(); - state.disable_current_thread(); - break; - - case GOTO: - if(state.is_lazy()) - do_goto(state, state.restore_branch()); - else - do_goto(state, further_states); - break; - - case CATCH: - // ignore for now - state.record_step(); - state.next_pc(); - break; - - case THROW: - state.record_step(); - throw "THROW not yet implemented"; // NOLINT(readability/throw) - - case ASSUME: - state.record_step(); - state.next_pc(); - if(instruction.guard.is_false()) - state.disable_current_thread(); - else - { - exprt guard=state.read(instruction.guard); - state.history->guard=guard; - } - break; - - case ASSERT: - case SKIP: - case LOCATION: - case DEAD: - state.record_step(); - state.next_pc(); - break; - - case DECL: - // assigning an RHS of NIL means 'nondet' - assign(state, to_code_decl(instruction.code).symbol(), nil_exprt()); - state.next_pc(); - break; - - case ATOMIC_BEGIN: - if(state.inside_atomic_section) - throw "nested ATOMIC_BEGIN"; - - state.record_step(); - state.next_pc(); - state.inside_atomic_section=true; - break; - - case ATOMIC_END: - if(!state.inside_atomic_section) - throw "ATOMIC_END unmatched"; // NOLINT(readability/throw) - - state.record_step(); - state.next_pc(); - state.inside_atomic_section=false; - break; - - case ASSIGN: - assign(state, to_code_assign(instruction.code)); - state.next_pc(); - break; - - case FUNCTION_CALL: - state.record_step(); - function_call( - state, to_code_function_call(instruction.code), further_states); - break; - - case OTHER: - state.record_step(); - - { - const codet &code=instruction.code; - const irep_idt &statement=code.get_statement(); - - if(statement==ID_expression) - { - // like SKIP - } - else if(statement==ID_printf) - { - // ignore for now (should record stuff printed) - } - else if(statement==ID_asm) - { - // ignore for now - } - else if(statement==ID_fence) - { - // ignore for SC - } - else if(statement==ID_input) - { - // just needs to be recorded - } - else - throw "unexpected OTHER statement: "+id2string(statement); - } - - state.next_pc(); - break; - - default: - throw "path_symext: unexpected instruction"; - } -} - -/*******************************************************************\ - -Function: path_symext::operator() - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symext::operator()(path_symex_statet &state) -{ - std::list further_states; - operator()(state, further_states); - if(!further_states.empty()) - throw "path_symext got unexpected further states"; -} - -/*******************************************************************\ - -Function: path_symex - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symex( - path_symex_statet &state, - std::list &further_states) -{ - // "state" is stored in "further_states" - assert(!further_states.empty()); - - path_symext path_symex; - path_symex(state, further_states); -} - -/*******************************************************************\ - -Function: path_symex - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symex(path_symex_statet &state) -{ - path_symext path_symex; - path_symex(state); -} - -/*******************************************************************\ - -Function: path_symex_goto - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symex_goto( - path_symex_statet &state, - bool taken) -{ - path_symext path_symex; - path_symex.do_goto(state, taken); -} - -/*******************************************************************\ - -Function: path_symex_assert_fail - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_symex_assert_fail(path_symex_statet &state) -{ - path_symext path_symex; - path_symex.do_assert_fail(state); -} diff --git a/src/aa-path-symex/path_symex.h b/src/aa-path-symex/path_symex.h deleted file mode 120000 index 538d30846d4..00000000000 --- a/src/aa-path-symex/path_symex.h +++ /dev/null @@ -1 +0,0 @@ -../path-symex/path_symex.h \ No newline at end of file diff --git a/src/aa-path-symex/path_symex_state.cpp b/src/aa-path-symex/path_symex_state.cpp deleted file mode 100644 index b0c502f639d..00000000000 --- a/src/aa-path-symex/path_symex_state.cpp +++ /dev/null @@ -1,799 +0,0 @@ -/*******************************************************************\ - -Module: State of path-based symbolic simulator - -Author: Daniel Kroening, kroening@kroening.com - Alex Horn, alex.horn@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include -#include - -#include - -#include - -#include -#include - -#include "path_symex_state.h" - -// #define DEBUG - -#ifdef DEBUG -#include -#include -#endif - -/*******************************************************************\ - -Function: initial_state - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -path_symex_statet initial_state( - var_mapt &var_map, - const locst &locs, - path_symex_historyt &path_symex_history) -{ - return path_symex_statet( - var_map, - locs, - path_symex_step_reft(path_symex_history), - path_symex_statet::branchest()); -} - -/*******************************************************************\ - -Function: path_symex_statet::output - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -goto_programt::const_targett path_symex_statet::get_instruction() const -{ - assert(current_thread " << tmp.pretty() << std::endl; - #endif - - return tmp5; -} - -/*******************************************************************\ - -Function: path_symex_statet::instantiate_rec - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -exprt path_symex_statet::instantiate_rec( - const exprt &src, - bool propagate) -{ - #ifdef DEBUG - std::cout << "instantiate_rec: " - << from_expr(var_map.ns, "", src) << std::endl; - #endif - - const typet &src_type=var_map.ns.follow(src.type()); - - if(src_type.id()==ID_struct) // src is a struct - { - const struct_typet &struct_type=to_struct_type(src_type); - const struct_typet::componentst &components=struct_type.components(); - - struct_exprt result(src.type()); - result.operands().resize(components.size()); - - // split it up into components - for(unsigned i=0; ithread_nr!=current_thread) - no_thread_interleavings++; - - // update our statistics - depth++; - - // add the step - history.generate_successor(); - path_symex_stept &step=*history; - - // copy PC - assert(current_threadis_goto()); - -#ifdef PATH_SYMEX_LAZY_BRANCH - if(!branches.empty() || history.is_nil()) -#endif - { - // get_branches() relies on branch decisions - branches.push_back(taken); - - if(get_instruction()->is_goto()) - { - branches_restore++; - } - else - { - assert(pc()==locs.entry_loc); - assert(history.is_nil()); - } - } - - record_step(); -} - -/*******************************************************************\ - -Function: path_symex_statet::is_feasible - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -bool path_symex_statet::is_feasible( - decision_proceduret &decision_procedure) const -{ - // feed path constraint to decision procedure - decision_procedure << history; - - // check whether SAT - switch(decision_procedure()) - { - case decision_proceduret::D_SATISFIABLE: return true; - - case decision_proceduret::D_UNSATISFIABLE: return false; - - case decision_proceduret::D_ERROR: throw "error from decision procedure"; - } - - return true; // not really reachable -} - -/*******************************************************************\ - -Function: path_symex_statet::check_assertion - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -bool path_symex_statet::check_assertion( - decision_proceduret &decision_procedure) -{ - const goto_programt::instructiont &instruction=*get_instruction(); - - // assert that this is an assertion - assert(instruction.is_assert()); - - // the assertion in SSA - exprt assertion=read(instruction.guard); - - // trivial? - if(assertion.is_true()) - return true; // no error - - // the path constraint - decision_procedure << history; - - // negate the assertion - decision_procedure.set_to(assertion, false); - - // check whether SAT - switch(decision_procedure.dec_solve()) - { - case decision_proceduret::D_SATISFIABLE: - return false; // error - - case decision_proceduret::D_UNSATISFIABLE: - return true; // no error - - default: - throw "error from decision procedure"; - } - - return true; // not really reachable -} diff --git a/src/aa-path-symex/path_symex_state.h b/src/aa-path-symex/path_symex_state.h deleted file mode 100644 index dd10e43d8da..00000000000 --- a/src/aa-path-symex/path_symex_state.h +++ /dev/null @@ -1,350 +0,0 @@ -/*******************************************************************\ - -Module: State of path-based symbolic simulator - -Author: Daniel Kroening, kroening@kroening.com - Alex Horn, alex.horn@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_AA_PATH_SYMEX_PATH_SYMEX_STATE_H -#define CPROVER_AA_PATH_SYMEX_PATH_SYMEX_STATE_H - -#include - -#include -#include -#include - -// These variables may be defined in this header file only because -// it is (transitively) included by many essential path-symex files. -// In addition, since these variables determine how states are -// handled, it makes sense to define them in this header file. -#define PATH_SYMEX_LAZY_STATE -#define PATH_SYMEX_FORK - -// This flag is particularly useful for regression testing purposes. -// -// If PATH_SYMEX_LAZY_BRANCH is undefined, then branches are always -// recorded and the control logic in get_branches() is bypassed. But -// the output of path_search() should be identical in this setting; -// otherwise, the assumptions about GOTO programs or the history -// data structure should be revisited. -#define PATH_SYMEX_LAZY_BRANCH - -// check POSIX-compliance -#ifdef PATH_SYMEX_FORK -#if defined(__linux__) || \ - defined(__FreeBSD_kernel__) || \ - defined(__GNU__) || \ - defined(__unix__) || \ - defined(__CYGWIN__) || \ - defined(__MACH__) -#include -#include -#else -#error Cannot define PATH_SYMEX_FORK on non-POSIX systems -#endif -#endif - -class path_symex_statet -{ -public: - // use symbolic execution to repopulate composite fields - - // TODO: consider std::bitset or chaining to shrink state size - typedef std::vector branchest; - - // if _branches.empty(), then initial state; otherwise, lazy state - - // \post: pc() is the entry point to the program under scrutiny - path_symex_statet( - var_mapt &_var_map, - const locst &_locs, - path_symex_step_reft _history, - const branchest &_branches): - var_map(_var_map), - locs(_locs), - shared_vars(), - threads(), - inside_atomic_section(), - history(_history), - unwinding_map(), - recursion_map(), - branches(_branches), - branches_restore(0), - current_thread(0), - no_thread_interleavings(0), - depth(0) - { - path_symex_statet::threadt &thread=add_thread(); - thread.pc=locs.entry_loc; // reset its PC - } - - // like initial state except that branches are copied from "other" - // and history will be 'nil' - static path_symex_statet lazy_copy(path_symex_statet &other) - { - // allow compiler to use RVO - return path_symex_statet( - other.var_map, - other.locs, - path_symex_step_reft(), - other.get_branches()); - } - - // These are tied to a particular var_map - // and a particular program. - var_mapt &var_map; - const locst &locs; - - // the value of a variable - struct var_statet - { - // it's a given explicit value or a symbol with given identifier - exprt value; - symbol_exprt ssa_symbol; - - // for uninterpreted functions or arrays we maintain an index set - typedef std::set index_sett; - index_sett index_set; - - var_statet(): - value(nil_exprt()), - ssa_symbol(irep_idt()) - { - } - }; - - // the values of the shared variables - typedef std::vector var_valt; - var_valt shared_vars; - - // procedure frame - struct framet - { - irep_idt current_function; - loc_reft return_location; - exprt return_lhs; - var_valt saved_local_vars; - }; - - // call stack - typedef std::vector call_stackt; - - // the state of a thread - struct threadt - { - public: - loc_reft pc; - call_stackt call_stack; // the call stack - var_valt local_vars; // thread-local variables - bool active; - - threadt():active(true) - { - } - }; - - typedef std::vector threadst; - threadst threads; - - // warning: reference is not stable - var_statet &get_var_state(const var_mapt::var_infot &var_info); - - bool inside_atomic_section; - - unsigned get_current_thread() const - { - return current_thread; - } - - void set_current_thread(unsigned _thread) - { - current_thread=_thread; - } - - goto_programt::const_targett get_instruction() const; - - // branch taken case - void record_true_branch() - { - branches.push_back(true); - } - - // branch not taken case - void record_false_branch() - { - branches.push_back(false); - } - - bool is_lazy() const - { - return branches_restore < branches.size(); - } - - // returns branch direction that should be taken - bool restore_branch() - { - assert(is_lazy()); - return branches[branches_restore++]; - } - - bool is_executable() const - { - return !threads.empty() && - threads[current_thread].active; - } - - // execution history - path_symex_step_reft history; - - // adds an entry to the history - void record_step(); - - // like record_step() except that branch decision is also recorded - void record_branch_step(bool taken); - - // various state transformers - - threadt &add_thread() - { - threads.resize(threads.size()+1); - return threads.back(); - } - - void disable_current_thread() - { - threads[current_thread].active=false; - } - - loc_reft pc() const - { - return threads[current_thread].pc; - } - - void next_pc() - { - threads[current_thread].pc.increase(); - } - - void set_pc(loc_reft new_pc) - { - threads[current_thread].pc=new_pc; - } - - // output - void output(std::ostream &out) const; - void output(const threadt &thread, std::ostream &out) const; - - // instantiate expressions with propagation - exprt read(const exprt &src) - { - return read(src, true); - } - - // instantiate without constant propagation - exprt read_no_propagate(const exprt &src) - { - return read(src, false); - } - - exprt dereference_rec(const exprt &src, bool propagate); - - std::string array_index_as_string(const exprt &) const; - - unsigned get_no_thread_interleavings() const - { - return no_thread_interleavings; - } - - unsigned get_depth() const - { - return depth; - } - - bool is_feasible(class decision_proceduret &) const; - - bool check_assertion(class decision_proceduret &); - - // counts how many times we have executed backwards edges - typedef std::map unwinding_mapt; - unwinding_mapt unwinding_map; - - // similar for recursive function calls - typedef std::map recursion_mapt; - recursion_mapt recursion_map; - -protected: - branchest branches; - branchest::size_type branches_restore; - - // On first call, O(N) where N is the length of the execution path - // leading to this state. Subsequent calls run in constant time. - const branchest &get_branches() - { - if(!branches.empty() || history.is_nil()) - return branches; - - // Contrarily, suppose this state is lazy. Since we did not - // return above, branches.empty(). By definition of is_lazy(), - // branches_restore must have been a negative number. Since - // its type is unsigned, however, this is impossible. - assert(!is_lazy()); - - path_symex_step_reft step_ref=history; - assert(!step_ref.is_nil()); - loc_reft next_loc_ref=pc(); - for(;;) - { - if(step_ref.is_nil()) - break; - - const loct &loc=locs[step_ref->pc]; - if(loc.target->is_goto()) - { - branches.push_back(loc.branch_target==next_loc_ref); - assert(branches.back() || step_ref->pc.next_loc()==next_loc_ref); - } - - next_loc_ref=step_ref->pc; - step_ref=step_ref->predecessor; - } - - // preserve non-laziness of this state (see first assertion) - branches_restore=branches.size(); - - // TODO: add "path_symex_step::branch_depth" field so we can - // reserve() the right capacity of vector and avoid reverse(). - std::reverse(branches.begin(), branches.end()); - - return branches; - } - - unsigned current_thread; - unsigned no_thread_interleavings; - unsigned depth; - - exprt read( - const exprt &src, - bool propagate); - - exprt instantiate_rec( - const exprt &src, - bool propagate); - - exprt instantiate_rec_address( - const exprt &src, - bool propagate); - - exprt read_symbol_member_index( - const exprt &src, - bool propagate); -}; - -path_symex_statet initial_state( - var_mapt &var_map, - const locst &locs, - path_symex_historyt &); - -#endif // CPROVER_AA_PATH_SYMEX_PATH_SYMEX_STATE_H diff --git a/src/aa-symex/Makefile b/src/aa-symex/Makefile deleted file mode 100644 index a5e2b0ad5d8..00000000000 --- a/src/aa-symex/Makefile +++ /dev/null @@ -1,68 +0,0 @@ -SRC = path_search.cpp - -OBJ += ../ansi-c/ansi-c$(LIBEXT) \ - ../linking/linking$(LIBEXT) \ - ../big-int/big-int$(LIBEXT) \ - ../goto-programs/goto-programs$(LIBEXT) \ - ../analyses/analyses$(LIBEXT) \ - ../langapi/langapi$(LIBEXT) \ - ../xmllang/xmllang$(LIBEXT) \ - ../assembler/assembler$(LIBEXT) \ - ../solvers/solvers$(LIBEXT) \ - ../util/util$(LIBEXT) \ - ../goto-symex/adjust_float_expressions$(OBJEXT) \ - ../goto-symex/rewrite_union$(OBJEXT) \ - ../pointer-analysis/dereference$(OBJEXT) \ - ../goto-instrument/cover$(OBJEXT) \ - ../aa-path-symex/aa-path-symex$(LIBEXT) \ - ../symex/symex_main$(OBJEXT) \ - ../symex/symex_parse_options$(OBJEXT) \ - ../symex/symex_cover$(OBJEXT) \ - ../path-symex/locs$(OBJEXT) ../path-symex/var_map$(OBJEXT) \ - ../path-symex/path_symex_history$(OBJEXT) - -INCLUDES= -I .. - -LIBS = - -include ../config.inc -include ../common - -CLEANFILES = symex$(EXEEXT) - -all: symex$(EXEEXT) - -ifneq ($(wildcard ../bv_refinement/Makefile),) - OBJ += ../bv_refinement/bv_refinement$(LIBEXT) - CP_CXXFLAGS += -DHAVE_BV_REFINEMENT -endif - -ifneq ($(wildcard ../cpp/Makefile),) - OBJ += ../cpp/cpp$(LIBEXT) - CP_CXXFLAGS += -DHAVE_CPP -endif - -ifneq ($(wildcard ../java_bytecode/Makefile),) - OBJ += ../java_bytecode/java_bytecode$(LIBEXT) - CP_CXXFLAGS += -DHAVE_JAVA_BYTECODE -endif - -ifneq ($(wildcard ../specc/Makefile),) - OBJ += ../specc/specc$(LIBEXT) - CP_CXXFLAGS += -DHAVE_SPECC -endif - -ifneq ($(wildcard ../php/Makefile),) - OBJ += ../php/php$(LIBEXT) - CP_CXXFLAGS += -DHAVE_PHP -endif - -############################################################################### - -symex$(EXEEXT): $(OBJ) - $(LINKBIN) - -.PHONY: symex-mac-signed - -symex-mac-signed: cbmc$(EXEEXT) - strip symex$(EXEEXT) ; codesign -v -s $(OSX_IDENTITY) symex$(EXEEXT) diff --git a/src/aa-symex/path_search.cpp b/src/aa-symex/path_search.cpp deleted file mode 100644 index 5bfa680177f..00000000000 --- a/src/aa-symex/path_search.cpp +++ /dev/null @@ -1,517 +0,0 @@ -/*******************************************************************\ - -Module: Path-based Symbolic Execution - -Author: Daniel Kroening, kroening@kroening.com - Alex Horn, alex.horn@cs.ox.ac.uk - -\*******************************************************************/ - -#include -#include - -#include -#include - -#include -#include - -#include "path_search.h" - -#ifdef PATH_SYMEX_FORK -// we've already check that the platform is (mostly) POSIX-compliant -#include -#endif - -/*******************************************************************\ - -Function: path_searcht::operator() - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -path_searcht::resultt path_searcht::operator()( - const goto_functionst &goto_functions) -{ -#ifdef PATH_SYMEX_FORK - // Disable output because there is no meaningful way - // to write text when multiple path_search processes - // run concurrently. This could be remedied by piping - // to individual files or inter-process communication, - // a performance bottleneck, however. - null_message_handlert null_message; - set_message_handler(null_message); -#endif - - locst locs(ns); - var_mapt var_map(ns); - - locs.build(goto_functions); - - // this is the container for the history-forest - path_symex_historyt history; - - queue.push_back(initial_state(var_map, locs, history)); - - // set up the statistics - number_of_instructions=0; - number_of_dropped_states=0; - number_of_paths=0; - number_of_VCCs=0; - number_of_VCCs_after_simplification=0; - number_of_failed_properties=0; - number_of_fast_forward_steps=0; - - // stop the time - start_time=current_time(); - - initialize_property_map(goto_functions); - - while(!queue.empty()) - { - // Pick a state from the queue, - // according to some heuristic. - queuet::iterator state=pick_state(); - - // fast forwarding required? - if(state->is_lazy()) - { - assert(state->is_executable()); - assert(state->history.is_nil()); - - // keep allocated memory, this is faster than - // instantiating a new empty vector and map - history.clear(); - var_map.clear(); - state->history=path_symex_step_reft(history); - - // restore all fields of a lazy state by symbolic - // execution along previously recorded branches - const queuet::size_type queue_size=queue.size(); - do - { - number_of_fast_forward_steps++; - - path_symex(*state, queue); -#ifdef PATH_SYMEX_OUTPUT - status() << "Fast forward thread " << state->get_current_thread() - << "/" << state->threads.size() - << " PC " << state->pc() << messaget::eom; -#endif - } - while(state->is_lazy() && state->is_executable()); - assert(queue.size() == queue_size); - } - - // TODO: check lazy states before fast forwarding, or perhaps it - // is better to even check before inserting into queue - if(drop_state(*state)) - { - number_of_dropped_states++; - queue.erase(state); - continue; - } - - if(!state->is_executable()) - { - queue.erase(state); - continue; - } - - // count only executable instructions - number_of_instructions++; - -#ifdef PATH_SYMEX_OUTPUT - status() << "Queue " << queue.size() - << " thread " << state->get_current_thread() - << "/" << state->threads.size() - << " PC " << state->pc() << messaget::eom; -#endif - - // an error, possibly? - if(state->get_instruction()->is_assert()) - { - if(show_vcc) - do_show_vcc(*state); - else - { - check_assertion(*state); - - // all assertions failed? - if(number_of_failed_properties==property_map.size()) - break; - } - } - -#ifdef PATH_SYMEX_FORK - if(try_await()) - { - debug() << "Child process has terminated " - "so exit parent" << messaget::eom; - break; - } -#endif - - // execute and record whether a "branch" occurred - const queuet::size_type queue_size = queue.size(); - path_symex(*state, queue); - - assert(queue_size <= queue.size()); - number_of_paths += (queue.size() - queue_size); - } - -#ifdef PATH_SYMEX_FORK - int exit_status=await(); - if(exit_status==0 && number_of_failed_properties!=0) - { - // the eldest child process (if any) reports found bugs - report_statistics(); - return UNSAFE; - } - else - { - // either a child found and reported a bug or - // the parent's search partition is safe - switch(exit_status) - { - case 0: return SAFE; - case 10: return UNSAFE; - default: return ERROR; - } - } -#else - report_statistics(); - - return number_of_failed_properties==0?SAFE:UNSAFE; -#endif -} - -#ifdef PATH_SYMEX_FORK -/*******************************************************************\ - -Function: path_searcht::await() - - Inputs: - - Outputs: returns zero if and only if every child process succeeds; - otherwise, the error of exactly one child is returned - - Purpose: POSIX-compliant (possibly blocking) wait on child - processes, writes to error() if anything goes wrong; - any earlier calls to try_await() do not affect await() - -\*******************************************************************/ - -int path_searcht::await() -{ - int status; - for(;;) - { - // a process' entries for its child processes are deleted after - // the first call to waitpid(). When waitpid() is called again - // it returns -1 and errno is set to ECHILD. - pid_t pid=wait(&status); - if(pid==-1) - { - if(errno==ECHILD) - break; // no more child processes - } - else - { - if(!WIFEXITED(status) || WEXITSTATUS(status)!=0) - { - debug() << "PID " << pid << " failed, return code " - << WEXITSTATUS(status) << messaget::eom; - - return WEXITSTATUS(status); - } - } - } - - return 0; -} - -/*******************************************************************\ - -Function: path_searcht::try_await() - - Inputs: - - Outputs: returns true if and only if at least one child process - has terminated - - Purpose: POSIX-compliant nonblocking wait on child processes, - child's status is preserved for await() function - -\*******************************************************************/ - -bool path_searcht::try_await() -{ - int status; - pid_t pid=waitpid(-1, &status, WNOHANG | WNOWAIT); - return pid!=-1; -} -#endif - -/*******************************************************************\ - -Function: path_searcht::report_statistics - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_searcht::report_statistics() -{ - // report a bit - - status() << "Number of instructions: " - << number_of_instructions << messaget::eom; - - status() << "Number of dropped states: " - << number_of_dropped_states << messaget::eom; - - status() << "Number of paths: " - << number_of_paths << messaget::eom; - - status() << "Number of fast forward steps: " - << number_of_fast_forward_steps << messaget::eom; - - status() << "Generated " << number_of_VCCs << " VCC(s), " - << number_of_VCCs_after_simplification - << " remaining after simplification" - << messaget::eom; - - time_periodt total_time=current_time()-start_time; - status() << "Runtime: " << total_time << "s total, " - << sat_time << "s SAT" << messaget::eom; -} - -/*******************************************************************\ - -Function: path_searcht::pick_state - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -path_searcht::queuet::iterator path_searcht::pick_state() -{ - // Picking the first one is a DFS. - return queue.begin(); -} - -/*******************************************************************\ - -Function: path_searcht::do_show_vcc - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_searcht::do_show_vcc(statet &state) -{ - // keep statistics - number_of_VCCs++; - - const goto_programt::instructiont &instruction= - *state.get_instruction(); - - mstreamt &out=result(); - - if(instruction.source_location.is_not_nil()) - out << instruction.source_location << '\n'; - - if(instruction.source_location.get_comment()!="") - out << instruction.source_location.get_comment() << '\n'; - - unsigned count=1; - - std::vector steps; - state.history.build_history(steps); - - for(const auto &step_ref : steps) - { - if(step_ref->guard.is_not_nil()) - { - std::string string_value=from_expr(ns, "", step_ref->guard); - out << "{-" << count << "} " << string_value << '\n'; - count++; - } - - if(step_ref->ssa_rhs.is_not_nil()) - { - equal_exprt equality(step_ref->ssa_lhs, step_ref->ssa_rhs); - std::string string_value=from_expr(ns, "", equality); - out << "{-" << count << "} " << string_value << '\n'; - count++; - } - } - - out << "|--------------------------" << '\n'; - - exprt assertion=state.read(instruction.guard); - - out << "{" << 1 << "} " - << from_expr(ns, "", assertion) << '\n'; - - if(!assertion.is_true()) - number_of_VCCs_after_simplification++; - - out << eom; -} - -/*******************************************************************\ - -Function: path_searcht::drop_state - - Inputs: - - Outputs: - - Purpose: decide whether to drop a state - -\*******************************************************************/ - -bool path_searcht::drop_state(const statet &state) const -{ - // depth limit - if(depth_limit_set && state.get_depth()>depth_limit) - return true; - - // context bound - if(context_bound_set && state.get_no_thread_interleavings()>context_bound) - return true; - - - // unwinding limit -- loops - if(unwind_limit_set && state.get_instruction()->is_backwards_goto()) - { - for(const auto &loop_info : state.unwinding_map) - if(loop_info.second>unwind_limit) - return true; - } - - // unwinding limit -- recursion - if(unwind_limit_set && state.get_instruction()->is_function_call()) - { - for(const auto &rec_info : state.recursion_map) - if(rec_info.second>unwind_limit) - return true; - } - - return false; -} - -/*******************************************************************\ - -Function: path_searcht::check_assertion - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_searcht::check_assertion(statet &state) -{ - // keep statistics - number_of_VCCs++; - - const goto_programt::instructiont &instruction= - *state.get_instruction(); - - irep_idt property_name=instruction.source_location.get_property_id(); - property_entryt &property_entry=property_map[property_name]; - - if(property_entry.status==FAILURE) - return; // already failed - else if(property_entry.status==NOT_REACHED) - property_entry.status=SUCCESS; // well, for now! - - // the assertion in SSA - exprt assertion= - state.read(instruction.guard); - - if(assertion.is_true()) - return; // no error, trivially - - // keep statistics - number_of_VCCs_after_simplification++; - - status() << "Checking property " << property_name << eom; - - // take the time - absolute_timet sat_start_time=current_time(); - - satcheckt satcheck; - bv_pointerst bv_pointers(ns, satcheck); - - satcheck.set_message_handler(get_message_handler()); - bv_pointers.set_message_handler(get_message_handler()); - - if(!state.check_assertion(bv_pointers)) - { - build_goto_trace(state, bv_pointers, property_entry.error_trace); - property_entry.status=FAILURE; - number_of_failed_properties++; - } - - sat_time+=current_time()-sat_start_time; -} - -/*******************************************************************\ - -Function: path_searcht::initialize_property_map - - Inputs: - - Outputs: - - Purpose: - -\*******************************************************************/ - -void path_searcht::initialize_property_map( - const goto_functionst &goto_functions) -{ - forall_goto_functions(it, goto_functions) - if(!it->second.is_inlined()) - { - const goto_programt &goto_program=it->second.body; - - forall_goto_program_instructions(i_it, goto_program) - { - if(!i_it->is_assert()) - continue; - - const source_locationt &source_location=i_it->source_location; - - irep_idt property_name=source_location.get_property_id(); - - property_entryt &property_entry=property_map[property_name]; - property_entry.status=NOT_REACHED; - property_entry.description=source_location.get_comment(); - property_entry.source_location=source_location; - } - } -} diff --git a/src/aa-symex/path_search.h b/src/aa-symex/path_search.h deleted file mode 100644 index 51c67ac93f0..00000000000 --- a/src/aa-symex/path_search.h +++ /dev/null @@ -1,119 +0,0 @@ -/*******************************************************************\ - -Module: Path-based Symbolic Execution - -Author: Daniel Kroening, kroening@kroening.com - Alex Horn, alex.horn@cs.ox.ac.uk - -\*******************************************************************/ - -#ifndef CPROVER_AA_SYMEX_PATH_SEARCH_H -#define CPROVER_AA_SYMEX_PATH_SEARCH_H - -#include - -#include - -#include - -class path_searcht:public safety_checkert -{ -public: - explicit path_searcht(const namespacet &_ns): - safety_checkert(_ns), - show_vcc(false), - depth_limit_set(false), // no limit - context_bound_set(false), - unwind_limit_set(false) - { - } - - virtual resultt operator()( - const goto_functionst &goto_functions); - - void set_depth_limit(unsigned limit) - { - depth_limit_set=true; - depth_limit=limit; - } - - void set_context_bound(unsigned limit) - { - context_bound_set=true; - context_bound=limit; - } - - void set_unwind_limit(unsigned limit) - { - unwind_limit_set=true; - unwind_limit=limit; - } - - bool show_vcc; - - // statistics - unsigned number_of_instructions; - unsigned number_of_dropped_states; - unsigned number_of_paths; - unsigned number_of_VCCs; - unsigned number_of_VCCs_after_simplification; - unsigned number_of_failed_properties; - unsigned number_of_fast_forward_steps; - absolute_timet start_time; - time_periodt sat_time; - - enum statust { NOT_REACHED, SUCCESS, FAILURE }; - - struct property_entryt - { - statust status; - irep_idt description; - goto_tracet error_trace; - source_locationt source_location; - - bool is_success() const { return status==SUCCESS; } - bool is_failure() const { return status==FAILURE; } - bool is_not_reached() const { return status==NOT_REACHED; } - }; - - typedef std::map property_mapt; - property_mapt property_map; - -protected: -#ifdef PATH_SYMEX_FORK - // blocks until child processes have terminated - int await(); - - // returns whether at least one child process has terminated - bool try_await(); -#endif - - typedef path_symex_statet statet; - - // State queue. Iterators are stable. - // The states most recently executed are at the head. - typedef std::list queuet; - queuet queue; - - // search heuristic - queuet::iterator pick_state(); - - bool execute(queuet::iterator state, const namespacet &); - - void check_assertion(statet &state); - void do_show_vcc(statet &state); - - bool drop_state(const statet &state) const; - - void report_statistics(); - - void initialize_property_map( - const goto_functionst &goto_functions); - - unsigned depth_limit; - unsigned context_bound; - unsigned unwind_limit; - bool depth_limit_set, context_bound_set, unwind_limit_set; -}; - -#endif // CPROVER_AA_SYMEX_PATH_SEARCH_H From fdd81210c9b1e98fa6c1085fc0ef7a13cbc2b9af Mon Sep 17 00:00:00 2001 From: Vlastimil Zeman Date: Mon, 27 Feb 2017 13:48:31 +0000 Subject: [PATCH 20/59] Fix failing travis tests after removal of aa-symex. --- .travis.yml | 2 +- src/Makefile | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6af73e31878..e8e19bc01ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,4 +47,4 @@ script: make -C src minisat2-download && make -C src CXX=$COMPILER CXXFLAGS="-Wall -O2 -g -Werror -Wno-deprecated-register -pedantic -Wno-sign-compare" -j2 && env UBSAN_OPTIONS=print_stacktrace=1 make -C regression test && - make -C src CXX=$COMPILER CXXFLAGS=$FLAGS -j2 aa-symex.dir cegis.dir clobber.dir memory-models.dir musketeer.dir + make -C src CXX=$COMPILER CXXFLAGS=$FLAGS -j2 cegis.dir clobber.dir memory-models.dir musketeer.dir diff --git a/src/Makefile b/src/Makefile index 7b9e3a1d446..3a452b7fe09 100644 --- a/src/Makefile +++ b/src/Makefile @@ -44,8 +44,6 @@ symex.dir: languages goto-programs.dir pointer-analysis.dir \ goto-symex.dir linking.dir analyses.dir solvers.dir \ path-symex.dir goto-instrument.dir -aa-symex.dir: symex.dir aa-path-symex.dir - # building for a particular directory $(patsubst %, %.dir, $(DIRS)): From 895f8a69514a29da293225f51fb60590571ee0cd Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 24 Oct 2016 12:27:56 +0100 Subject: [PATCH 21/59] Skip already-loaded Java classes --- src/java_bytecode/java_bytecode_convert_class.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/java_bytecode/java_bytecode_convert_class.cpp b/src/java_bytecode/java_bytecode_convert_class.cpp index 8d42611bfe0..b62c5746765 100644 --- a/src/java_bytecode/java_bytecode_convert_class.cpp +++ b/src/java_bytecode/java_bytecode_convert_class.cpp @@ -75,6 +75,13 @@ Function: java_bytecode_convert_classt::convert void java_bytecode_convert_classt::convert(const classt &c) { + std::string qualified_classname="java::"+id2string(c.name); + if(symbol_table.has_symbol(qualified_classname)) + { + debug() << "Skip class " << c.name << " (already loaded)" << eom; + return; + } + class_typet class_type; class_type.set_tag(c.name); @@ -107,7 +114,7 @@ void java_bytecode_convert_classt::convert(const classt &c) symbolt new_symbol; new_symbol.base_name=c.name; new_symbol.pretty_name=c.name; - new_symbol.name="java::"+id2string(c.name); + new_symbol.name=qualified_classname; class_type.set(ID_name, new_symbol.name); new_symbol.type=class_type; new_symbol.mode=ID_java; From 777d52e35548d2add1b46fb468b3534e19b4b2f6 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 1 Nov 2016 13:48:01 +0000 Subject: [PATCH 22/59] Convert Java methods only when they have a caller This means that library methods, for example, will often not be converted. For the time being virtual methods calls are handled simply, assuming that any class we know of that provides an override might be called. --- .../java_bytecode_convert_class.cpp | 35 ++++++--- .../java_bytecode_convert_class.h | 6 +- .../java_bytecode_convert_method.cpp | 57 +++++++++++++-- .../java_bytecode_convert_method.h | 12 ++- .../java_bytecode_convert_method_class.h | 12 ++- src/java_bytecode/java_bytecode_language.cpp | 73 ++++++++++++++++++- src/java_bytecode/java_entry_point.cpp | 8 +- src/java_bytecode/java_entry_point.h | 3 +- 8 files changed, 179 insertions(+), 27 deletions(-) diff --git a/src/java_bytecode/java_bytecode_convert_class.cpp b/src/java_bytecode/java_bytecode_convert_class.cpp index b62c5746765..2036bcd9bce 100644 --- a/src/java_bytecode/java_bytecode_convert_class.cpp +++ b/src/java_bytecode/java_bytecode_convert_class.cpp @@ -27,11 +27,13 @@ class java_bytecode_convert_classt:public messaget symbol_tablet &_symbol_table, message_handlert &_message_handler, bool _disable_runtime_checks, - size_t _max_array_length): + size_t _max_array_length, + lazy_methodst& _lm): messaget(_message_handler), symbol_table(_symbol_table), disable_runtime_checks(_disable_runtime_checks), - max_array_length(_max_array_length) + max_array_length(_max_array_length), + lazy_methods(_lm) { } @@ -52,6 +54,7 @@ class java_bytecode_convert_classt:public messaget symbol_tablet &symbol_table; const bool disable_runtime_checks; const size_t max_array_length; + lazy_methodst &lazy_methods; // conversion void convert(const classt &c); @@ -81,7 +84,7 @@ void java_bytecode_convert_classt::convert(const classt &c) debug() << "Skip class " << c.name << " (already loaded)" << eom; return; } - + class_typet class_type; class_type.set_tag(c.name); @@ -135,13 +138,19 @@ void java_bytecode_convert_classt::convert(const classt &c) // now do methods for(const auto &method : c.methods) - java_bytecode_convert_method( - *class_symbol, - method, - symbol_table, - get_message_handler(), - disable_runtime_checks, - max_array_length); + { + const irep_idt method_identifier= + id2string(qualified_classname)+ + "."+id2string(method.name)+ + ":"+method.signature; + java_bytecode_convert_method_lazy( + *class_symbol,method_identifier,method,symbol_table); + lazy_methods[method_identifier]= + std::make_pair(class_symbol,&method); + } + //java_bytecode_convert_method( + // *class_symbol, method, symbol_table, get_message_handler(), + // disable_runtime_checks, max_array_length); // is this a root class? if(c.extends.empty()) @@ -329,13 +338,15 @@ bool java_bytecode_convert_class( symbol_tablet &symbol_table, message_handlert &message_handler, bool disable_runtime_checks, - size_t max_array_length) + size_t max_array_length, + lazy_methodst &lazy_methods) { java_bytecode_convert_classt java_bytecode_convert_class( symbol_table, message_handler, disable_runtime_checks, - max_array_length); + max_array_length, + lazy_methods); try { diff --git a/src/java_bytecode/java_bytecode_convert_class.h b/src/java_bytecode/java_bytecode_convert_class.h index ffaaf6e34da..8c1dccc02f5 100644 --- a/src/java_bytecode/java_bytecode_convert_class.h +++ b/src/java_bytecode/java_bytecode_convert_class.h @@ -14,11 +14,15 @@ Author: Daniel Kroening, kroening@kroening.com #include "java_bytecode_parse_tree.h" +typedef std::map > + lazy_methodst; + bool java_bytecode_convert_class( const java_bytecode_parse_treet &parse_tree, symbol_tablet &symbol_table, message_handlert &message_handler, bool disable_runtime_checks, - size_t max_array_length); + size_t max_array_length, + lazy_methodst &); #endif // CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_CONVERT_CLASS_H diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index 54412747708..652547b9def 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -20,6 +20,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include #include #include "java_bytecode_convert_method.h" @@ -181,6 +182,35 @@ const exprt java_bytecode_convert_methodt::variable( } } +void java_bytecode_convert_method_lazy( + const symbolt& class_symbol, + const irep_idt method_identifier, + const java_bytecode_parse_treet::methodt &m, + symbol_tablet& symbol_table) +{ + symbolt method_symbol; + typet member_type=java_type_from_string(m.signature); + + method_symbol.name=method_identifier; + method_symbol.base_name=m.base_name; + method_symbol.mode=ID_java; + method_symbol.location=m.source_location; + method_symbol.location.set_function(method_identifier); + + if(method_symbol.base_name=="") + { + method_symbol.pretty_name=id2string(class_symbol.pretty_name)+"."+ + id2string(class_symbol.base_name)+"()"; + member_type.set(ID_constructor,true); + } + else + method_symbol.pretty_name=id2string(class_symbol.pretty_name)+"."+ + id2string(m.base_name)+"()"; + + method_symbol.type=member_type; + symbol_table.add(method_symbol); +} + /*******************************************************************\ Function: java_bytecode_convert_methodt::convert @@ -347,10 +377,10 @@ void java_bytecode_convert_methodt::convert( if((!m.is_abstract) && (!m.is_native)) method_symbol.value=convert_instructions(m, code_type); - // do we have the method symbol already? + // Replace the existing stub symbol with the real deal: const auto s_it=symbol_table.symbols.find(method.get_name()); - if(s_it!=symbol_table.symbols.end()) - symbol_table.symbols.erase(s_it); // erase, we stubbed it + assert(s_it!=symbol_table.symbols.end()); + symbol_table.symbols.erase(s_it); symbol_table.add(method_symbol); } @@ -1113,12 +1143,25 @@ codet java_bytecode_convert_methodt::convert_instructions( symbol_table.add(symbol); } + needed_methods.push_back(arg0.get(ID_identifier)); + if(is_virtual) { // dynamic binding assert(use_this); assert(!call.arguments().empty()); call.function()=arg0; + const auto& call_class=arg0.get(ID_C_class); + assert(call_class!=irep_idt()); + const auto& call_basename=arg0.get(ID_component_name); + assert(call_basename!=irep_idt()); + auto child_classes=class_hierarchy.get_children_trans(call_class); + for(const auto& child_class : child_classes) + { + auto methodid=id2string(child_class)+"."+id2string(call_basename); + if(symbol_table.has_symbol(methodid)) + needed_methods.push_back(methodid); + } } else { @@ -2144,13 +2187,17 @@ void java_bytecode_convert_method( symbol_tablet &symbol_table, message_handlert &message_handler, bool disable_runtime_checks, - size_t max_array_length) + size_t max_array_length, + std::vector& needed_methods, + const class_hierarchyt& ch) { java_bytecode_convert_methodt java_bytecode_convert_method( symbol_table, message_handler, disable_runtime_checks, - max_array_length); + max_array_length, + needed_methods, + ch); java_bytecode_convert_method(class_symbol, method); } diff --git a/src/java_bytecode/java_bytecode_convert_method.h b/src/java_bytecode/java_bytecode_convert_method.h index 8945af95bd1..327bfd09932 100644 --- a/src/java_bytecode/java_bytecode_convert_method.h +++ b/src/java_bytecode/java_bytecode_convert_method.h @@ -14,12 +14,22 @@ Author: Daniel Kroening, kroening@kroening.com #include "java_bytecode_parse_tree.h" +class class_hierarchyt; + void java_bytecode_convert_method( const symbolt &class_symbol, const java_bytecode_parse_treet::methodt &, symbol_tablet &symbol_table, message_handlert &message_handler, bool disable_runtime_checks, - size_t max_array_length); + size_t max_array_length, + std::vector& needed_methods, + const class_hierarchyt&); + +void java_bytecode_convert_method_lazy( + const symbolt &class_symbol, + const irep_idt method_identifier, + const java_bytecode_parse_treet::methodt &, + symbol_tablet &symbol_table); #endif // CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_CONVERT_METHOD_H diff --git a/src/java_bytecode/java_bytecode_convert_method_class.h b/src/java_bytecode/java_bytecode_convert_method_class.h index 8c0e708a530..30d0d974646 100644 --- a/src/java_bytecode/java_bytecode_convert_method_class.h +++ b/src/java_bytecode/java_bytecode_convert_method_class.h @@ -15,12 +15,14 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include "java_bytecode_parse_tree.h" +#include "java_bytecode_convert_class.h" #include #include class symbol_tablet; class symbolt; +class class_hierarchyt; class java_bytecode_convert_methodt:public messaget { @@ -29,11 +31,15 @@ class java_bytecode_convert_methodt:public messaget symbol_tablet &_symbol_table, message_handlert &_message_handler, bool _disable_runtime_checks, - size_t _max_array_length): + size_t _max_array_length, + std::vector& _needed_methods, + const class_hierarchyt& _ch): messaget(_message_handler), symbol_table(_symbol_table), disable_runtime_checks(_disable_runtime_checks), - max_array_length(_max_array_length) + max_array_length(_max_array_length), + needed_methods(_needed_methods), + class_hierarchy(_ch) { } @@ -52,6 +58,8 @@ class java_bytecode_convert_methodt:public messaget symbol_tablet &symbol_table; const bool disable_runtime_checks; const size_t max_array_length; + std::vector& needed_methods; + const class_hierarchyt& class_hierarchy; irep_idt method_id; irep_idt current_method; diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index 1d9d9f57b41..fb0e19ef487 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -14,8 +14,11 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include + #include "java_bytecode_language.h" #include "java_bytecode_convert_class.h" +#include "java_bytecode_convert_method.h" #include "java_bytecode_internal_additions.h" #include "java_bytecode_typecheck.h" #include "java_entry_point.h" @@ -180,10 +183,15 @@ Function: java_bytecode_languaget::typecheck \*******************************************************************/ + + bool java_bytecode_languaget::typecheck( symbol_tablet &symbol_table, const std::string &module) { + std::map > + lazy_methods; + // first convert all for(java_class_loadert::class_mapt::const_iterator c_it=java_class_loader.class_map.begin(); @@ -200,10 +208,73 @@ bool java_bytecode_languaget::typecheck( symbol_table, get_message_handler(), disable_runtime_checks, - max_user_array_length)) + max_user_array_length, + lazy_methods)) return true; } + // Now incrementally elaborate methods that are reachable from this entry point: + + // Convert-method will need this to find virtual function targets. + class_hierarchyt ch; + ch(symbol_table); + + std::vector worklist1; + std::vector worklist2; + + auto main_function=get_main_symbol(symbol_table,main_class,get_message_handler(),true); + if(main_function.stop_convert) + { + // Failed, mark all functions in the given main class reachable. + const auto& methods=java_class_loader.class_map.at(main_class).parsed_class.methods; + for(const auto& method : methods) + { + const irep_idt methodid="java::"+id2string(main_class)+"."+ + id2string(method.name)+":"+ + id2string(method.signature); + worklist2.push_back(methodid); + } + } + else + worklist2.push_back(main_function.main_function.name); + + std::set already_populated; + while(worklist2.size()!=0) + { + std::swap(worklist1,worklist2); + for(const auto& mname : worklist1) + { + if(!already_populated.insert(mname).second) + continue; + auto findit=lazy_methods.find(mname); + if(findit==lazy_methods.end()) + { + debug() << "Skip " << mname << eom; + continue; + } + debug() << "Lazy methods: elaborate " << mname << eom; + const auto& parsed_method=findit->second; + java_bytecode_convert_method(*parsed_method.first,*parsed_method.second, + symbol_table,get_message_handler(), + disable_runtime_checks,max_user_array_length,worklist2,ch); + } + worklist1.clear(); + } + + // Remove symbols for methods that were declared but never used: + symbol_tablet keep_symbols; + + for(const auto& sym : symbol_table.symbols) + { + if(lazy_methods.count(sym.first) && !already_populated.count(sym.first)) + continue; + keep_symbols.add(sym.second); + } + + debug() << "Lazy methods: removed " << symbol_table.symbols.size() - keep_symbols.symbols.size() << " unreachable methods" << eom; + + symbol_table.swap(keep_symbols); + // now typecheck all if(java_bytecode_typecheck( symbol_table, get_message_handler())) diff --git a/src/java_bytecode/java_entry_point.cpp b/src/java_bytecode/java_entry_point.cpp index dcc3dead0a8..44a59091ba2 100644 --- a/src/java_bytecode/java_entry_point.cpp +++ b/src/java_bytecode/java_entry_point.cpp @@ -327,11 +327,11 @@ void java_record_outputs( } } - main_function_resultt get_main_symbol( symbol_tablet &symbol_table, const irep_idt &main_class, - message_handlert &message_handler) + message_handlert &message_handler, + bool allow_no_body) { symbolt symbol; main_function_resultt res; @@ -415,7 +415,7 @@ main_function_resultt get_main_symbol( } // check if it has a body - if(symbol.value.is_nil()) + if(symbol.value.is_nil() && !allow_no_body) { message.error() << "main method `" << main_class << "' has no body" << messaget::eom; @@ -480,7 +480,7 @@ main_function_resultt get_main_symbol( symbol=symbol_table.symbols.find(*matches.begin())->second; // check if it has a body - if(symbol.value.is_nil()) + if(symbol.value.is_nil() && !allow_no_body) { message.error() << "main method `" << main_class << "' has no body" << messaget::eom; diff --git a/src/java_bytecode/java_entry_point.h b/src/java_bytecode/java_entry_point.h index 7fa562de89a..82071aa26b1 100644 --- a/src/java_bytecode/java_entry_point.h +++ b/src/java_bytecode/java_entry_point.h @@ -28,6 +28,7 @@ typedef struct main_function_resultt get_main_symbol( symbol_tablet &symbol_table, const irep_idt &main_class, - message_handlert &); + message_handlert &, + bool allow_no_body = false); #endif // CPROVER_JAVA_BYTECODE_JAVA_ENTRY_POINT_H From b7a7bfb17a7234d8a35cf2d8e43cba447e0272c7 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 1 Nov 2016 14:19:53 +0000 Subject: [PATCH 23/59] Remove dead global variables When lazy method conversion is in use, they might end up unused. --- src/java_bytecode/java_bytecode_language.cpp | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index fb0e19ef487..fc5ee421343 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -171,6 +171,19 @@ bool java_bytecode_languaget::parse( return false; } +static void gather_needed_globals(const exprt& e, const symbol_tablet& symbol_table, symbol_tablet& needed) +{ + if(e.id()==ID_symbol) + { + const auto& sym=symbol_table.lookup(to_symbol_expr(e).get_identifier()); + if(sym.is_static_lifetime) + needed.add(sym); + } + else + forall_operands(opit,e) + gather_needed_globals(*opit,symbol_table,needed); +} + /*******************************************************************\ Function: java_bytecode_languaget::typecheck @@ -183,8 +196,6 @@ Function: java_bytecode_languaget::typecheck \*******************************************************************/ - - bool java_bytecode_languaget::typecheck( symbol_tablet &symbol_table, const std::string &module) @@ -266,12 +277,16 @@ bool java_bytecode_languaget::typecheck( for(const auto& sym : symbol_table.symbols) { + if(sym.second.is_static_lifetime) + continue; if(lazy_methods.count(sym.first) && !already_populated.count(sym.first)) continue; + if(sym.second.type.id()==ID_code) + gather_needed_globals(sym.second.value,symbol_table,keep_symbols); keep_symbols.add(sym.second); } - debug() << "Lazy methods: removed " << symbol_table.symbols.size() - keep_symbols.symbols.size() << " unreachable methods" << eom; + debug() << "Lazy methods: removed " << symbol_table.symbols.size() - keep_symbols.symbols.size() << " unreachable methods and globals" << eom; symbol_table.swap(keep_symbols); From caf804e4721759dca5953ccea6bb118baf88a440 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 2 Nov 2016 17:02:41 +0000 Subject: [PATCH 24/59] Restrict virtual method targets to known-created types Previously even with lazy method conversion enabled, if we had a caller to A.f and C.f overrides A.f, we would generate a possible call to C.f even if a C is never instantiated in any reachable method. This commit changes that, such that we need *both* a callsite and evidence of a C being constructed to generate the callgraph edge. --- .../java_bytecode_convert_method.cpp | 24 ++- .../java_bytecode_convert_method.h | 1 + .../java_bytecode_convert_method_class.h | 3 + src/java_bytecode/java_bytecode_language.cpp | 156 +++++++++++++++--- 4 files changed, 148 insertions(+), 36 deletions(-) diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index 652547b9def..39d347cdb1c 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -1067,7 +1067,10 @@ codet java_bytecode_convert_methodt::convert_instructions( { if(as_string(arg0.get(ID_identifier)) .find("")!=std::string::npos) + { + needed_classes.insert(classname); code_type.set(ID_constructor, true); + } else code_type.set(ID_java_super_method_call, true); } @@ -1143,30 +1146,19 @@ codet java_bytecode_convert_methodt::convert_instructions( symbol_table.add(symbol); } - needed_methods.push_back(arg0.get(ID_identifier)); - if(is_virtual) { // dynamic binding assert(use_this); assert(!call.arguments().empty()); call.function()=arg0; - const auto& call_class=arg0.get(ID_C_class); - assert(call_class!=irep_idt()); - const auto& call_basename=arg0.get(ID_component_name); - assert(call_basename!=irep_idt()); - auto child_classes=class_hierarchy.get_children_trans(call_class); - for(const auto& child_class : child_classes) - { - auto methodid=id2string(child_class)+"."+id2string(call_basename); - if(symbol_table.has_symbol(methodid)) - needed_methods.push_back(methodid); - } + // Populate needed methods later, once we know what object types can exist. } else { // static binding call.function()=symbol_exprt(arg0.get(ID_identifier), arg0.type()); + needed_methods.push_back(arg0.get(ID_identifier)); } call.function().add_source_location()=loc; @@ -1708,6 +1700,8 @@ codet java_bytecode_convert_methodt::convert_instructions( symbol_exprt symbol_expr(arg0.type()); const auto &field_name=arg0.get_string(ID_component_name); symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name); + if(arg0.type().id()==ID_symbol) + needed_classes.insert(to_symbol_type(arg0.type()).get_identifier()); results[0]=java_bytecode_promotion(symbol_expr); // set $assertionDisabled to false @@ -1725,6 +1719,8 @@ codet java_bytecode_convert_methodt::convert_instructions( symbol_exprt symbol_expr(arg0.type()); const auto &field_name=arg0.get_string(ID_component_name); symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name); + if(arg0.type().id()==ID_symbol) + needed_classes.insert(to_symbol_type(arg0.type()).get_identifier()); c=code_assignt(symbol_expr, op[0]); } else if(statement==patternt("?2?")) // i2c etc. @@ -2189,6 +2185,7 @@ void java_bytecode_convert_method( bool disable_runtime_checks, size_t max_array_length, std::vector& needed_methods, + std::set& needed_classes, const class_hierarchyt& ch) { java_bytecode_convert_methodt java_bytecode_convert_method( @@ -2197,6 +2194,7 @@ void java_bytecode_convert_method( disable_runtime_checks, max_array_length, needed_methods, + needed_classes, ch); java_bytecode_convert_method(class_symbol, method); diff --git a/src/java_bytecode/java_bytecode_convert_method.h b/src/java_bytecode/java_bytecode_convert_method.h index 327bfd09932..b6302161a43 100644 --- a/src/java_bytecode/java_bytecode_convert_method.h +++ b/src/java_bytecode/java_bytecode_convert_method.h @@ -24,6 +24,7 @@ void java_bytecode_convert_method( bool disable_runtime_checks, size_t max_array_length, std::vector& needed_methods, + std::set& needed_classes, const class_hierarchyt&); void java_bytecode_convert_method_lazy( diff --git a/src/java_bytecode/java_bytecode_convert_method_class.h b/src/java_bytecode/java_bytecode_convert_method_class.h index 30d0d974646..8eaf7ac8af5 100644 --- a/src/java_bytecode/java_bytecode_convert_method_class.h +++ b/src/java_bytecode/java_bytecode_convert_method_class.h @@ -33,12 +33,14 @@ class java_bytecode_convert_methodt:public messaget bool _disable_runtime_checks, size_t _max_array_length, std::vector& _needed_methods, + std::set& _needed_classes, const class_hierarchyt& _ch): messaget(_message_handler), symbol_table(_symbol_table), disable_runtime_checks(_disable_runtime_checks), max_array_length(_max_array_length), needed_methods(_needed_methods), + needed_classes(_needed_classes), class_hierarchy(_ch) { } @@ -59,6 +61,7 @@ class java_bytecode_convert_methodt:public messaget const bool disable_runtime_checks; const size_t max_array_length; std::vector& needed_methods; + std::set& needed_classes; const class_hierarchyt& class_hierarchy; irep_idt method_id; diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index fc5ee421343..057859cef04 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -171,6 +171,48 @@ bool java_bytecode_languaget::parse( return false; } +static void get_virtual_method_targets( + const code_function_callt& c, + const std::set& needed_classes, + std::vector& needed_methods, + const symbol_tablet& symbol_table, + const class_hierarchyt& class_hierarchy) +{ + + const auto& called_function=c.function(); + assert(called_function.id()==ID_virtual_function); + + const auto& call_class=called_function.get(ID_C_class); + assert(call_class!=irep_idt()); + const auto& call_basename=called_function.get(ID_component_name); + assert(call_basename!=irep_idt()); + + auto child_classes=class_hierarchy.get_children_trans(call_class); + child_classes.push_back(call_class); + for(const auto& child_class : child_classes) + { + // Program-wide, is this class ever instantiated? + if(!needed_classes.count(child_class)) + continue; + auto methodid=id2string(child_class)+"."+id2string(call_basename); + if(symbol_table.has_symbol(methodid)) + needed_methods.push_back(methodid); + } +} + +static void gather_virtual_callsites(const exprt& e, std::vector& result) +{ + if(e.id()!=ID_code) + return; + const codet& c=to_code(e); + if(c.get_statement()==ID_function_call && + to_code_function_call(c).function().id()==ID_virtual_function) + result.push_back(&to_code_function_call(c)); + else + forall_operands(it,e) + gather_virtual_callsites(*it,result); +} + static void gather_needed_globals(const exprt& e, const symbol_tablet& symbol_table, symbol_tablet& needed) { if(e.id()==ID_symbol) @@ -184,6 +226,48 @@ static void gather_needed_globals(const exprt& e, const symbol_tablet& symbol_ta gather_needed_globals(*opit,symbol_table,needed); } +static void gather_field_types( + const typet& class_type, + const namespacet& ns, + std::set& needed_classes) +{ + const auto& underlying_type=to_struct_type(ns.follow(class_type)); + for(const auto& field : underlying_type.components()) + { + if(field.type().id()==ID_struct || field.type().id()==ID_symbol) + gather_field_types(field.type(),ns,needed_classes); + else if(field.type().id()==ID_pointer) + { + // Skip array primitive pointers, for example: + if(field.type().subtype().id()!=ID_symbol) + continue; + const auto& field_classid=to_symbol_type(field.type().subtype()).get_identifier(); + if(needed_classes.insert(field_classid).second) + gather_field_types(field.type().subtype(),ns,needed_classes); + } + } +} + +static void initialise_needed_classes( + const std::vector& entry_points, + const namespacet& ns, + std::set& needed_classes) +{ + for(const auto& mname : entry_points) + { + const auto& symbol=ns.lookup(mname); + const auto& mtype=to_code_type(symbol.type); + for(const auto& param : mtype.parameters()) + { + if(param.type().id()==ID_pointer) + { + needed_classes.insert(to_symbol_type(param.type().subtype()).get_identifier()); + gather_field_types(param.type().subtype(),ns,needed_classes); + } + } + } +} + /*******************************************************************\ Function: java_bytecode_languaget::typecheck @@ -230,8 +314,8 @@ bool java_bytecode_languaget::typecheck( class_hierarchyt ch; ch(symbol_table); - std::vector worklist1; - std::vector worklist2; + std::vector method_worklist1; + std::vector method_worklist2; auto main_function=get_main_symbol(symbol_table,main_class,get_message_handler(),true); if(main_function.stop_convert) @@ -243,34 +327,60 @@ bool java_bytecode_languaget::typecheck( const irep_idt methodid="java::"+id2string(main_class)+"."+ id2string(method.name)+":"+ id2string(method.signature); - worklist2.push_back(methodid); + method_worklist2.push_back(methodid); } } else - worklist2.push_back(main_function.main_function.name); + method_worklist2.push_back(main_function.main_function.name); - std::set already_populated; - while(worklist2.size()!=0) - { - std::swap(worklist1,worklist2); - for(const auto& mname : worklist1) + std::set needed_classes; + initialise_needed_classes(method_worklist2,namespacet(symbol_table),needed_classes); + + std::set methods_already_populated; + std::vector virtual_callsites; + + bool any_new_methods; + do { + + any_new_methods=false; + while(method_worklist2.size()!=0) { - if(!already_populated.insert(mname).second) - continue; - auto findit=lazy_methods.find(mname); - if(findit==lazy_methods.end()) + std::swap(method_worklist1,method_worklist2); + for(const auto& mname : method_worklist1) { - debug() << "Skip " << mname << eom; - continue; + if(!methods_already_populated.insert(mname).second) + continue; + auto findit=lazy_methods.find(mname); + if(findit==lazy_methods.end()) + { + debug() << "Skip " << mname << eom; + continue; + } + debug() << "Lazy methods: elaborate " << mname << eom; + const auto& parsed_method=findit->second; + java_bytecode_convert_method(*parsed_method.first,*parsed_method.second, + symbol_table,get_message_handler(), + disable_runtime_checks,max_user_array_length, + method_worklist2,needed_classes,ch); + gather_virtual_callsites(symbol_table.lookup(mname).value,virtual_callsites); + any_new_methods=true; } - debug() << "Lazy methods: elaborate " << mname << eom; - const auto& parsed_method=findit->second; - java_bytecode_convert_method(*parsed_method.first,*parsed_method.second, - symbol_table,get_message_handler(), - disable_runtime_checks,max_user_array_length,worklist2,ch); + method_worklist1.clear(); } - worklist1.clear(); - } + + // Given the object types we now know may be created, populate more + // possible virtual function call targets: + + debug() << "Lazy methods: add virtual method targets (" << virtual_callsites.size() << + " callsites)" << eom; + + for(const auto& callsite : virtual_callsites) + { + get_virtual_method_targets(*callsite,needed_classes,method_worklist2, + symbol_table,ch); + } + + } while(any_new_methods); // Remove symbols for methods that were declared but never used: symbol_tablet keep_symbols; @@ -279,7 +389,7 @@ bool java_bytecode_languaget::typecheck( { if(sym.second.is_static_lifetime) continue; - if(lazy_methods.count(sym.first) && !already_populated.count(sym.first)) + if(lazy_methods.count(sym.first) && !methods_already_populated.count(sym.first)) continue; if(sym.second.type.id()==ID_code) gather_needed_globals(sym.second.value,symbol_table,keep_symbols); From 6e1133da85836360375d846c6ee03f05aff64d42 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 21 Nov 2016 15:01:38 +0000 Subject: [PATCH 25/59] Mark all classes in root jar reachable if it doesn't declare a main function --- src/java_bytecode/java_bytecode_language.cpp | 24 ++++++++++++++------ src/java_bytecode/java_bytecode_language.h | 1 + src/java_bytecode/java_class_loader.h | 1 - 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index 057859cef04..dc6c350ba7f 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -150,6 +150,8 @@ bool java_bytecode_languaget::parse( { status() << "JAR file without entry point: loading it all" << eom; java_class_loader.load_entire_jar(path); + for(const auto& kv : java_class_loader.jar_map.at(path).entries) + main_jar_classes.push_back(kv.first); } else java_class_loader.add_jar_file(path); @@ -320,14 +322,22 @@ bool java_bytecode_languaget::typecheck( auto main_function=get_main_symbol(symbol_table,main_class,get_message_handler(),true); if(main_function.stop_convert) { - // Failed, mark all functions in the given main class reachable. - const auto& methods=java_class_loader.class_map.at(main_class).parsed_class.methods; - for(const auto& method : methods) + // Failed, mark all functions in the given main class(es) reachable. + std::vector reachable_classes; + if(!main_class.empty()) + reachable_classes.push_back(main_class); + else + reachable_classes=main_jar_classes; + for(const auto& classname : reachable_classes) { - const irep_idt methodid="java::"+id2string(main_class)+"."+ - id2string(method.name)+":"+ - id2string(method.signature); - method_worklist2.push_back(methodid); + const auto& methods=java_class_loader.class_map.at(classname).parsed_class.methods; + for(const auto& method : methods) + { + const irep_idt methodid="java::"+id2string(classname)+"."+ + id2string(method.name)+":"+ + id2string(method.signature); + method_worklist2.push_back(methodid); + } } } else diff --git a/src/java_bytecode/java_bytecode_language.h b/src/java_bytecode/java_bytecode_language.h index 5937f6f4fd4..36b28682dca 100644 --- a/src/java_bytecode/java_bytecode_language.h +++ b/src/java_bytecode/java_bytecode_language.h @@ -72,6 +72,7 @@ class java_bytecode_languaget:public languaget protected: irep_idt main_class; + std::vector main_jar_classes; java_class_loadert java_class_loader; bool assume_inputs_non_null; // assume inputs variables to be non-null diff --git a/src/java_bytecode/java_class_loader.h b/src/java_bytecode/java_class_loader.h index 4d67b3e7164..b2a4953445a 100644 --- a/src/java_bytecode/java_class_loader.h +++ b/src/java_bytecode/java_class_loader.h @@ -37,7 +37,6 @@ class java_class_loadert:public messaget jar_poolt jar_pool; -protected: class jar_map_entryt { public: From 49bfea4d8b0fb6b8b10e1a1abf09e565a7daa210 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 23 Nov 2016 11:02:34 +0000 Subject: [PATCH 26/59] Add this-parameter before determining needed classes If the given entry point has a this-parameter of type A, that constitutes evidence that virtual callsites might target a class of type A. --- .../java_bytecode_convert_method.cpp | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index 39d347cdb1c..d10cfdec60b 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -207,6 +207,18 @@ void java_bytecode_convert_method_lazy( method_symbol.pretty_name=id2string(class_symbol.pretty_name)+"."+ id2string(m.base_name)+"()"; + // do we need to add 'this' as a parameter? + if(!m.is_static) + { + code_typet &code_type=to_code_type(member_type); + code_typet::parameterst ¶meters=code_type.parameters(); + code_typet::parametert this_p; + const reference_typet object_ref_type(symbol_typet(class_symbol.name)); + this_p.type()=object_ref_type; + this_p.set_this(); + parameters.insert(parameters.begin(), this_p); + } + method_symbol.type=member_type; symbol_table.add(method_symbol); } @@ -227,29 +239,17 @@ void java_bytecode_convert_methodt::convert( const symbolt &class_symbol, const methodt &m) { - typet member_type=java_type_from_string(m.signature); - - assert(member_type.id()==ID_code); - const irep_idt method_identifier= id2string(class_symbol.name)+"."+id2string(m.name)+":"+m.signature; method_id=method_identifier; + const auto& old_sym=symbol_table.lookup(method_identifier); + + typet member_type=old_sym.type; code_typet &code_type=to_code_type(member_type); method_return_type=code_type.return_type(); code_typet::parameterst ¶meters=code_type.parameters(); - // do we need to add 'this' as a parameter? - if(!m.is_static) - { - code_typet::parametert this_p; - const reference_typet object_ref_type( - symbol_typet(class_symbol.name)); - this_p.type()=object_ref_type; - this_p.set_this(); - parameters.insert(parameters.begin(), this_p); - } - variables.clear(); // find parameter names in the local variable table: From e12448b0dfde0b0b37f5f329d451fcabd5f8d431 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 30 Nov 2016 15:38:08 +0000 Subject: [PATCH 27/59] Lazy method conversion: load callee parent classes Previously lazy virtual callsite resolution would assume that in order to call B.f, it is necessary to instantiate a B and call A.f, where A is some parent of B. This commit amends that to allow creation of a C, where C is a subtype of B and does not override f itself, is enough for B.f to be callable. --- src/java_bytecode/java_bytecode_language.cpp | 84 +++++++++++++++++--- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index dc6c350ba7f..8e5ce448b57 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -173,14 +173,29 @@ bool java_bytecode_languaget::parse( return false; } +static irep_idt get_virtual_method_target( + const std::set& needed_classes, + const irep_idt& call_basename, + const irep_idt& classname, + const symbol_tablet& symbol_table) +{ + // Program-wide, is this class ever instantiated? + if(!needed_classes.count(classname)) + return irep_idt(); + auto methodid=id2string(classname)+"."+id2string(call_basename); + if(symbol_table.has_symbol(methodid)) + return methodid; + else + return irep_idt(); +} + static void get_virtual_method_targets( const code_function_callt& c, const std::set& needed_classes, std::vector& needed_methods, - const symbol_tablet& symbol_table, + symbol_tablet& symbol_table, const class_hierarchyt& class_hierarchy) { - const auto& called_function=c.function(); assert(called_function.id()==ID_virtual_function); @@ -189,17 +204,56 @@ static void get_virtual_method_targets( const auto& call_basename=called_function.get(ID_component_name); assert(call_basename!=irep_idt()); + auto old_size=needed_methods.size(); + auto child_classes=class_hierarchy.get_children_trans(call_class); - child_classes.push_back(call_class); for(const auto& child_class : child_classes) { - // Program-wide, is this class ever instantiated? - if(!needed_classes.count(child_class)) - continue; - auto methodid=id2string(child_class)+"."+id2string(call_basename); - if(symbol_table.has_symbol(methodid)) - needed_methods.push_back(methodid); + auto child_method=get_virtual_method_target(needed_classes,call_basename, + child_class,symbol_table); + if(child_method!=irep_idt()) + needed_methods.push_back(child_method); + } + + irep_idt parent_class_id=call_class; + while(1) + { + auto parent_method=get_virtual_method_target(needed_classes,call_basename, + parent_class_id,symbol_table); + if(parent_method!=irep_idt()) + { + needed_methods.push_back(parent_method); + break; + } + else + { + auto findit=class_hierarchy.class_map.find(parent_class_id); + if(findit==class_hierarchy.class_map.end()) + break; + else + { + const auto& entry=findit->second; + if(entry.parents.size()==0) + break; + else + parent_class_id=entry.parents[0]; + } + } } + + if(needed_methods.size()==old_size) + { + // Didn't find any candidate callee. Generate a stub. + std::string stubname=id2string(call_class)+"."+id2string(call_basename); + symbolt symbol; + symbol.name=stubname; + symbol.base_name=call_basename; + symbol.type=c.function().type(); + symbol.value.make_nil(); + symbol.mode=ID_java; + symbol_table.add(symbol); + } + } static void gather_virtual_callsites(const exprt& e, std::vector& result) @@ -253,6 +307,7 @@ static void gather_field_types( static void initialise_needed_classes( const std::vector& entry_points, const namespacet& ns, + const class_hierarchyt& ch, std::set& needed_classes) { for(const auto& mname : entry_points) @@ -263,8 +318,12 @@ static void initialise_needed_classes( { if(param.type().id()==ID_pointer) { - needed_classes.insert(to_symbol_type(param.type().subtype()).get_identifier()); - gather_field_types(param.type().subtype(),ns,needed_classes); + const auto& param_classid=to_symbol_type(param.type().subtype()).get_identifier(); + std::vector class_and_parents=ch.get_parents_trans(param_classid); + class_and_parents.push_back(param_classid); + for(const auto& classid : class_and_parents) + needed_classes.insert(classid); + gather_field_types(param.type().subtype(),ns,needed_classes); } } } @@ -344,7 +403,7 @@ bool java_bytecode_languaget::typecheck( method_worklist2.push_back(main_function.main_function.name); std::set needed_classes; - initialise_needed_classes(method_worklist2,namespacet(symbol_table),needed_classes); + initialise_needed_classes(method_worklist2,namespacet(symbol_table),ch,needed_classes); std::set methods_already_populated; std::vector virtual_callsites; @@ -386,6 +445,7 @@ bool java_bytecode_languaget::typecheck( for(const auto& callsite : virtual_callsites) { + // This will also create a stub if a virtual callsite has no targets. get_virtual_method_targets(*callsite,needed_classes,method_worklist2, symbol_table,ch); } From d20bdc644adc98c740d0c264cac43347f6af429e Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 17 Jan 2017 11:55:35 +0000 Subject: [PATCH 28/59] Always assume String, Class and Object are callable --- src/java_bytecode/java_bytecode_language.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index 8e5ce448b57..1655347f627 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -327,6 +327,13 @@ static void initialise_needed_classes( } } } + + // Also add classes whose instances are magically + // created by the JVM and so won't be spotted by + // looking for constructors and calls as usual: + needed_classes.insert("java::java.lang.String"); + needed_classes.insert("java::java.lang.Class"); + needed_classes.insert("java::java.lang.Object"); } /*******************************************************************\ From 93af0389f44de0ccca8c74e55b4a814073b36794 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 17 Jan 2017 12:01:49 +0000 Subject: [PATCH 29/59] Don't try to call an abstract function --- src/goto-programs/remove_virtual_functions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/goto-programs/remove_virtual_functions.cpp b/src/goto-programs/remove_virtual_functions.cpp index 4b950593aed..c93b50a2500 100644 --- a/src/goto-programs/remove_virtual_functions.cpp +++ b/src/goto-programs/remove_virtual_functions.cpp @@ -339,7 +339,8 @@ void remove_virtual_functionst::get_functions( component_name, functions); - functions.push_back(root_function); + if(root_function.symbol_expr!=symbol_exprt()) + functions.push_back(root_function); } /*******************************************************************\ From 21decbb64ea03022d3986d60e638c6165f40890e Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 25 Jan 2017 15:53:40 +0000 Subject: [PATCH 30/59] Make lazy method loading optional --- .../java_bytecode_convert_class.cpp | 42 +++++++--- .../java_bytecode_convert_class.h | 7 +- .../java_bytecode_convert_method.cpp | 23 +++--- .../java_bytecode_convert_method.h | 25 +++++- .../java_bytecode_convert_method_class.h | 14 ++-- src/java_bytecode/java_bytecode_language.cpp | 76 ++++++++++++++----- src/java_bytecode/java_bytecode_language.h | 17 +++++ src/util/language.h | 9 +++ src/util/language_file.cpp | 16 ++++ src/util/language_file.h | 23 ++++++ 10 files changed, 196 insertions(+), 56 deletions(-) diff --git a/src/java_bytecode/java_bytecode_convert_class.cpp b/src/java_bytecode/java_bytecode_convert_class.cpp index 2036bcd9bce..eb642baa846 100644 --- a/src/java_bytecode/java_bytecode_convert_class.cpp +++ b/src/java_bytecode/java_bytecode_convert_class.cpp @@ -14,6 +14,7 @@ Author: Daniel Kroening, kroening@kroening.com #include "java_root_class.h" #include "java_types.h" #include "java_bytecode_convert_method.h" +#include "java_bytecode_language.h" #include #include @@ -28,12 +29,14 @@ class java_bytecode_convert_classt:public messaget message_handlert &_message_handler, bool _disable_runtime_checks, size_t _max_array_length, - lazy_methodst& _lm): + lazy_methodst& _lm, + lazy_methods_modet _lazy_methods_mode): messaget(_message_handler), symbol_table(_symbol_table), disable_runtime_checks(_disable_runtime_checks), max_array_length(_max_array_length), - lazy_methods(_lm) + lazy_methods(_lm), + lazy_methods_mode(_lazy_methods_mode) { } @@ -55,6 +58,7 @@ class java_bytecode_convert_classt:public messaget const bool disable_runtime_checks; const size_t max_array_length; lazy_methodst &lazy_methods; + lazy_methods_modet lazy_methods_mode; // conversion void convert(const classt &c); @@ -143,14 +147,30 @@ void java_bytecode_convert_classt::convert(const classt &c) id2string(qualified_classname)+ "."+id2string(method.name)+ ":"+method.signature; + // Always run the lazy pre-stage, as it symbol-table + // registers the function. java_bytecode_convert_method_lazy( - *class_symbol,method_identifier,method,symbol_table); - lazy_methods[method_identifier]= - std::make_pair(class_symbol,&method); + *class_symbol, + method_identifier, + method, + symbol_table); + if(lazy_methods_mode==LAZY_METHODS_MODE_EAGER) + { + // Upgrade to a fully-realized symbol now: + java_bytecode_convert_method( + *class_symbol, + method, + symbol_table, + get_message_handler(), + disable_runtime_checks, + max_array_length); + } + else + { + // Wait for our caller to decide what needs elaborating. + lazy_methods[method_identifier]=std::make_pair(class_symbol, &method); + } } - //java_bytecode_convert_method( - // *class_symbol, method, symbol_table, get_message_handler(), - // disable_runtime_checks, max_array_length); // is this a root class? if(c.extends.empty()) @@ -339,14 +359,16 @@ bool java_bytecode_convert_class( message_handlert &message_handler, bool disable_runtime_checks, size_t max_array_length, - lazy_methodst &lazy_methods) + lazy_methodst &lazy_methods, + lazy_methods_modet lazy_methods_mode) { java_bytecode_convert_classt java_bytecode_convert_class( symbol_table, message_handler, disable_runtime_checks, max_array_length, - lazy_methods); + lazy_methods, + lazy_methods_mode); try { diff --git a/src/java_bytecode/java_bytecode_convert_class.h b/src/java_bytecode/java_bytecode_convert_class.h index 8c1dccc02f5..5cc1526a125 100644 --- a/src/java_bytecode/java_bytecode_convert_class.h +++ b/src/java_bytecode/java_bytecode_convert_class.h @@ -13,9 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include "java_bytecode_parse_tree.h" - -typedef std::map > - lazy_methodst; +#include "java_bytecode_language.h" bool java_bytecode_convert_class( const java_bytecode_parse_treet &parse_tree, @@ -23,6 +21,7 @@ bool java_bytecode_convert_class( message_handlert &message_handler, bool disable_runtime_checks, size_t max_array_length, - lazy_methodst &); + lazy_methodst &, + lazy_methods_modet); #endif // CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_CONVERT_CLASS_H diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index d10cfdec60b..6565e91f72e 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -20,7 +20,6 @@ Author: Daniel Kroening, kroening@kroening.com #include #include -#include #include #include "java_bytecode_convert_method.h" @@ -1068,7 +1067,8 @@ codet java_bytecode_convert_methodt::convert_instructions( if(as_string(arg0.get(ID_identifier)) .find("")!=std::string::npos) { - needed_classes.insert(classname); + if(needed_classes) + needed_classes->insert(classname); code_type.set(ID_constructor, true); } else @@ -1158,7 +1158,8 @@ codet java_bytecode_convert_methodt::convert_instructions( { // static binding call.function()=symbol_exprt(arg0.get(ID_identifier), arg0.type()); - needed_methods.push_back(arg0.get(ID_identifier)); + if(needed_methods) + needed_methods->push_back(arg0.get(ID_identifier)); } call.function().add_source_location()=loc; @@ -1700,8 +1701,8 @@ codet java_bytecode_convert_methodt::convert_instructions( symbol_exprt symbol_expr(arg0.type()); const auto &field_name=arg0.get_string(ID_component_name); symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name); - if(arg0.type().id()==ID_symbol) - needed_classes.insert(to_symbol_type(arg0.type()).get_identifier()); + if(needed_classes && arg0.type().id()==ID_symbol) + needed_classes->insert(to_symbol_type(arg0.type()).get_identifier()); results[0]=java_bytecode_promotion(symbol_expr); // set $assertionDisabled to false @@ -1719,8 +1720,8 @@ codet java_bytecode_convert_methodt::convert_instructions( symbol_exprt symbol_expr(arg0.type()); const auto &field_name=arg0.get_string(ID_component_name); symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name); - if(arg0.type().id()==ID_symbol) - needed_classes.insert(to_symbol_type(arg0.type()).get_identifier()); + if(needed_classes && arg0.type().id()==ID_symbol) + needed_classes->insert(to_symbol_type(arg0.type()).get_identifier()); c=code_assignt(symbol_expr, op[0]); } else if(statement==patternt("?2?")) // i2c etc. @@ -2184,9 +2185,8 @@ void java_bytecode_convert_method( message_handlert &message_handler, bool disable_runtime_checks, size_t max_array_length, - std::vector& needed_methods, - std::set& needed_classes, - const class_hierarchyt& ch) + std::vector *needed_methods, + std::set *needed_classes) { java_bytecode_convert_methodt java_bytecode_convert_method( symbol_table, @@ -2194,8 +2194,7 @@ void java_bytecode_convert_method( disable_runtime_checks, max_array_length, needed_methods, - needed_classes, - ch); + needed_classes); java_bytecode_convert_method(class_symbol, method); } diff --git a/src/java_bytecode/java_bytecode_convert_method.h b/src/java_bytecode/java_bytecode_convert_method.h index b6302161a43..145c7a5cc91 100644 --- a/src/java_bytecode/java_bytecode_convert_method.h +++ b/src/java_bytecode/java_bytecode_convert_method.h @@ -23,9 +23,28 @@ void java_bytecode_convert_method( message_handlert &message_handler, bool disable_runtime_checks, size_t max_array_length, - std::vector& needed_methods, - std::set& needed_classes, - const class_hierarchyt&); + std::vector *needed_methods, + std::set *needed_classes); + +// Must provide both the optional parameters or neither. +inline void java_bytecode_convert_method( + const symbolt &class_symbol, + const java_bytecode_parse_treet::methodt &method, + symbol_tablet &symbol_table, + message_handlert &message_handler, + bool disable_runtime_checks, + size_t max_array_length) +{ + java_bytecode_convert_method( + class_symbol, + method, + symbol_table, + message_handler, + disable_runtime_checks, + max_array_length, + nullptr, + nullptr); +} void java_bytecode_convert_method_lazy( const symbolt &class_symbol, diff --git a/src/java_bytecode/java_bytecode_convert_method_class.h b/src/java_bytecode/java_bytecode_convert_method_class.h index 8eaf7ac8af5..96e640ecdf3 100644 --- a/src/java_bytecode/java_bytecode_convert_method_class.h +++ b/src/java_bytecode/java_bytecode_convert_method_class.h @@ -22,7 +22,6 @@ Author: Daniel Kroening, kroening@kroening.com class symbol_tablet; class symbolt; -class class_hierarchyt; class java_bytecode_convert_methodt:public messaget { @@ -32,16 +31,14 @@ class java_bytecode_convert_methodt:public messaget message_handlert &_message_handler, bool _disable_runtime_checks, size_t _max_array_length, - std::vector& _needed_methods, - std::set& _needed_classes, - const class_hierarchyt& _ch): + std::vector *_needed_methods, + std::set *_needed_classes): messaget(_message_handler), symbol_table(_symbol_table), disable_runtime_checks(_disable_runtime_checks), max_array_length(_max_array_length), needed_methods(_needed_methods), - needed_classes(_needed_classes), - class_hierarchy(_ch) + needed_classes(_needed_classes) { } @@ -60,9 +57,8 @@ class java_bytecode_convert_methodt:public messaget symbol_tablet &symbol_table; const bool disable_runtime_checks; const size_t max_array_length; - std::vector& needed_methods; - std::set& needed_classes; - const class_hierarchyt& class_hierarchy; + std::vector *needed_methods; + std::set *needed_classes; irep_idt method_id; irep_idt current_method; diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index 1655347f627..42c6d0bb9ef 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -48,6 +48,12 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd) std::stoi(cmd.get_value("java-max-input-array-length")); if(cmd.isset("java-max-vla-length")) max_user_array_length=std::stoi(cmd.get_value("java-max-vla-length")); + if(cmd.isset("lazy-methods-context-sensitive")) + lazy_methods_mode=LAZY_METHODS_MODE_CONTEXT_SENSITIVE; + else if(cmd.isset("lazy-methods")) + lazy_methods_mode=LAZY_METHODS_MODE_CONTEXT_INSENSITIVE; + else + lazy_methods_mode=LAZY_METHODS_MODE_EAGER; } /*******************************************************************\ @@ -352,9 +358,6 @@ bool java_bytecode_languaget::typecheck( symbol_tablet &symbol_table, const std::string &module) { - std::map > - lazy_methods; - // first convert all for(java_class_loadert::class_mapt::const_iterator c_it=java_class_loader.class_map.begin(); @@ -372,13 +375,30 @@ bool java_bytecode_languaget::typecheck( get_message_handler(), disable_runtime_checks, max_user_array_length, - lazy_methods)) + lazy_methods, + lazy_methods_mode)) return true; } - // Now incrementally elaborate methods that are reachable from this entry point: + // Now incrementally elaborate methods that are reachable from this entry point. + if(lazy_methods_mode==LAZY_METHODS_MODE_CONTEXT_INSENSITIVE) + { + if(do_ci_lazy_method_conversion(symbol_table, lazy_methods)) + return true; + } + + // now typecheck all + if(java_bytecode_typecheck( + symbol_table, get_message_handler())) + return true; + + return false; +} - // Convert-method will need this to find virtual function targets. +bool java_bytecode_languaget::do_ci_lazy_method_conversion( + symbol_tablet &symbol_table, + lazy_methodst &lazy_methods) +{ class_hierarchyt ch; ch(symbol_table); @@ -432,12 +452,17 @@ bool java_bytecode_languaget::typecheck( debug() << "Skip " << mname << eom; continue; } - debug() << "Lazy methods: elaborate " << mname << eom; + debug() << "CI lazy methods: elaborate " << mname << eom; const auto& parsed_method=findit->second; - java_bytecode_convert_method(*parsed_method.first,*parsed_method.second, - symbol_table,get_message_handler(), - disable_runtime_checks,max_user_array_length, - method_worklist2,needed_classes,ch); + java_bytecode_convert_method( + *parsed_method.first, + *parsed_method.second, + symbol_table, + get_message_handler(), + disable_runtime_checks, + max_user_array_length, + &method_worklist2, + &needed_classes); gather_virtual_callsites(symbol_table.lookup(mname).value,virtual_callsites); any_new_methods=true; } @@ -447,7 +472,7 @@ bool java_bytecode_languaget::typecheck( // Given the object types we now know may be created, populate more // possible virtual function call targets: - debug() << "Lazy methods: add virtual method targets (" << virtual_callsites.size() << + debug() << "CI lazy methods: add virtual method targets (" << virtual_callsites.size() << " callsites)" << eom; for(const auto& callsite : virtual_callsites) @@ -473,18 +498,33 @@ bool java_bytecode_languaget::typecheck( keep_symbols.add(sym.second); } - debug() << "Lazy methods: removed " << symbol_table.symbols.size() - keep_symbols.symbols.size() << " unreachable methods and globals" << eom; + debug() << "CI lazy methods: removed " << symbol_table.symbols.size() - keep_symbols.symbols.size() << " unreachable methods and globals" << eom; symbol_table.swap(keep_symbols); - // now typecheck all - if(java_bytecode_typecheck( - symbol_table, get_message_handler())) - return true; - return false; } +void java_bytecode_languaget::lazy_methods_provided(std::set &methods) const +{ + for(const auto &kv : lazy_methods) + methods.insert(kv.first); +} + +void java_bytecode_languaget::convert_lazy_method( + const irep_idt &id, + symbol_tablet &symtab) +{ + const auto &lazy_method_entry=lazy_methods.at(id); + java_bytecode_convert_method( + *lazy_method_entry.first, + *lazy_method_entry.second, + symtab, + get_message_handler(), + disable_runtime_checks, + max_user_array_length); +} + /*******************************************************************\ Function: java_bytecode_languaget::final diff --git a/src/java_bytecode/java_bytecode_language.h b/src/java_bytecode/java_bytecode_language.h index 36b28682dca..750b92aa367 100644 --- a/src/java_bytecode/java_bytecode_language.h +++ b/src/java_bytecode/java_bytecode_language.h @@ -16,6 +16,16 @@ Author: Daniel Kroening, kroening@kroening.com #define MAX_NONDET_ARRAY_LENGTH_DEFAULT 5 +enum lazy_methods_modet +{ + LAZY_METHODS_MODE_EAGER, + LAZY_METHODS_MODE_CONTEXT_INSENSITIVE, + LAZY_METHODS_MODE_CONTEXT_SENSITIVE +}; + +typedef std::map > + lazy_methodst; + class java_bytecode_languaget:public languaget { public: @@ -69,8 +79,13 @@ class java_bytecode_languaget:public languaget std::set extensions() const override; void modules_provided(std::set &modules) override; + virtual void lazy_methods_provided(std::set &) const override; + virtual void convert_lazy_method( + const irep_idt &id, symbol_tablet &) override; protected: + bool do_ci_lazy_method_conversion(symbol_tablet &, lazy_methodst &); + irep_idt main_class; std::vector main_jar_classes; java_class_loadert java_class_loader; @@ -83,6 +98,8 @@ class java_bytecode_languaget:public languaget // - array size for newarray size_t max_nondet_array_length; // maximal length for non-det array creation size_t max_user_array_length; // max size for user code created arrays + lazy_methodst lazy_methods; + lazy_methods_modet lazy_methods_mode; }; languaget *new_java_bytecode_language(); diff --git a/src/util/language.h b/src/util/language.h index edd83471cd5..b19615496ec 100644 --- a/src/util/language.h +++ b/src/util/language.h @@ -49,6 +49,15 @@ class languaget:public messaget virtual void modules_provided(std::set &modules) { } + // add lazy functions provided to set + + virtual void lazy_methods_provided(std::set &methods) const + { } + + // populate a lazy method + virtual void convert_lazy_method(const irep_idt &id, symbol_tablet &) + { } + // final adjustments, e.g., initialization and call to main() virtual bool final( diff --git a/src/util/language_file.cpp b/src/util/language_file.cpp index dffad975c45..5ecbf9b7438 100644 --- a/src/util/language_file.cpp +++ b/src/util/language_file.cpp @@ -65,6 +65,13 @@ void language_filet::get_modules() language->modules_provided(modules); } +void language_filet::convert_lazy_method( + const irep_idt &id, + symbol_tablet &symtab) +{ + language->convert_lazy_method(id, symtab); +} + /*******************************************************************\ Function: language_filest::show_parse @@ -190,8 +197,17 @@ bool language_filest::typecheck(symbol_tablet &symbol_table) it!=filemap.end(); it++) { if(it->second.modules.empty()) + { if(it->second.language->typecheck(symbol_table, "")) return true; + // register lazy methods. + // TODO: learn about modules and generalise this + // to module-providing languages if required. + std::set lazy_method_ids; + it->second.language->lazy_methods_provided(lazy_method_ids); + for(const auto &id : lazy_method_ids) + lazymethodmap[id]=&it->second; + } } // typecheck modules diff --git a/src/util/language_file.h b/src/util/language_file.h index 533e8d5240e..b538c24e84f 100644 --- a/src/util/language_file.h +++ b/src/util/language_file.h @@ -42,6 +42,10 @@ class language_filet void get_modules(); + void convert_lazy_method( + const irep_idt &id, + symbol_tablet &symtab); + language_filet(const language_filet &rhs); language_filet():language(NULL) @@ -57,9 +61,15 @@ class language_filest:public messaget typedef std::map filemapt; filemapt filemap; + // Contains pointers into filemapt! typedef std::map modulemapt; modulemapt modulemap; + // Contains pointers into filemapt! + // This is safe-ish as long as this is std::map. + typedef std::map lazymethodmapt; + lazymethodmapt lazymethodmap; + void clear_files() { filemap.clear(); @@ -75,10 +85,23 @@ class language_filest:public messaget bool interfaces(symbol_tablet &symbol_table); + bool has_lazy_method(const irep_idt &id) + { + return lazymethodmap.count(id); + } + + void convert_lazy_method( + const irep_idt &id, + symbol_tablet &symtab) + { + return lazymethodmap.at(id)->convert_lazy_method(id, symtab); + } + void clear() { filemap.clear(); modulemap.clear(); + lazymethodmap.clear(); } protected: From 2f47cba7332a8cc9e7a4eec50ff71b3134b93ea2 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 6 Feb 2017 11:18:04 +0000 Subject: [PATCH 31/59] Add CBMC lazy-methods parameter TODO: move all Java frontend parameters into something defined on java_bytecode_languaget and have all driver programs gather the frontends' defined parameters. --- src/cbmc/cbmc_parse_options.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cbmc/cbmc_parse_options.h b/src/cbmc/cbmc_parse_options.h index 87e9beb45d2..adc6e2ee517 100644 --- a/src/cbmc/cbmc_parse_options.h +++ b/src/cbmc/cbmc_parse_options.h @@ -56,6 +56,7 @@ class optionst; "(graphml-witness):" \ "(java-max-vla-length):(java-unwind-enum-static)" \ "(localize-faults)(localize-faults-method):" \ + "(lazy-methods)" \ "(fixedbv)(floatbv)(all-claims)(all-properties)" // legacy, and will eventually disappear // NOLINT(whitespace/line_length) class cbmc_parse_optionst: From 311806ecbf6b27ece359e76f8e312410dd2205d5 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Thu, 9 Feb 2017 16:44:27 +0000 Subject: [PATCH 32/59] Document lazy methods --- .../java_bytecode_convert_method.cpp | 19 ++++ src/java_bytecode/java_bytecode_language.cpp | 103 ++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index 6565e91f72e..1cd371c1901 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -181,6 +181,25 @@ const exprt java_bytecode_convert_methodt::variable( } } +/*******************************************************************\ + +Function: java_bytecode_convert_method_lazy + + Inputs: `class_symbol`: class this method belongs to + `method_identifier`: fully qualified method name, including + type signature (e.g. "x.y.z.f:(I)") + `m`: parsed method object to convert + `symbol_table`: global symbol table (will be modified) + + Outputs: + + Purpose: This creates a method symbol in the symtab, but doesn't + actually perform method conversion just yet. The caller + should call java_bytecode_convert_method later to give the + symbol/method a body. + +\*******************************************************************/ + void java_bytecode_convert_method_lazy( const symbolt& class_symbol, const irep_idt method_identifier, diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index 42c6d0bb9ef..310a5ef69dd 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -179,6 +179,27 @@ bool java_bytecode_languaget::parse( return false; } +/*******************************************************************\ + +Function: get_virtual_method_target + + Inputs: `needed_classes`: set of classes that can be instantiated. + Any potential callee not in this set will be ignored. + `call_basename`: unqualified function name with type + signature (e.g. "f:(I)") + `classname`: class name that may define or override a + function named `call_basename`. + `symbol_table`: global symtab + + Outputs: Returns the fully qualified name of `classname`'s definition + of `call_basename` if found and `classname` is present in + `needed_classes`, or irep_idt() otherwise. + + Purpose: Find a virtual callee, if one is defined and the callee type + is known to exist. + +\*******************************************************************/ + static irep_idt get_virtual_method_target( const std::set& needed_classes, const irep_idt& call_basename, @@ -195,6 +216,27 @@ static irep_idt get_virtual_method_target( return irep_idt(); } +/*******************************************************************\ + +Function: get_virtual_method_target + + Inputs: `c`: function call whose potential target functions should + be determined. + `needed_classes`: set of classes that can be instantiated. + Any potential callee not in this set will be ignored. + `symbol_table`: global symtab + `class_hierarchy`: global class hierarchy + + Outputs: Populates `needed_methods` with all possible `c` callees, + taking `needed_classes` into account (virtual function + overrides defined on classes that are not 'needed' are + ignored) + + Purpose: Find possible callees, excluding types that are not known + to be instantiated. + +\*******************************************************************/ + static void get_virtual_method_targets( const code_function_callt& c, const std::set& needed_classes, @@ -262,6 +304,19 @@ static void get_virtual_method_targets( } +/*******************************************************************\ + +Function: gather_virtual_callsites + + Inputs: `e`: expression tree to search + + Outputs: Populates `result` with pointers to each function call + within e that calls a virtual function. + + Purpose: See output + +\*******************************************************************/ + static void gather_virtual_callsites(const exprt& e, std::vector& result) { if(e.id()!=ID_code) @@ -275,6 +330,20 @@ static void gather_virtual_callsites(const exprt& e, std::vector& entry_points, const namespacet& ns, From 49105209d4d7284b7c0094f0ca6aa34e05f17a02 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Thu, 9 Feb 2017 16:55:15 +0000 Subject: [PATCH 33/59] Style fixes --- .../java_bytecode_convert_method.cpp | 5 +- src/java_bytecode/java_bytecode_language.cpp | 98 ++++++++++++------- src/java_bytecode/java_bytecode_language.h | 6 +- 3 files changed, 73 insertions(+), 36 deletions(-) diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index 1cd371c1901..79db9de0f03 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -219,7 +219,7 @@ void java_bytecode_convert_method_lazy( { method_symbol.pretty_name=id2string(class_symbol.pretty_name)+"."+ id2string(class_symbol.base_name)+"()"; - member_type.set(ID_constructor,true); + member_type.set(ID_constructor, true); } else method_symbol.pretty_name=id2string(class_symbol.pretty_name)+"."+ @@ -1171,7 +1171,8 @@ codet java_bytecode_convert_methodt::convert_instructions( assert(use_this); assert(!call.arguments().empty()); call.function()=arg0; - // Populate needed methods later, once we know what object types can exist. + // Populate needed methods later, + // once we know what object types can exist. } else { diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index 310a5ef69dd..c9f1b1771d2 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -257,8 +257,12 @@ static void get_virtual_method_targets( auto child_classes=class_hierarchy.get_children_trans(call_class); for(const auto& child_class : child_classes) { - auto child_method=get_virtual_method_target(needed_classes,call_basename, - child_class,symbol_table); + auto child_method= + get_virtual_method_target( + needed_classes, + call_basename, + child_class, + symbol_table); if(child_method!=irep_idt()) needed_methods.push_back(child_method); } @@ -266,8 +270,12 @@ static void get_virtual_method_targets( irep_idt parent_class_id=call_class; while(1) { - auto parent_method=get_virtual_method_target(needed_classes,call_basename, - parent_class_id,symbol_table); + auto parent_method= + get_virtual_method_target( + needed_classes, + call_basename, + parent_class_id, + symbol_table); if(parent_method!=irep_idt()) { needed_methods.push_back(parent_method); @@ -301,7 +309,6 @@ static void get_virtual_method_targets( symbol.mode=ID_java; symbol_table.add(symbol); } - } /*******************************************************************\ @@ -317,7 +324,9 @@ Function: gather_virtual_callsites \*******************************************************************/ -static void gather_virtual_callsites(const exprt& e, std::vector& result) +static void gather_virtual_callsites( + const exprt& e, + std::vector& result) { if(e.id()!=ID_code) return; @@ -326,8 +335,8 @@ static void gather_virtual_callsites(const exprt& e, std::vector class_and_parents=ch.get_parents_trans(param_classid); + const auto& param_classid= + to_symbol_type(param.type().subtype()).get_identifier(); + std::vector class_and_parents= + ch.get_parents_trans(param_classid); class_and_parents.push_back(param_classid); for(const auto& classid : class_and_parents) needed_classes.insert(classid); - gather_field_types(param.type().subtype(),ns,needed_classes); + gather_field_types(param.type().subtype(), ns, needed_classes); } } } @@ -483,7 +498,8 @@ bool java_bytecode_languaget::typecheck( return true; } - // Now incrementally elaborate methods that are reachable from this entry point. + // Now incrementally elaborate methods + // that are reachable from this entry point. if(lazy_methods_mode==LAZY_METHODS_MODE_CONTEXT_INSENSITIVE) { if(do_ci_lazy_method_conversion(symbol_table, lazy_methods)) @@ -508,7 +524,8 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( std::vector method_worklist1; std::vector method_worklist2; - auto main_function=get_main_symbol(symbol_table,main_class,get_message_handler(),true); + auto main_function= + get_main_symbol(symbol_table, main_class, get_message_handler(), true); if(main_function.stop_convert) { // Failed, mark all functions in the given main class(es) reachable. @@ -519,7 +536,8 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( reachable_classes=main_jar_classes; for(const auto& classname : reachable_classes) { - const auto& methods=java_class_loader.class_map.at(classname).parsed_class.methods; + const auto& methods= + java_class_loader.class_map.at(classname).parsed_class.methods; for(const auto& method : methods) { const irep_idt methodid="java::"+id2string(classname)+"."+ @@ -533,18 +551,22 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( method_worklist2.push_back(main_function.main_function.name); std::set needed_classes; - initialise_needed_classes(method_worklist2,namespacet(symbol_table),ch,needed_classes); + initialise_needed_classes( + method_worklist2, + namespacet(symbol_table), + ch, + needed_classes); std::set methods_already_populated; std::vector virtual_callsites; bool any_new_methods; - do { - + do + { any_new_methods=false; while(method_worklist2.size()!=0) { - std::swap(method_worklist1,method_worklist2); + std::swap(method_worklist1, method_worklist2); for(const auto& mname : method_worklist1) { if(!methods_already_populated.insert(mname).second) @@ -566,7 +588,9 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( max_user_array_length, &method_worklist2, &needed_classes); - gather_virtual_callsites(symbol_table.lookup(mname).value,virtual_callsites); + gather_virtual_callsites( + symbol_table.lookup(mname).value, + virtual_callsites); any_new_methods=true; } method_worklist1.clear(); @@ -575,14 +599,16 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( // Given the object types we now know may be created, populate more // possible virtual function call targets: - debug() << "CI lazy methods: add virtual method targets (" << virtual_callsites.size() << - " callsites)" << eom; + debug() << "CI lazy methods: add virtual method targets (" + << virtual_callsites.size() + << " callsites)" + << eom; for(const auto& callsite : virtual_callsites) { // This will also create a stub if a virtual callsite has no targets. - get_virtual_method_targets(*callsite,needed_classes,method_worklist2, - symbol_table,ch); + get_virtual_method_targets(*callsite, needed_classes, method_worklist2, + symbol_table, ch); } } while(any_new_methods); @@ -594,14 +620,20 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( { if(sym.second.is_static_lifetime) continue; - if(lazy_methods.count(sym.first) && !methods_already_populated.count(sym.first)) + if(lazy_methods.count(sym.first) && + !methods_already_populated.count(sym.first)) + { continue; + } if(sym.second.type.id()==ID_code) - gather_needed_globals(sym.second.value,symbol_table,keep_symbols); + gather_needed_globals(sym.second.value, symbol_table, keep_symbols); keep_symbols.add(sym.second); } - debug() << "CI lazy methods: removed " << symbol_table.symbols.size() - keep_symbols.symbols.size() << " unreachable methods and globals" << eom; + debug() << "CI lazy methods: removed " + << symbol_table.symbols.size() - keep_symbols.symbols.size() + << " unreachable methods and globals" + << eom; symbol_table.swap(keep_symbols); diff --git a/src/java_bytecode/java_bytecode_language.h b/src/java_bytecode/java_bytecode_language.h index 750b92aa367..afdd275ddf6 100644 --- a/src/java_bytecode/java_bytecode_language.h +++ b/src/java_bytecode/java_bytecode_language.h @@ -23,7 +23,11 @@ enum lazy_methods_modet LAZY_METHODS_MODE_CONTEXT_SENSITIVE }; -typedef std::map > +typedef std::pair< + const symbolt*, + const java_bytecode_parse_treet::methodt*> + lazy_method_valuet; +typedef std::map lazy_methodst; class java_bytecode_languaget:public languaget From 9474d563dc07b8fe2763ef72431e4696fa81921b Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Thu, 9 Feb 2017 17:08:15 +0000 Subject: [PATCH 34/59] Add lazy loading tests --- regression/cbmc-java/lazyloading1/A.class | Bin 0 -> 222 bytes regression/cbmc-java/lazyloading1/B.class | Bin 0 -> 222 bytes regression/cbmc-java/lazyloading1/test.class | Bin 0 -> 292 bytes regression/cbmc-java/lazyloading1/test.desc | 8 +++++ regression/cbmc-java/lazyloading1/test.java | 21 +++++++++++++ regression/cbmc-java/lazyloading2/A.class | Bin 0 -> 222 bytes regression/cbmc-java/lazyloading2/B.class | Bin 0 -> 222 bytes regression/cbmc-java/lazyloading2/test.class | Bin 0 -> 310 bytes regression/cbmc-java/lazyloading2/test.desc | 8 +++++ regression/cbmc-java/lazyloading2/test.java | 23 ++++++++++++++ regression/cbmc-java/lazyloading3/A.class | Bin 0 -> 222 bytes regression/cbmc-java/lazyloading3/B.class | Bin 0 -> 222 bytes regression/cbmc-java/lazyloading3/C.class | Bin 0 -> 197 bytes regression/cbmc-java/lazyloading3/D.class | Bin 0 -> 197 bytes regression/cbmc-java/lazyloading3/test.class | Bin 0 -> 296 bytes regression/cbmc-java/lazyloading3/test.desc | 8 +++++ regression/cbmc-java/lazyloading3/test.java | 30 +++++++++++++++++++ 17 files changed, 98 insertions(+) create mode 100644 regression/cbmc-java/lazyloading1/A.class create mode 100644 regression/cbmc-java/lazyloading1/B.class create mode 100644 regression/cbmc-java/lazyloading1/test.class create mode 100644 regression/cbmc-java/lazyloading1/test.desc create mode 100644 regression/cbmc-java/lazyloading1/test.java create mode 100644 regression/cbmc-java/lazyloading2/A.class create mode 100644 regression/cbmc-java/lazyloading2/B.class create mode 100644 regression/cbmc-java/lazyloading2/test.class create mode 100644 regression/cbmc-java/lazyloading2/test.desc create mode 100644 regression/cbmc-java/lazyloading2/test.java create mode 100644 regression/cbmc-java/lazyloading3/A.class create mode 100644 regression/cbmc-java/lazyloading3/B.class create mode 100644 regression/cbmc-java/lazyloading3/C.class create mode 100644 regression/cbmc-java/lazyloading3/D.class create mode 100644 regression/cbmc-java/lazyloading3/test.class create mode 100644 regression/cbmc-java/lazyloading3/test.desc create mode 100644 regression/cbmc-java/lazyloading3/test.java diff --git a/regression/cbmc-java/lazyloading1/A.class b/regression/cbmc-java/lazyloading1/A.class new file mode 100644 index 0000000000000000000000000000000000000000..d6a62ca1ce465a6ae3fc35f9fa702cfa834ca298 GIT binary patch literal 222 zcmZXNy9&ZU5Jm6gVa!WyEd)!oFpZ@MB3OwQihUAS*$@+m8~@8nu3 zOQ{W4iHjO%@ih)$!DeDk=;%Aj!QtNc Vnm$}Ke`uF|tv@Ve*yV=-?*m^uqBqm`X_Sbr8+Ekm=tM6r!7<>R9O5A6#ILZBY z?k_p7_u~m*hK>glEeF1XHlZ<3i&QNL=4gB*SgZ0R3EfRv$ZdU&WOWcx&JHC6Z(r6` zEZ3A-v~jNyqM}hnO`)!EBM>9Vjr$$4#Ipfe)OD%LdK@30-UQ)r^KJ#@ zu}ke_w@&PKW|9?^aBW;F(65`_c5X+`YsJidW-m*#H!+IP3b!%tpc(dtpyI98%A_By zX|l9)O44U7&_s^E0|Hha5fM-*5CiaCXkv-e1G}*2pAV2P5Pq|~C2#H1Xc2xA%}16OcPq|~C2#H1Xc2xB@U16OcPq|~C2#H1Xc2xA%}16OcK literal 0 HcmV?d00001 diff --git a/regression/cbmc-java/lazyloading3/B.class b/regression/cbmc-java/lazyloading3/B.class new file mode 100644 index 0000000000000000000000000000000000000000..9a4ab54d369d7175755e23dfabef5f15440bf383 GIT binary patch literal 222 zcmX^0Z`VEs1_l!bJ}w4k25xo+9(D#^Mg}&U%)HDJJ4Oa(4b3n{1{UZ1lvG9rexJ;| zRKL>Pq|~C2#H1Xc2xB@U16Occ5zb#DL54!6!+VDk(Sy*z4g7E1P33$hZ57`kdu7p zkmU1yy#XxXyU^j;=-KEKND%aBvm{unv`E#OaWXv-jIcaQf*+-Y+|}1uR!0%%?6`-r zt`fOT8*r4osd*;u!h;2y?}dax!$B^JOR$eKnJA2*@l$}f44D6k7ue}Ajkq_NIeUU0 PZS1gGtvO_MnKX2N4w)Zy literal 0 HcmV?d00001 diff --git a/regression/cbmc-java/lazyloading3/D.class b/regression/cbmc-java/lazyloading3/D.class new file mode 100644 index 0000000000000000000000000000000000000000..7e16bd6527d6835776fcc14eb5132a4d94fcf1b2 GIT binary patch literal 197 zcmX^0Z`VEs1_l!bel7-P1|D_>UUmjPMh3FqHk-`6%n~~wS3@(5k%7fI zKP8osf!`-HFV(L!Hz~C!Brz!mD8dz-Us{x$>Xr%OaF(PNm*{0BmL>8quraU$&2wR7 z5CHM@a}x8?_5G8wQj<#<6d0I*mNGCf0x=5%E0hJ)02JW>@??QDNRCx&I|JiJurw!- QWCIII07)(&kBNaB01$#7eEKI~GBKD~_yhb= z#y2)@GV|WfelxS*Kc8O!?r>>P#z_@5)D2G2&}eG36ry{d`{F^N)a@-4!esmC6l$r@ z-DJPX+-`2OH7nu9`kZ(-O@;!R*>=BMy0MqXYT;gr+m(H_F(PPK|Bm2*(m!oDlp{D)`eOP3$G;8oD9r!> literal 0 HcmV?d00001 diff --git a/regression/cbmc-java/lazyloading3/test.desc b/regression/cbmc-java/lazyloading3/test.desc new file mode 100644 index 00000000000..c0011248128 --- /dev/null +++ b/regression/cbmc-java/lazyloading3/test.desc @@ -0,0 +1,8 @@ +CORE +test.class +--lazy-methods --verbosity 10 --function test.main +^EXIT=0$ +^SIGNAL=0$ +elaborate java::A\.f:\(\)V +-- +elaborate java::B\.g:\(\)V diff --git a/regression/cbmc-java/lazyloading3/test.java b/regression/cbmc-java/lazyloading3/test.java new file mode 100644 index 00000000000..6d3129d1261 --- /dev/null +++ b/regression/cbmc-java/lazyloading3/test.java @@ -0,0 +1,30 @@ +// This test checks that because `main` has a parameter of type C, which has a field of type A, +// A::f is considered reachable, but B::g is not. + +public class test +{ + public static void main(C c) + { + c.a.f(); + } +} + +class A +{ + public void f() {} +} + +class B +{ + public void g() {} +} + +class C +{ + A a; +} + +class D +{ + B b; +} From 5c5bd7a43a0033999fc95efe62fed3fa9e561469 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Mon, 13 Feb 2017 11:08:22 +0000 Subject: [PATCH 35/59] Improve code style No functional changes intended --- src/goto-cc/compile.cpp | 6 +- src/goto-programs/get_goto_model.cpp | 4 +- .../java_bytecode_convert_class.cpp | 4 +- .../java_bytecode_convert_method.cpp | 16 +-- .../java_bytecode_convert_method.h | 2 +- src/java_bytecode/java_bytecode_language.cpp | 98 +++++++++---------- src/java_bytecode/java_entry_point.h | 2 +- src/langapi/language_ui.cpp | 4 +- src/util/language_file.cpp | 46 ++++----- src/util/language_file.h | 33 ++++--- 10 files changed, 110 insertions(+), 105 deletions(-) diff --git a/src/goto-cc/compile.cpp b/src/goto-cc/compile.cpp index f900b9824a7..04d50e76f82 100644 --- a/src/goto-cc/compile.cpp +++ b/src/goto-cc/compile.cpp @@ -544,8 +544,8 @@ bool compilet::parse(const std::string &file_name) language_filet language_file; - std::pair - res=language_files.filemap.insert( + std::pair + res=language_files.file_map.insert( std::pair(file_name, language_file)); language_filet &lf=res.first->second; @@ -736,7 +736,7 @@ bool compilet::parse_source(const std::string &file_name) return true; // so we remove it from the list afterwards - language_files.filemap.erase(file_name); + language_files.file_map.erase(file_name); return false; } diff --git a/src/goto-programs/get_goto_model.cpp b/src/goto-programs/get_goto_model.cpp index 5afef435596..02aae876030 100644 --- a/src/goto-programs/get_goto_model.cpp +++ b/src/goto-programs/get_goto_model.cpp @@ -75,8 +75,8 @@ bool get_goto_modelt::operator()(const std::vector &files) return true; } - std::pair - result=language_files.filemap.insert( + std::pair + result=language_files.file_map.insert( std::pair(filename, language_filet())); language_filet &lf=result.first->second; diff --git a/src/java_bytecode/java_bytecode_convert_class.cpp b/src/java_bytecode/java_bytecode_convert_class.cpp index eb642baa846..440b0ce32cf 100644 --- a/src/java_bytecode/java_bytecode_convert_class.cpp +++ b/src/java_bytecode/java_bytecode_convert_class.cpp @@ -29,13 +29,13 @@ class java_bytecode_convert_classt:public messaget message_handlert &_message_handler, bool _disable_runtime_checks, size_t _max_array_length, - lazy_methodst& _lm, + lazy_methodst& _lazy_methods, lazy_methods_modet _lazy_methods_mode): messaget(_message_handler), symbol_table(_symbol_table), disable_runtime_checks(_disable_runtime_checks), max_array_length(_max_array_length), - lazy_methods(_lm), + lazy_methods(_lazy_methods), lazy_methods_mode(_lazy_methods_mode) { } diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index 79db9de0f03..bc12fc77617 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -201,10 +201,10 @@ Function: java_bytecode_convert_method_lazy \*******************************************************************/ void java_bytecode_convert_method_lazy( - const symbolt& class_symbol, - const irep_idt method_identifier, + const symbolt &class_symbol, + const irep_idt &method_identifier, const java_bytecode_parse_treet::methodt &m, - symbol_tablet& symbol_table) + symbol_tablet &symbol_table) { symbolt method_symbol; typet member_type=java_type_from_string(m.signature); @@ -217,12 +217,14 @@ void java_bytecode_convert_method_lazy( if(method_symbol.base_name=="") { - method_symbol.pretty_name=id2string(class_symbol.pretty_name)+"."+ - id2string(class_symbol.base_name)+"()"; + method_symbol.pretty_name= + id2string(class_symbol.pretty_name)+"."+ + id2string(class_symbol.base_name)+"()"; member_type.set(ID_constructor, true); } else - method_symbol.pretty_name=id2string(class_symbol.pretty_name)+"."+ + method_symbol.pretty_name= + id2string(class_symbol.pretty_name)+"."+ id2string(m.base_name)+"()"; // do we need to add 'this' as a parameter? @@ -261,7 +263,7 @@ void java_bytecode_convert_methodt::convert( id2string(class_symbol.name)+"."+id2string(m.name)+":"+m.signature; method_id=method_identifier; - const auto& old_sym=symbol_table.lookup(method_identifier); + const auto &old_sym=symbol_table.lookup(method_identifier); typet member_type=old_sym.type; code_typet &code_type=to_code_type(member_type); diff --git a/src/java_bytecode/java_bytecode_convert_method.h b/src/java_bytecode/java_bytecode_convert_method.h index 145c7a5cc91..68b0dd4e0a8 100644 --- a/src/java_bytecode/java_bytecode_convert_method.h +++ b/src/java_bytecode/java_bytecode_convert_method.h @@ -48,7 +48,7 @@ inline void java_bytecode_convert_method( void java_bytecode_convert_method_lazy( const symbolt &class_symbol, - const irep_idt method_identifier, + const irep_idt &method_identifier, const java_bytecode_parse_treet::methodt &, symbol_tablet &symbol_table); diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index c9f1b1771d2..4512ec97709 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -156,7 +156,7 @@ bool java_bytecode_languaget::parse( { status() << "JAR file without entry point: loading it all" << eom; java_class_loader.load_entire_jar(path); - for(const auto& kv : java_class_loader.jar_map.at(path).entries) + for(const auto &kv : java_class_loader.jar_map.at(path).entries) main_jar_classes.push_back(kv.first); } else @@ -201,10 +201,10 @@ Function: get_virtual_method_target \*******************************************************************/ static irep_idt get_virtual_method_target( - const std::set& needed_classes, - const irep_idt& call_basename, - const irep_idt& classname, - const symbol_tablet& symbol_table) + const std::set &needed_classes, + const irep_idt &call_basename, + const irep_idt &classname, + const symbol_tablet &symbol_table) { // Program-wide, is this class ever instantiated? if(!needed_classes.count(classname)) @@ -238,24 +238,24 @@ Function: get_virtual_method_target \*******************************************************************/ static void get_virtual_method_targets( - const code_function_callt& c, - const std::set& needed_classes, - std::vector& needed_methods, - symbol_tablet& symbol_table, - const class_hierarchyt& class_hierarchy) + const code_function_callt &c, + const std::set &needed_classes, + std::vector &needed_methods, + symbol_tablet &symbol_table, + const class_hierarchyt &class_hierarchy) { - const auto& called_function=c.function(); + const auto &called_function=c.function(); assert(called_function.id()==ID_virtual_function); - const auto& call_class=called_function.get(ID_C_class); + const auto &call_class=called_function.get(ID_C_class); assert(call_class!=irep_idt()); - const auto& call_basename=called_function.get(ID_component_name); + const auto &call_basename=called_function.get(ID_component_name); assert(call_basename!=irep_idt()); auto old_size=needed_methods.size(); auto child_classes=class_hierarchy.get_children_trans(call_class); - for(const auto& child_class : child_classes) + for(const auto &child_class : child_classes) { auto child_method= get_virtual_method_target( @@ -288,8 +288,8 @@ static void get_virtual_method_targets( break; else { - const auto& entry=findit->second; - if(entry.parents.size()==0) + const auto &entry=findit->second; + if(entry.parents.empty()) break; else parent_class_id=entry.parents[0]; @@ -325,12 +325,12 @@ Function: gather_virtual_callsites \*******************************************************************/ static void gather_virtual_callsites( - const exprt& e, - std::vector& result) + const exprt &e, + std::vector &result) { if(e.id()!=ID_code) return; - const codet& c=to_code(e); + const codet &c=to_code(e); if(c.get_statement()==ID_function_call && to_code_function_call(c).function().id()==ID_virtual_function) result.push_back(&to_code_function_call(c)); @@ -354,13 +354,13 @@ Function: gather_needed_globals \*******************************************************************/ static void gather_needed_globals( - const exprt& e, - const symbol_tablet& symbol_table, - symbol_tablet& needed) + const exprt &e, + const symbol_tablet &symbol_table, + symbol_tablet &needed) { if(e.id()==ID_symbol) { - const auto& sym=symbol_table.lookup(to_symbol_expr(e).get_identifier()); + const auto &sym=symbol_table.lookup(to_symbol_expr(e).get_identifier()); if(sym.is_static_lifetime) needed.add(sym); } @@ -387,12 +387,12 @@ Function: gather_field_types \*******************************************************************/ static void gather_field_types( - const typet& class_type, - const namespacet& ns, - std::set& needed_classes) + const typet &class_type, + const namespacet &ns, + std::set &needed_classes) { - const auto& underlying_type=to_struct_type(ns.follow(class_type)); - for(const auto& field : underlying_type.components()) + const auto &underlying_type=to_struct_type(ns.follow(class_type)); + for(const auto &field : underlying_type.components()) { if(field.type().id()==ID_struct || field.type().id()==ID_symbol) gather_field_types(field.type(), ns, needed_classes); @@ -401,7 +401,7 @@ static void gather_field_types( // Skip array primitive pointers, for example: if(field.type().subtype().id()!=ID_symbol) continue; - const auto& field_classid= + const auto &field_classid= to_symbol_type(field.type().subtype()).get_identifier(); if(needed_classes.insert(field_classid).second) gather_field_types(field.type().subtype(), ns, needed_classes); @@ -411,7 +411,7 @@ static void gather_field_types( /*******************************************************************\ -Function: initialise_needed_classes +Function: initialize_needed_classes Inputs: `entry_points`: list of fully-qualified function names that we should assume are reachable @@ -426,26 +426,26 @@ Function: initialise_needed_classes \*******************************************************************/ -static void initialise_needed_classes( - const std::vector& entry_points, - const namespacet& ns, - const class_hierarchyt& ch, - std::set& needed_classes) +static void initialize_needed_classes( + const std::vector &entry_points, + const namespacet &ns, + const class_hierarchyt &ch, + std::set &needed_classes) { - for(const auto& mname : entry_points) + for(const auto &mname : entry_points) { - const auto& symbol=ns.lookup(mname); - const auto& mtype=to_code_type(symbol.type); - for(const auto& param : mtype.parameters()) + const auto &symbol=ns.lookup(mname); + const auto &mtype=to_code_type(symbol.type); + for(const auto ¶m : mtype.parameters()) { if(param.type().id()==ID_pointer) { - const auto& param_classid= + const auto ¶m_classid= to_symbol_type(param.type().subtype()).get_identifier(); std::vector class_and_parents= ch.get_parents_trans(param_classid); class_and_parents.push_back(param_classid); - for(const auto& classid : class_and_parents) + for(const auto &classid : class_and_parents) needed_classes.insert(classid); gather_field_types(param.type().subtype(), ns, needed_classes); } @@ -534,11 +534,11 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( reachable_classes.push_back(main_class); else reachable_classes=main_jar_classes; - for(const auto& classname : reachable_classes) + for(const auto &classname : reachable_classes) { - const auto& methods= + const auto &methods= java_class_loader.class_map.at(classname).parsed_class.methods; - for(const auto& method : methods) + for(const auto &method : methods) { const irep_idt methodid="java::"+id2string(classname)+"."+ id2string(method.name)+":"+ @@ -551,7 +551,7 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( method_worklist2.push_back(main_function.main_function.name); std::set needed_classes; - initialise_needed_classes( + initialize_needed_classes( method_worklist2, namespacet(symbol_table), ch, @@ -567,7 +567,7 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( while(method_worklist2.size()!=0) { std::swap(method_worklist1, method_worklist2); - for(const auto& mname : method_worklist1) + for(const auto &mname : method_worklist1) { if(!methods_already_populated.insert(mname).second) continue; @@ -578,7 +578,7 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( continue; } debug() << "CI lazy methods: elaborate " << mname << eom; - const auto& parsed_method=findit->second; + const auto &parsed_method=findit->second; java_bytecode_convert_method( *parsed_method.first, *parsed_method.second, @@ -604,7 +604,7 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( << " callsites)" << eom; - for(const auto& callsite : virtual_callsites) + for(const auto &callsite : virtual_callsites) { // This will also create a stub if a virtual callsite has no targets. get_virtual_method_targets(*callsite, needed_classes, method_worklist2, @@ -616,7 +616,7 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( // Remove symbols for methods that were declared but never used: symbol_tablet keep_symbols; - for(const auto& sym : symbol_table.symbols) + for(const auto &sym : symbol_table.symbols) { if(sym.second.is_static_lifetime) continue; diff --git a/src/java_bytecode/java_entry_point.h b/src/java_bytecode/java_entry_point.h index 82071aa26b1..e6575734d80 100644 --- a/src/java_bytecode/java_entry_point.h +++ b/src/java_bytecode/java_entry_point.h @@ -29,6 +29,6 @@ main_function_resultt get_main_symbol( symbol_tablet &symbol_table, const irep_idt &main_class, message_handlert &, - bool allow_no_body = false); + bool allow_no_body=false); #endif // CPROVER_JAVA_BYTECODE_JAVA_ENTRY_POINT_H diff --git a/src/langapi/language_ui.cpp b/src/langapi/language_ui.cpp index 8640d735631..95b5d104a4f 100644 --- a/src/langapi/language_ui.cpp +++ b/src/langapi/language_ui.cpp @@ -104,8 +104,8 @@ bool language_uit::parse(const std::string &filename) return true; } - std::pair - result=language_files.filemap.insert( + std::pair + result=language_files.file_map.insert( std::pair(filename, language_filet())); language_filet &lf=result.first->second; diff --git a/src/util/language_file.cpp b/src/util/language_file.cpp index 5ecbf9b7438..46f51564b54 100644 --- a/src/util/language_file.cpp +++ b/src/util/language_file.cpp @@ -67,9 +67,9 @@ void language_filet::get_modules() void language_filet::convert_lazy_method( const irep_idt &id, - symbol_tablet &symtab) + symbol_tablet &symbol_table) { - language->convert_lazy_method(id, symtab); + language->convert_lazy_method(id, symbol_table); } /*******************************************************************\ @@ -86,8 +86,8 @@ Function: language_filest::show_parse void language_filest::show_parse(std::ostream &out) { - for(filemapt::iterator it=filemap.begin(); - it!=filemap.end(); it++) + for(file_mapt::iterator it=file_map.begin(); + it!=file_map.end(); it++) it->second.language->show_parse(out); } @@ -105,8 +105,8 @@ Function: language_filest::parse bool language_filest::parse() { - for(filemapt::iterator it=filemap.begin(); - it!=filemap.end(); it++) + for(file_mapt::iterator it=file_map.begin(); + it!=file_map.end(); it++) { // open file @@ -152,8 +152,8 @@ bool language_filest::typecheck(symbol_tablet &symbol_table) { // typecheck interfaces - for(filemapt::iterator it=filemap.begin(); - it!=filemap.end(); it++) + for(file_mapt::iterator it=file_map.begin(); + it!=file_map.end(); it++) { if(it->second.language->interfaces(symbol_table)) return true; @@ -163,8 +163,8 @@ bool language_filest::typecheck(symbol_tablet &symbol_table) unsigned collision_counter=0; - for(filemapt::iterator fm_it=filemap.begin(); - fm_it!=filemap.end(); fm_it++) + for(file_mapt::iterator fm_it=file_map.begin(); + fm_it!=file_map.end(); fm_it++) { const language_filet::modulest &modules= fm_it->second.modules; @@ -177,7 +177,7 @@ bool language_filest::typecheck(symbol_tablet &symbol_table) // these may collide, and then get renamed std::string module_name=*mo_it; - while(modulemap.find(module_name)!=modulemap.end()) + while(module_map.find(module_name)!=module_map.end()) { module_name=*mo_it+"#"+std::to_string(collision_counter); collision_counter++; @@ -186,15 +186,15 @@ bool language_filest::typecheck(symbol_tablet &symbol_table) language_modulet module; module.file=&fm_it->second; module.name=module_name; - modulemap.insert( + module_map.insert( std::pair(module.name, module)); } } // typecheck files - for(filemapt::iterator it=filemap.begin(); - it!=filemap.end(); it++) + for(file_mapt::iterator it=file_map.begin(); + it!=file_map.end(); it++) { if(it->second.modules.empty()) { @@ -206,14 +206,14 @@ bool language_filest::typecheck(symbol_tablet &symbol_table) std::set lazy_method_ids; it->second.language->lazy_methods_provided(lazy_method_ids); for(const auto &id : lazy_method_ids) - lazymethodmap[id]=&it->second; + lazy_method_map[id]=&it->second; } } // typecheck modules - for(modulemapt::iterator it=modulemap.begin(); - it!=modulemap.end(); it++) + for(module_mapt::iterator it=module_map.begin(); + it!=module_map.end(); it++) { if(typecheck_module(symbol_table, it->second)) return true; @@ -239,8 +239,8 @@ bool language_filest::final( { std::set languages; - for(filemapt::iterator it=filemap.begin(); - it!=filemap.end(); it++) + for(file_mapt::iterator it=file_map.begin(); + it!=file_map.end(); it++) { if(languages.insert(it->second.language->id()).second) if(it->second.language->final(symbol_table)) @@ -265,8 +265,8 @@ Function: language_filest::interfaces bool language_filest::interfaces( symbol_tablet &symbol_table) { - for(filemapt::iterator it=filemap.begin(); - it!=filemap.end(); it++) + for(file_mapt::iterator it=file_map.begin(); + it!=file_map.end(); it++) { if(it->second.language->interfaces(symbol_table)) return true; @@ -293,9 +293,9 @@ bool language_filest::typecheck_module( { // check module map - modulemapt::iterator it=modulemap.find(module); + module_mapt::iterator it=module_map.find(module); - if(it==modulemap.end()) + if(it==module_map.end()) { error() << "found no file that provides module " << module << eom; return true; diff --git a/src/util/language_file.h b/src/util/language_file.h index b538c24e84f..d3184d48697 100644 --- a/src/util/language_file.h +++ b/src/util/language_file.h @@ -44,7 +44,7 @@ class language_filet void convert_lazy_method( const irep_idt &id, - symbol_tablet &symtab); + symbol_tablet &symbol_table); language_filet(const language_filet &rhs); @@ -58,21 +58,21 @@ class language_filet class language_filest:public messaget { public: - typedef std::map filemapt; - filemapt filemap; + typedef std::map file_mapt; + file_mapt file_map; - // Contains pointers into filemapt! - typedef std::map modulemapt; - modulemapt modulemap; + // Contains pointers into file_mapt! + typedef std::map module_mapt; + module_mapt module_map; // Contains pointers into filemapt! // This is safe-ish as long as this is std::map. - typedef std::map lazymethodmapt; - lazymethodmapt lazymethodmap; + typedef std::map lazy_method_mapt; + lazy_method_mapt lazy_method_map; void clear_files() { - filemap.clear(); + file_map.clear(); } bool parse(); @@ -87,21 +87,24 @@ class language_filest:public messaget bool has_lazy_method(const irep_idt &id) { - return lazymethodmap.count(id); + return lazy_method_map.count(id); } + // The method must have been added to the symbol table and registered + // in lazy_method_map (currently always in language_filest::typecheck) + // for this to be legal. void convert_lazy_method( const irep_idt &id, - symbol_tablet &symtab) + symbol_tablet &symbol_table) { - return lazymethodmap.at(id)->convert_lazy_method(id, symtab); + return lazy_method_map.at(id)->convert_lazy_method(id, symbol_table); } void clear() { - filemap.clear(); - modulemap.clear(); - lazymethodmap.clear(); + file_map.clear(); + module_map.clear(); + lazy_method_map.clear(); } protected: From 86bef2317d14b10cec6f86dcafc1355f5f30d421 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 15 Feb 2017 11:34:20 +0000 Subject: [PATCH 36/59] Use safe pointers for optional arguments This basic safe-pointer class doesn't do any lifetime management; rather it just enforces explicit null-checks and throws if they don't go as expected. --- .../java_bytecode_convert_method.cpp | 12 ++-- .../java_bytecode_convert_method.h | 9 +-- .../java_bytecode_convert_method_class.h | 9 +-- src/java_bytecode/java_bytecode_language.cpp | 4 +- src/util/safe_pointer.h | 64 +++++++++++++++++++ 5 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 src/util/safe_pointer.h diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index bc12fc77617..ed87954ed0b 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -1724,7 +1724,10 @@ codet java_bytecode_convert_methodt::convert_instructions( const auto &field_name=arg0.get_string(ID_component_name); symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name); if(needed_classes && arg0.type().id()==ID_symbol) - needed_classes->insert(to_symbol_type(arg0.type()).get_identifier()); + { + needed_classes->insert( + to_symbol_type(arg0.type()).get_identifier()); + } results[0]=java_bytecode_promotion(symbol_expr); // set $assertionDisabled to false @@ -1743,7 +1746,8 @@ codet java_bytecode_convert_methodt::convert_instructions( const auto &field_name=arg0.get_string(ID_component_name); symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name); if(needed_classes && arg0.type().id()==ID_symbol) - needed_classes->insert(to_symbol_type(arg0.type()).get_identifier()); + needed_classes->insert( + to_symbol_type(arg0.type()).get_identifier()); c=code_assignt(symbol_expr, op[0]); } else if(statement==patternt("?2?")) // i2c etc. @@ -2207,8 +2211,8 @@ void java_bytecode_convert_method( message_handlert &message_handler, bool disable_runtime_checks, size_t max_array_length, - std::vector *needed_methods, - std::set *needed_classes) + safe_pointer > needed_methods, + safe_pointer > needed_classes) { java_bytecode_convert_methodt java_bytecode_convert_method( symbol_table, diff --git a/src/java_bytecode/java_bytecode_convert_method.h b/src/java_bytecode/java_bytecode_convert_method.h index 68b0dd4e0a8..e81881f44e1 100644 --- a/src/java_bytecode/java_bytecode_convert_method.h +++ b/src/java_bytecode/java_bytecode_convert_method.h @@ -11,6 +11,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include #include "java_bytecode_parse_tree.h" @@ -23,8 +24,8 @@ void java_bytecode_convert_method( message_handlert &message_handler, bool disable_runtime_checks, size_t max_array_length, - std::vector *needed_methods, - std::set *needed_classes); + safe_pointer > needed_methods, + safe_pointer > needed_classes); // Must provide both the optional parameters or neither. inline void java_bytecode_convert_method( @@ -42,8 +43,8 @@ inline void java_bytecode_convert_method( message_handler, disable_runtime_checks, max_array_length, - nullptr, - nullptr); + safe_pointer >::create_null(), + safe_pointer >::create_null()); } void java_bytecode_convert_method_lazy( diff --git a/src/java_bytecode/java_bytecode_convert_method_class.h b/src/java_bytecode/java_bytecode_convert_method_class.h index 96e640ecdf3..ae4ba711640 100644 --- a/src/java_bytecode/java_bytecode_convert_method_class.h +++ b/src/java_bytecode/java_bytecode_convert_method_class.h @@ -13,6 +13,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include +#include #include #include "java_bytecode_parse_tree.h" #include "java_bytecode_convert_class.h" @@ -31,8 +32,8 @@ class java_bytecode_convert_methodt:public messaget message_handlert &_message_handler, bool _disable_runtime_checks, size_t _max_array_length, - std::vector *_needed_methods, - std::set *_needed_classes): + safe_pointer > _needed_methods, + safe_pointer > _needed_classes): messaget(_message_handler), symbol_table(_symbol_table), disable_runtime_checks(_disable_runtime_checks), @@ -57,8 +58,8 @@ class java_bytecode_convert_methodt:public messaget symbol_tablet &symbol_table; const bool disable_runtime_checks; const size_t max_array_length; - std::vector *needed_methods; - std::set *needed_classes; + safe_pointer > needed_methods; + safe_pointer > needed_classes; irep_idt method_id; irep_idt current_method; diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index 4512ec97709..03b5a51a4a2 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -586,8 +586,8 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( get_message_handler(), disable_runtime_checks, max_user_array_length, - &method_worklist2, - &needed_classes); + safe_pointer >::create_non_null(&method_worklist2), + safe_pointer >::create_non_null(&needed_classes)); gather_virtual_callsites( symbol_table.lookup(mname).value, virtual_callsites); diff --git a/src/util/safe_pointer.h b/src/util/safe_pointer.h new file mode 100644 index 00000000000..47e52ac13fe --- /dev/null +++ b/src/util/safe_pointer.h @@ -0,0 +1,64 @@ +/*******************************************************************\ + +Module: Simple checked pointers + +Author: Chris Smowton, chris@smowton.net + +\*******************************************************************/ + +#ifndef CPROVER_UTIL_SAFE_POINTER_H +#define CPROVER_UTIL_SAFE_POINTER_H + +template class safe_pointer +{ + public: + operator bool() const + { + return !!ptr; + } + + T *get() const + { + assert(ptr && "dereferenced a null safe pointer"); + return ptr; + } + + T &operator*() const + { + return *get(); + } + + T *operator->() const + { + return get(); + } + + static safe_pointer create_null() + { + return safe_pointer(); + } + + static safe_pointer create_non_null( + T *target) + { + assert(target && "initialized safe pointer with null"); + return safe_pointer(target); + } + + static safe_pointer create_maybe_null( + T *target) + { + return safe_pointer(target); + } + + protected: + T *ptr; + + explicit safe_pointer(T *target) : ptr(target) + {} + + safe_pointer() : ptr(nullptr) + {} +}; + +#endif From ffef5d715dbde87696151ed6cc501e1f391aeb12 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 15 Feb 2017 12:58:30 +0000 Subject: [PATCH 37/59] Add lazy conversion documentation Also fix some trivial linting errors. No functional changes. --- .../java_bytecode_convert_method.cpp | 2 + src/java_bytecode/java_bytecode_language.cpp | 86 +++++++++++++++++-- src/java_bytecode/java_bytecode_language.h | 4 +- 3 files changed, 82 insertions(+), 10 deletions(-) diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index ed87954ed0b..f101d19c824 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -1746,8 +1746,10 @@ codet java_bytecode_convert_methodt::convert_instructions( const auto &field_name=arg0.get_string(ID_component_name); symbol_expr.set_identifier(arg0.get_string(ID_class)+"."+field_name); if(needed_classes && arg0.type().id()==ID_symbol) + { needed_classes->insert( to_symbol_type(arg0.type()).get_identifier()); + } c=code_assignt(symbol_expr, op[0]); } else if(statement==patternt("?2?")) // i2c etc. diff --git a/src/java_bytecode/java_bytecode_language.cpp b/src/java_bytecode/java_bytecode_language.cpp index 03b5a51a4a2..e9d5a87186b 100644 --- a/src/java_bytecode/java_bytecode_language.cpp +++ b/src/java_bytecode/java_bytecode_language.cpp @@ -502,6 +502,7 @@ bool java_bytecode_languaget::typecheck( // that are reachable from this entry point. if(lazy_methods_mode==LAZY_METHODS_MODE_CONTEXT_INSENSITIVE) { + // ci: context-insensitive. if(do_ci_lazy_method_conversion(symbol_table, lazy_methods)) return true; } @@ -514,6 +515,32 @@ bool java_bytecode_languaget::typecheck( return false; } +/*******************************************************************\ + +Function: java_bytecode_languaget::do_ci_lazy_method_conversion + + Inputs: `symbol_table`: global symbol table + `lazy_methods`: map from method names to relevant symbol + and parsed-method objects. + + Outputs: Elaborates lazily-converted methods that may be reachable + starting from the main entry point (usually provided with + the --function command-line option) (side-effect on the + symbol_table). Returns false on success. + + Purpose: Uses a simple context-insensitive ('ci') analysis to + determine which methods may be reachable from the main + entry point. In brief, static methods are reachable if we + find a callsite in another reachable site, while virtual + methods are reachable if we find a virtual callsite + targeting a compatible type *and* a constructor callsite + indicating an object of that type may be instantiated (or + evidence that an object of that type exists before the + main function is entered, such as being passed as a + parameter). + +\*******************************************************************/ + bool java_bytecode_languaget::do_ci_lazy_method_conversion( symbol_tablet &symbol_table, lazy_methodst &lazy_methods) @@ -558,7 +585,7 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( needed_classes); std::set methods_already_populated; - std::vector virtual_callsites; + std::vector virtual_callsites; bool any_new_methods; do @@ -586,8 +613,10 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( get_message_handler(), disable_runtime_checks, max_user_array_length, - safe_pointer >::create_non_null(&method_worklist2), - safe_pointer >::create_non_null(&needed_classes)); + safe_pointer >::create_non_null( + &method_worklist2), + safe_pointer >::create_non_null( + &needed_classes)); gather_virtual_callsites( symbol_table.lookup(mname).value, virtual_callsites); @@ -607,11 +636,15 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( for(const auto &callsite : virtual_callsites) { // This will also create a stub if a virtual callsite has no targets. - get_virtual_method_targets(*callsite, needed_classes, method_worklist2, - symbol_table, ch); + get_virtual_method_targets( + *callsite, + needed_classes, + method_worklist2, + symbol_table, + ch); } - - } while(any_new_methods); + } + while(any_new_methods); // Remove symbols for methods that were declared but never used: symbol_tablet keep_symbols; @@ -640,12 +673,49 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion( return false; } -void java_bytecode_languaget::lazy_methods_provided(std::set &methods) const +/*******************************************************************\ + +Function: java_bytecode_languaget::lazy_methods_provided + + Inputs: None + + Outputs: Populates `methods` with the complete list of lazy methods + that are available to convert (those which are valid + parameters for `convert_lazy_method`) + + Purpose: Provide feedback to `language_filest` so that when asked + for a lazy method, it can delegate to this instance of + java_bytecode_languaget. + +\*******************************************************************/ + +void java_bytecode_languaget::lazy_methods_provided( + std::set &methods) const { for(const auto &kv : lazy_methods) methods.insert(kv.first); } +/*******************************************************************\ + +Function: java_bytecode_languaget::convert_lazy_method + + Inputs: `id`: method ID to convert + `symtab`: global symbol table + + Outputs: Amends the symbol table entry for function `id`, which + should be a lazy method provided by this instance of + `java_bytecode_languaget`. It should initially have a nil + value. After this method completes, it will have a value + representing the method body, identical to that produced + using eager method conversion. + + Purpose: Promote a lazy-converted method (one whose type is known + but whose body hasn't been converted) into a fully- + elaborated one. + +\*******************************************************************/ + void java_bytecode_languaget::convert_lazy_method( const irep_idt &id, symbol_tablet &symtab) diff --git a/src/java_bytecode/java_bytecode_language.h b/src/java_bytecode/java_bytecode_language.h index afdd275ddf6..ea177e0226a 100644 --- a/src/java_bytecode/java_bytecode_language.h +++ b/src/java_bytecode/java_bytecode_language.h @@ -24,8 +24,8 @@ enum lazy_methods_modet }; typedef std::pair< - const symbolt*, - const java_bytecode_parse_treet::methodt*> + const symbolt *, + const java_bytecode_parse_treet::methodt *> lazy_method_valuet; typedef std::map lazy_methodst; From a30720b39e3597875ee476840523d2d31c0a9a5f Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 15 Feb 2017 17:28:55 +0000 Subject: [PATCH 38/59] Improve failed test printer --- regression/failed-tests-printer.pl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/regression/failed-tests-printer.pl b/regression/failed-tests-printer.pl index 832ba2d2c64..40767185d5c 100755 --- a/regression/failed-tests-printer.pl +++ b/regression/failed-tests-printer.pl @@ -4,23 +4,25 @@ open LOG,") { chomp; if (/^Test '(.+)'/) { $current_test = $1; - $ignore = 0; - } elsif (1 == $ignore) { - next; + $printed_this_test = 0; } elsif (/\[FAILED\]\s*$/) { - $ignore = 1; - print "Failed test: $current_test\n"; - my $outf = `sed -n '2p' $current_test/test.desc`; - $outf =~ s/\..*$/.out/; - system("cat $current_test/$outf"); - print "\n\n"; + if(0 == $printed_this_test) { + $printed_this_test = 1; + print "\n\n"; + print "Failed test: $current_test\n"; + my $outf = `sed -n '2p' $current_test/test.desc`; + $outf =~ s/\..*$/.out/; + system("cat $current_test/$outf"); + print "\n\nFailed test.desc lines:\n"; + } + print "$_\n"; } } From 8809a4c56820dd74bc52834655e0c2639919d40a Mon Sep 17 00:00:00 2001 From: Norbert Manthey Date: Tue, 28 Feb 2017 23:17:12 +0100 Subject: [PATCH 39/59] Remove aa-symex from DIRS variable in Makefile Without this patch, calling "make clean" fails, because make tries to call "make clean" in the aa-symex directory as well. By removing aa-symex from the DIRS variable, this problem is fixed. Fixes: cleanup aa-path-symex and aa-symex --- src/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index 3a452b7fe09..269ddeda140 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ DIRS = ansi-c big-int cbmc cpp goto-cc goto-instrument goto-programs \ goto-symex langapi pointer-analysis solvers util linking xmllang \ - assembler analyses java_bytecode aa-path-symex path-symex musketeer \ - json cegis goto-analyzer jsil symex goto-diff aa-symex clobber \ + assembler analyses java_bytecode path-symex musketeer \ + json cegis goto-analyzer jsil symex goto-diff clobber \ memory-models all: cbmc.dir goto-cc.dir goto-instrument.dir symex.dir goto-analyzer.dir goto-diff.dir From 6c0ff32172d56335deebc5044ea3eacac3faf824 Mon Sep 17 00:00:00 2001 From: thk123 Date: Tue, 29 Nov 2016 14:50:47 +0000 Subject: [PATCH 40/59] Don't allowing functions called from _Start to be inlined When the partial inlining comes to the _Start function, it skips over it. We don't want inlining on the start function because if we are trying to find the entry point for the users code, it is important it hasn't been inlined into GOTO generated code. --- src/goto-programs/goto_inline.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/goto-programs/goto_inline.cpp b/src/goto-programs/goto_inline.cpp index 830798c289e..c8c97f8d4a5 100644 --- a/src/goto-programs/goto_inline.cpp +++ b/src/goto-programs/goto_inline.cpp @@ -213,7 +213,12 @@ void goto_partial_inline( // called function const goto_functiont &goto_function=f_it->second; - if(!goto_function.body_available()) + // We can't take functions without bodies to find functions + // inside them to be inlined. + // We also don't allow for the _start function to have any of its + // function calls to be inlined + if(!goto_function.body_available() || + f_it->first==ID__start) continue; const goto_programt &goto_program=goto_function.body; From d47d503b660386e840ed41e3fe5ba9dd7ef0dfd5 Mon Sep 17 00:00:00 2001 From: Dario Cattaruzza Date: Tue, 25 Oct 2016 16:14:56 +0100 Subject: [PATCH 41/59] Get symbol of member expression --- src/util/std_expr.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/util/std_expr.h b/src/util/std_expr.h index a2f78ab25e8..30296525585 100644 --- a/src/util/std_expr.h +++ b/src/util/std_expr.h @@ -2979,6 +2979,17 @@ class member_exprt:public exprt { return op0(); } + + // Retrieves the object(symbol) this member corresponds to + inline const symbol_exprt &symbol() const + { + const exprt &op=op0(); + if(op.id()==ID_member) + { + return static_cast(op).symbol(); + } + return to_symbol_expr(op); + } }; /*! \brief Cast a generic exprt to a \ref member_exprt From 27153d142eb07dc0e78eb47d72e52b877af5d776 Mon Sep 17 00:00:00 2001 From: Dario Cattaruzza Date: Tue, 25 Oct 2016 16:16:43 +0100 Subject: [PATCH 42/59] Auxiliary function to check if the ssa has enough data to build an identifier --- src/util/ssa_expr.cpp | 13 +++++++++++++ src/util/ssa_expr.h | 6 +++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/util/ssa_expr.cpp b/src/util/ssa_expr.cpp index c75d7d2ed92..affd2907eb5 100644 --- a/src/util/ssa_expr.cpp +++ b/src/util/ssa_expr.cpp @@ -78,6 +78,19 @@ static void build_ssa_identifier_rec( assert(false); } +/* Used to determine whether or not an identifier can be built + * before trying and getting an exception */ +bool ssa_exprt::can_build_identifier(const exprt &expr) +{ + if(expr.id()==ID_symbol) + return true; + else if(expr.id()==ID_member || + expr.id()==ID_index) + return can_build_identifier(expr.op0()); + else + return false; +} + /*******************************************************************\ Function: ssa_exprt::build_identifier diff --git a/src/util/ssa_expr.h b/src/util/ssa_expr.h index 446e82169d6..e18862fa9f9 100644 --- a/src/util/ssa_expr.h +++ b/src/util/ssa_expr.h @@ -64,7 +64,7 @@ class ssa_exprt:public symbol_exprt const irep_idt get_l1_object_identifier() const { - #if 0 + #if 1 return get_l1_object().get_identifier(); #else // the above is the clean version, this is the fast one, using @@ -134,6 +134,10 @@ class ssa_exprt:public symbol_exprt const irep_idt &l0, const irep_idt &l1, const irep_idt &l2); + + /* Used to determine whether or not an identifier can be built + * before trying and getting an exception */ + static bool can_build_identifier(const exprt &src); }; /*! \brief Cast a generic exprt to an \ref ssa_exprt From 2987406470da274a1f75024251bc07650352465c Mon Sep 17 00:00:00 2001 From: Dario Cattaruzza Date: Tue, 25 Oct 2016 16:17:06 +0100 Subject: [PATCH 43/59] Bitwise operators for mpinteger --- src/util/mp_arith.cpp | 264 ++++++++++++++++++++++++++++++++++++++++++ src/util/mp_arith.h | 23 ++++ 2 files changed, 287 insertions(+) diff --git a/src/util/mp_arith.cpp b/src/util/mp_arith.cpp index 338a6103e40..e70c654bd14 100644 --- a/src/util/mp_arith.cpp +++ b/src/util/mp_arith.cpp @@ -17,6 +17,9 @@ Author: Daniel Kroening, kroening@kroening.com #include "mp_arith.h" #include "arith_tools.h" + +typedef BigInt::ullong_t ullong_t; + /*******************************************************************\ Function: >> @@ -320,3 +323,264 @@ unsigned integer2unsigned(const mp_integer &n) assert(ull <= std::numeric_limits::max()); return (unsigned)ull; } + +/*******************************************************************\ + +Function: bitwise_or + + Inputs: + + Outputs: + + Purpose: bitwise or + bitwise operations only make sense on native objects, hence the + largest object size should be the largest available c++ integer + size (currently long long) + +\*******************************************************************/ + +mp_integer bitwise_or(const mp_integer &a, const mp_integer &b) +{ + ullong_t result=a.to_ulong()|b.to_ulong(); + return result; +} + +/*******************************************************************\ + +Function: bitwise_and + + Inputs: + + Outputs: + + Purpose: bitwise and + bitwise operations only make sense on native objects, hence the + largest object size should be the largest available c++ integer + size (currently long long) + +\*******************************************************************/ + +mp_integer bitwise_and(const mp_integer &a, const mp_integer &b) +{ + ullong_t result=a.to_ulong()&b.to_ulong(); + return result; +} + +/*******************************************************************\ + +Function: bitwise_xor + + Inputs: + + Outputs: + + Purpose: bitwise xor + bitwise operations only make sense on native objects, hence the + largest object size should be the largest available c++ integer + size (currently long long) + +\*******************************************************************/ + +mp_integer bitwise_xor(const mp_integer &a, const mp_integer &b) +{ + ullong_t result=a.to_ulong()^b.to_ulong(); + return result; +} + +/*******************************************************************\ + +Function: bitwise_neg + + Inputs: + + Outputs: + + Purpose: bitwise negation + bitwise operations only make sense on native objects, hence the + largest object size should be the largest available c++ integer + size (currently long long) + +\*******************************************************************/ + +mp_integer bitwise_neg(const mp_integer &a) +{ + ullong_t result=~a.to_ulong(); + return result; +} + +/*******************************************************************\ + +Function: arith_left_shift + + Inputs: + + Outputs: + + Purpose: arithmetic left shift + bitwise operations only make sense on native objects, hence the + largest object size should be the largest available c++ integer + size (currently long long) + +\*******************************************************************/ + +mp_integer arith_left_shift( + const mp_integer &a, + const mp_integer &b, + std::size_t true_size) +{ + ullong_t shift=b.to_ulong(); + if(shift>true_size && a!=mp_integer(0)) + throw "shift value out of range"; + + ullong_t result=a.to_ulong()<true_size) + throw "shift value out of range"; + + ullong_t sign=(1<<(true_size-1))&number; + ullong_t pad=(sign==0) ? 0 : ~((1<<(true_size-shift))-1); + ullong_t result=(number>>shift)|pad; + return result; +} + +/*******************************************************************\ + +Function: logic_left_shift + + Inputs: + + Outputs: + + Purpose: logic left shift + bitwise operations only make sense on native objects, hence the + largest object size should be the largest available c++ integer + size (currently long long) + +\*******************************************************************/ + +mp_integer logic_left_shift( + const mp_integer &a, + const mp_integer &b, + std::size_t true_size) +{ + ullong_t shift=b.to_ulong(); + if(shift>true_size && a!=mp_integer(0)) + throw "shift value out of range"; + + ullong_t result=a.to_ulong()<true_size) + throw "shift value out of range"; + + ullong_t result=a.to_ulong()>>shift; + return result; +} + +/*******************************************************************\ + +Function: rotate_right + + Inputs: + + Outputs: + + Purpose: rotates right (MSB=LSB) + bitwise operations only make sense on native objects, hence the + largest object size should be the largest available c++ integer + size (currently long long) + +\*******************************************************************/ + +mp_integer rotate_right( + const mp_integer &a, + const mp_integer &b, + std::size_t true_size) +{ + ullong_t number=a.to_ulong(); + ullong_t shift=b.to_ulong(); + if(shift>true_size) + throw "shift value out of range"; + + ullong_t revShift=true_size-shift; + ullong_t filter=1<<(true_size-1); + ullong_t result=(number>>shift)|((number<true_size) + throw "shift value out of range"; + + ullong_t revShift=true_size-shift; + ullong_t filter=1<<(true_size-1); + ullong_t result=((number<>revShift); + return result; +} diff --git a/src/util/mp_arith.h b/src/util/mp_arith.h index 030a292bb74..046b1bff788 100644 --- a/src/util/mp_arith.h +++ b/src/util/mp_arith.h @@ -20,6 +20,28 @@ typedef BigInt mp_integer; std::ostream &operator<<(std::ostream &, const mp_integer &); mp_integer operator>>(const mp_integer &, const mp_integer &); mp_integer operator<<(const mp_integer &, const mp_integer &); +mp_integer bitwise_or(const mp_integer &, const mp_integer &); +mp_integer bitwise_and(const mp_integer &, const mp_integer &); +mp_integer bitwise_xor(const mp_integer &, const mp_integer &); +mp_integer bitwise_neg(const mp_integer &); + +mp_integer arith_left_shift( + const mp_integer &, const mp_integer &, std::size_t true_size); + +mp_integer arith_right_shift( + const mp_integer &, const mp_integer &, std::size_t true_size); + +mp_integer logic_left_shift( + const mp_integer &, const mp_integer &, std::size_t true_size); + +mp_integer logic_right_shift( + const mp_integer &, const mp_integer &, std::size_t true_size); + +mp_integer rotate_right( + const mp_integer &, const mp_integer &, std::size_t true_size); + +mp_integer rotate_left( + const mp_integer &, const mp_integer &, std::size_t true_size); const std::string integer2string(const mp_integer &, unsigned base=10); const mp_integer string2integer(const std::string &, unsigned base=10); @@ -28,5 +50,6 @@ const mp_integer binary2integer(const std::string &, bool is_signed); mp_integer::ullong_t integer2ulong(const mp_integer &); std::size_t integer2size_t(const mp_integer &); unsigned integer2unsigned(const mp_integer &); +const mp_integer mp_zero=string2integer("0"); #endif // CPROVER_UTIL_MP_ARITH_H From d81dd759c9373a526e35d900a6651fda0799c650 Mon Sep 17 00:00:00 2001 From: Dario Cattaruzza Date: Tue, 25 Oct 2016 16:18:08 +0100 Subject: [PATCH 44/59] Auxiliary function to retrieve tail of trace and added dead command to trace --- src/goto-programs/goto_trace.cpp | 5 ++++- src/goto-programs/goto_trace.h | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/goto-programs/goto_trace.cpp b/src/goto-programs/goto_trace.cpp index ad8bdcdfdd9..4179afb5395 100644 --- a/src/goto-programs/goto_trace.cpp +++ b/src/goto-programs/goto_trace.cpp @@ -65,6 +65,7 @@ void goto_trace_stept::output( case goto_trace_stept::ASSIGNMENT: out << "ASSIGNMENT"; break; case goto_trace_stept::GOTO: out << "GOTO"; break; case goto_trace_stept::DECL: out << "DECL"; break; + case goto_trace_stept::DEAD: out << "DEAD"; break; case goto_trace_stept::OUTPUT: out << "OUTPUT"; break; case goto_trace_stept::INPUT: out << "INPUT"; break; case goto_trace_stept::ATOMIC_BEGIN: out << "ATOMC_BEGIN"; break; @@ -73,7 +74,9 @@ void goto_trace_stept::output( case goto_trace_stept::SHARED_WRITE: out << "SHARED WRITE"; break; case goto_trace_stept::FUNCTION_CALL: out << "FUNCTION CALL"; break; case goto_trace_stept::FUNCTION_RETURN: out << "FUNCTION RETURN"; break; - default: assert(false); + default: + out << "unknown type: " << type << std::endl; + assert(false); } if(type==ASSERT || type==ASSUME || type==GOTO) diff --git a/src/goto-programs/goto_trace.h b/src/goto-programs/goto_trace.h index 507d538ada0..a669fac5e6b 100644 --- a/src/goto-programs/goto_trace.h +++ b/src/goto-programs/goto_trace.h @@ -154,6 +154,13 @@ class goto_tracet steps.push_back(step); } + // retrieves the final step in the trace for manipulation + // (used to fill a trace from code, hence non-const) + inline goto_trace_stept &get_last_step() + { + return steps.back(); + } + // delete all steps after (not including) s void trim_after(stepst::iterator s) { From 7fb8174485d59e458097725cc79947f42b08ad7b Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Fri, 13 Jan 2017 14:36:01 +0000 Subject: [PATCH 45/59] Fix arithmetic shift operators to_ulong() will negate a negative number, rather than returning its two's complement representation as an unsigned type as we might reasonably suppose. Instead use to_long() everywhere to preserve the bitwise representation and then use sign-bit filling to make sure the value is correctly re-encoded as mp_integer. --- src/util/mp_arith.cpp | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/util/mp_arith.cpp b/src/util/mp_arith.cpp index e70c654bd14..6a9082b6823 100644 --- a/src/util/mp_arith.cpp +++ b/src/util/mp_arith.cpp @@ -18,7 +18,8 @@ Author: Daniel Kroening, kroening@kroening.com #include "arith_tools.h" -typedef BigInt::ullong_t ullong_t; +typedef BigInt::ullong_t ullong_t; // NOLINT(readability/identifiers) +typedef BigInt::llong_t llong_t; // NOLINT(readability/identifiers) /*******************************************************************\ @@ -432,8 +433,12 @@ mp_integer arith_left_shift( if(shift>true_size && a!=mp_integer(0)) throw "shift value out of range"; - ullong_t result=a.to_ulong()<true_size) throw "shift value out of range"; - ullong_t sign=(1<<(true_size-1))&number; - ullong_t pad=(sign==0) ? 0 : ~((1<<(true_size-shift))-1); - ullong_t result=(number>>shift)|pad; + llong_t sign=(1<<(true_size-1))&number; + llong_t pad=(sign==0) ? 0 : ~((1<<(true_size-shift))-1); + llong_t result=(number >> shift)|pad; return result; } @@ -490,8 +495,17 @@ mp_integer logic_left_shift( ullong_t shift=b.to_ulong(); if(shift>true_size && a!=mp_integer(0)) throw "shift value out of range"; - - ullong_t result=a.to_ulong()<true_size) throw "shift value out of range"; - ullong_t result=a.to_ulong()>>shift; + ullong_t result=((ullong_t)a.to_long()) >> shift; return result; } @@ -550,7 +564,7 @@ mp_integer rotate_right( ullong_t revShift=true_size-shift; ullong_t filter=1<<(true_size-1); - ullong_t result=(number>>shift)|((number<> shift)|((number<>revShift); + ullong_t result=((number<> revShift); return result; } From fb616c542cec51cf99c61350e9d2df404eed700a Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 16 Jan 2017 14:58:46 +0000 Subject: [PATCH 46/59] Added a new class for handling the internals This code was originally in the `dump_ct` class but it is useful in other places (specifically when generating stubs we don't want to include any of these). --- src/goto-programs/Makefile | 5 +- src/goto-programs/system_library_symbols.cpp | 298 +++++++++++++++++++ src/goto-programs/system_library_symbols.h | 37 +++ 3 files changed, 339 insertions(+), 1 deletion(-) create mode 100644 src/goto-programs/system_library_symbols.cpp create mode 100644 src/goto-programs/system_library_symbols.h diff --git a/src/goto-programs/Makefile b/src/goto-programs/Makefile index d8cb835e4a8..485bc211e24 100644 --- a/src/goto-programs/Makefile +++ b/src/goto-programs/Makefile @@ -20,7 +20,10 @@ SRC = goto_convert.cpp goto_convert_function_call.cpp \ slice_global_inits.cpp goto_inline_class.cpp class_identifier.cpp \ show_goto_functions_json.cpp \ show_goto_functions_xml.cpp \ - remove_static_init_loops.cpp remove_instanceof.cpp + remove_static_init_loops.cpp \ + remove_instanceof.cpp \ + system_library_symbols.cpp \ + INCLUDES= -I .. diff --git a/src/goto-programs/system_library_symbols.cpp b/src/goto-programs/system_library_symbols.cpp new file mode 100644 index 00000000000..44bb1b1b2cd --- /dev/null +++ b/src/goto-programs/system_library_symbols.cpp @@ -0,0 +1,298 @@ +/*******************************************************************\ + +Module: Goto Programs + +Author: Thomas Kiley + +\*******************************************************************/ + +#include "system_library_symbols.h" +#include +#include +#include + +system_library_symbolst::system_library_symbolst() +{ + init_system_library_map(); +} + +/*******************************************************************\ + +Function: system_library_symbolst::init_system_library_map + +Inputs: + +Outputs: + +Purpose: To generate a map of header file names -> list of symbols + The symbol names are reserved as the header and source files + will be compiled in to the goto program. + +\*******************************************************************/ + +void system_library_symbolst::init_system_library_map() +{ + // ctype.h + std::list ctype_syms= + { + "isalnum", "isalpha", "isblank", "iscntrl", "isdigit", "isgraph", + "islower", "isprint", "ispunct", "isspace", "isupper", "isxdigit", + "tolower", "toupper" + }; + add_to_system_library("ctype.h", ctype_syms); + + // fcntl.h + std::list fcntl_syms= + { + "creat", "fcntl", "open" + }; + add_to_system_library("fcntl.h", fcntl_syms); + + // locale.h + std::list locale_syms= + { + "setlocale" + }; + add_to_system_library("locale.h", locale_syms); + + // math.h + std::list math_syms= + { + "acos", "acosh", "asin", "asinh", "atan", "atan2", "atanh", + "cbrt", "ceil", "copysign", "cos", "cosh", "erf", "erfc", "exp", + "exp2", "expm1", "fabs", "fdim", "floor", "fma", "fmax", "fmin", + "fmod", "fpclassify", "frexp", "hypot", "ilogb", "isfinite", + "isinf", "isnan", "isnormal", "j0", "j1", "jn", "ldexp", "lgamma", + "llrint", "llround", "log", "log10", "log1p", "log2", "logb", + "lrint", "lround", "modf", "nan", "nearbyint", "nextafter", "pow", + "remainder", "remquo", "rint", "round", "scalbln", "scalbn", + "signbit", "sin", "sinh", "sqrt", "tan", "tanh", "tgamma", + "trunc", "y0", "y1", "yn" + }; + add_to_system_library("math.h", math_syms); + + // pthread.h + std::list pthread_syms= + { + "pthread_cleanup_pop", "pthread_cleanup_push", + "pthread_cond_broadcast", "pthread_cond_destroy", + "pthread_cond_init", "pthread_cond_signal", + "pthread_cond_timedwait", "pthread_cond_wait", "pthread_create", + "pthread_detach", "pthread_equal", "pthread_exit", + "pthread_getspecific", "pthread_join", "pthread_key_delete", + "pthread_mutex_destroy", "pthread_mutex_init", + "pthread_mutex_lock", "pthread_mutex_trylock", + "pthread_mutex_unlock", "pthread_once", "pthread_rwlock_destroy", + "pthread_rwlock_init", "pthread_rwlock_rdlock", + "pthread_rwlock_unlock", "pthread_rwlock_wrlock", + "pthread_rwlockattr_destroy", "pthread_rwlockattr_getpshared", + "pthread_rwlockattr_init", "pthread_rwlockattr_setpshared", + "pthread_self", "pthread_setspecific" + }; + add_to_system_library("pthread.h", pthread_syms); + + // setjmp.h + std::list setjmp_syms= + { + "_longjmp", "_setjmp", "longjmp", "longjmperror", "setjmp", + "siglongjmp", "sigsetjmp" + }; + add_to_system_library("setjmp.h", setjmp_syms); + + // stdio.h + std::list stdio_syms= + { + "asprintf", "clearerr", "fclose", "fdopen", "feof", "ferror", + "fflush", "fgetc", "fgetln", "fgetpos", "fgets", "fgetwc", + "fgetws", "fileno", "fopen", "fprintf", "fpurge", "fputc", + "fputs", "fputwc", "fputws", "fread", "freopen", "fropen", + "fscanf", "fseek", "fsetpos", "ftell", "funopen", "fwide", + "fwopen", "fwprintf", "fwrite", "getc", "getchar", "getdelim", + "getline", "gets", "getw", "getwc", "getwchar", "mkdtemp", + "mkstemp", "mktemp", "perror", "printf", "putc", "putchar", + "puts", "putw", "putwc", "putwchar", "remove", "rewind", "scanf", + "setbuf", "setbuffer", "setlinebuf", "setvbuf", "snprintf", + "sprintf", "sscanf", "strerror", "swprintf", "sys_errlist", + "sys_nerr", "tempnam", "tmpfile", "tmpnam", "ungetc", "ungetwc", + "vasprintf", "vfprintf", "vfscanf", "vfwprintf", "vprintf", + "vscanf", "vsnprintf", "vsprintf", "vsscanf", "vswprintf", + "vwprintf", "wprintf", + /* non-public struct types */ + "tag-__sFILE", "tag-__sbuf", // OS X + "tag-_IO_FILE", "tag-_IO_marker", // Linux + }; + add_to_system_library("stdio.h", stdio_syms); + + // stdlib.h + std::list stdlib_syms= + { + "abort", "abs", "atexit", "atof", "atoi", "atol", "atoll", + "bsearch", "calloc", "div", "exit", "free", "getenv", "labs", + "ldiv", "llabs", "lldiv", "malloc", "mblen", "mbstowcs", "mbtowc", + "qsort", "rand", "realloc", "srand", "strtod", "strtof", "strtol", + "strtold", "strtoll", "strtoul", "strtoull", "system", "wcstombs", + "wctomb" + }; + add_to_system_library("stdlib.h", stdlib_syms); + + // string.h + std::list string_syms= + { + "strcat", "strncat", "strchr", "strrchr", "strcmp", "strncmp", + "strcpy", "strncpy", "strerror", "strlen", "strpbrk", "strspn", + "strcspn", "strstr", "strtok" + }; + add_to_system_library("string.h", string_syms); + + // time.h + std::list time_syms= + { + "asctime", "asctime_r", "ctime", "ctime_r", "difftime", "gmtime", + "gmtime_r", "localtime", "localtime_r", "mktime", + /* non-public struct types */ + "tag-timespec", "tag-timeval" + }; + add_to_system_library("time.h", time_syms); + + // unistd.h + std::list unistd_syms= + { + "_exit", "access", "alarm", "chdir", "chown", "close", "dup", + "dup2", "execl", "execle", "execlp", "execv", "execve", "execvp", + "fork", "fpathconf", "getcwd", "getegid", "geteuid", "getgid", + "getgroups", "getlogin", "getpgrp", "getpid", "getppid", "getuid", + "isatty", "link", "lseek", "pathconf", "pause", "pipe", "read", + "rmdir", "setgid", "setpgid", "setsid", "setuid", "sleep", + "sysconf", "tcgetpgrp", "tcsetpgrp", "ttyname", "ttyname_r", + "unlink", "write" + }; + add_to_system_library("unistd.h", unistd_syms); + + // sys/select.h + std::list sys_select_syms= + { + "select" + }; + add_to_system_library("sys/select.h", sys_select_syms); + + // sys/socket.h + std::list sys_socket_syms= + { + "accept", "bind", "connect" + }; + add_to_system_library("sys/socket.h", sys_socket_syms); + + // sys/stat.h + std::list sys_stat_syms= + { + "fstat", "lstat", "stat" + }; + add_to_system_library("sys/stat.h", sys_stat_syms); + +#if 0 + // sys/types.h + std::list sys_types_syms= + { + }; + add_to_system_library("sys/types.h", sys_types_syms); +#endif + + // sys/wait.h + std::list sys_wait_syms= + { + "wait", "waitpid" + }; + add_to_system_library("sys/wait.h", sys_wait_syms); +} + +/*******************************************************************\ + +Function: system_library_symbolst::add_to_system_library + +Inputs: + header_file - the name of the header file the symbol came from + symbols - a list of the names of the symbols in the header file + +Outputs: + +Purpose: To add the symbols from a specific header file to the + system library map. The symbol is used as the key so that + we can easily look up symbols. + +\*******************************************************************/ + +void system_library_symbolst::add_to_system_library( + irep_idt header_file, + std::list symbols) +{ + for(const irep_idt &symbol : symbols) + { + system_library_map[symbol]=header_file; + } +} + + +/*******************************************************************\ + +Function: system_library_symbolst::is_symbol_internal_symbol + +Inputs: + symbol - the symbol to check + +Outputs: True if the symbol is an internal symbol. If specific system + headers need to be included, the out_system_headers will contain + the headers. + +Purpose: To find out if a symbol is an internal symbol. + +\*******************************************************************/ + +bool system_library_symbolst::is_symbol_internal_symbol( + const symbolt &symbol, + std::set &out_system_headers) const +{ + const std::string &name_str=id2string(symbol.name); + + if(has_prefix(name_str, CPROVER_PREFIX) || + name_str=="__func__" || + name_str=="__FUNCTION__" || + name_str=="__PRETTY_FUNCTION__" || + name_str=="argc'" || + name_str=="argv'" || + name_str=="envp'" || + name_str=="envp_size'") + return true; + + const std::string &file_str=id2string(symbol.location.get_file()); + + // don't dump internal GCC builtins + if((file_str=="gcc_builtin_headers_alpha.h" || + file_str=="gcc_builtin_headers_arm.h" || + file_str=="gcc_builtin_headers_ia32.h" || + file_str=="gcc_builtin_headers_mips.h" || + file_str=="gcc_builtin_headers_power.h" || + file_str=="gcc_builtin_headers_generic.h") && + has_prefix(name_str, "__builtin_")) + return true; + + if(name_str=="__builtin_va_start" || + name_str=="__builtin_va_end" || + symbol.name==ID_gcc_builtin_va_arg) + { + out_system_headers.insert("stdarg.h"); + return true; + } + + if(name_str.find("$link")!=std::string::npos) + return false; + + const auto &it=system_library_map.find(symbol.name); + + if(it!=system_library_map.end()) + { + out_system_headers.insert(it->second); + return true; + } + + return false; +} diff --git a/src/goto-programs/system_library_symbols.h b/src/goto-programs/system_library_symbols.h new file mode 100644 index 00000000000..a253b903bd8 --- /dev/null +++ b/src/goto-programs/system_library_symbols.h @@ -0,0 +1,37 @@ +/*******************************************************************\ + +Module: Goto Programs + +Author: Thomas Kiley + +\*******************************************************************/ + +#ifndef CPROVER_GOTO_PROGRAMS_SYSTEM_LIBRARY_SYMBOLS_H +#define CPROVER_GOTO_PROGRAMS_SYSTEM_LIBRARY_SYMBOLS_H + +#include +#include +#include + +class symbolt; + +class system_library_symbolst +{ +public: + system_library_symbolst(); + + bool is_symbol_internal_symbol( + const symbolt &symbol, + std::set &out_system_headers) const; + +private: + void init_system_library_map(); + + void add_to_system_library( + irep_idt header_file, + std::list symbols); + + std::map system_library_map; +}; + +#endif // CPROVER_GOTO_PROGRAMS_SYSTEM_LIBRARY_SYMBOLS_H From fc756f336c04a788487c2f7e59bd1c8568c4c5f5 Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 16 Jan 2017 17:07:04 +0000 Subject: [PATCH 47/59] Adding more symbols that should be excluded The existing symbols were missing a few symbols from the files they were supposed to be symbols for. Further, for some reason the math functions were sometimes used with a double underscore prefix. Some included files were missed (fenv.h, errno.c, noop.c). There were some other prefixes that clearly have internal meaning (__VERIFIER, nondet_). Also asserts weren't being included. These problems were discovered by running the make and seeing which tests failed and what functions were being stubbed. It is therefore not necessarily exhaustive. Perhaps there is a better approach to this problem. --- src/goto-programs/system_library_symbols.cpp | 71 +++++++++++++++++--- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/src/goto-programs/system_library_symbols.cpp b/src/goto-programs/system_library_symbols.cpp index 44bb1b1b2cd..76023d0c455 100644 --- a/src/goto-programs/system_library_symbols.cpp +++ b/src/goto-programs/system_library_symbols.cpp @@ -10,6 +10,7 @@ Author: Thomas Kiley #include #include #include +#include system_library_symbolst::system_library_symbolst() { @@ -61,16 +62,28 @@ void system_library_symbolst::init_system_library_map() "acos", "acosh", "asin", "asinh", "atan", "atan2", "atanh", "cbrt", "ceil", "copysign", "cos", "cosh", "erf", "erfc", "exp", "exp2", "expm1", "fabs", "fdim", "floor", "fma", "fmax", "fmin", - "fmod", "fpclassify", "frexp", "hypot", "ilogb", "isfinite", - "isinf", "isnan", "isnormal", "j0", "j1", "jn", "ldexp", "lgamma", - "llrint", "llround", "log", "log10", "log1p", "log2", "logb", - "lrint", "lround", "modf", "nan", "nearbyint", "nextafter", "pow", - "remainder", "remquo", "rint", "round", "scalbln", "scalbn", - "signbit", "sin", "sinh", "sqrt", "tan", "tanh", "tgamma", - "trunc", "y0", "y1", "yn" + "fmod", "fpclassify", "fpclassifyl", "fpclassifyf", "frexp", + "hypot", "ilogb", "isfinite", "isinf", "isnan", "isnormal", + "j0", "j1", "jn", "ldexp", "lgamma", "llrint", "llround", "log", + "log10", "log1p", "log2", "logb", "lrint", "lround", "modf", "nan", + "nearbyint", "nextafter", "pow", "remainder", "remquo", "rint", + "round", "scalbln", "scalbn", "signbit", "sin", "sinh", "sqrt", + "tan", "tanh", "tgamma", "trunc", "y0", "y1", "yn", "isinff", + "isinfl", "isnanf", "isnanl" }; add_to_system_library("math.h", math_syms); + // for some reason the math functions can sometimes be prefixed with + // a double underscore + std::list underscore_math_syms; + for(const irep_idt &math_sym : math_syms) + { + std::ostringstream underscore_id; + underscore_id << "__" << math_sym; + underscore_math_syms.push_back(irep_idt(underscore_id.str())); + } + add_to_system_library("math.h", underscore_math_syms); + // pthread.h std::list pthread_syms= { @@ -140,7 +153,8 @@ void system_library_symbolst::init_system_library_map() { "strcat", "strncat", "strchr", "strrchr", "strcmp", "strncmp", "strcpy", "strncpy", "strerror", "strlen", "strpbrk", "strspn", - "strcspn", "strstr", "strtok" + "strcspn", "strstr", "strtok", "strcasecmp", "strncasecmp", "strdup", + "memset" }; add_to_system_library("string.h", string_syms); @@ -189,6 +203,27 @@ void system_library_symbolst::init_system_library_map() }; add_to_system_library("sys/stat.h", sys_stat_syms); + std::list fenv_syms= + { + "fenv_t", "fexcept_t", "feclearexcept", "fegetexceptflag", + "feraiseexcept", "fesetexceptflag", "fetestexcept", + "fegetround", "fesetround", "fegetenv", "feholdexcept", + "fesetenv", "feupdateenv" + }; + add_to_system_library("fenv.h", fenv_syms); + + std::list errno_syms= + { + "__error", "__errno_location", "__errno" + }; + add_to_system_library("errno.c", errno_syms); + + std::list noop_syms= + { + "__noop" + }; + add_to_system_library("noop.c", noop_syms); + #if 0 // sys/types.h std::list sys_types_syms= @@ -263,6 +298,17 @@ bool system_library_symbolst::is_symbol_internal_symbol( name_str=="envp_size'") return true; + // exclude nondet instructions + if(has_prefix(name_str, "nondet_")) + { + return true; + } + + if(has_prefix(name_str, "__VERIFIER")) + { + return true; + } + const std::string &file_str=id2string(symbol.location.get_file()); // don't dump internal GCC builtins @@ -283,6 +329,15 @@ bool system_library_symbolst::is_symbol_internal_symbol( return true; } + // don't dump asserts + else if(name_str=="__assert_fail" || + name_str=="_assert" || + name_str=="__assert_c99" || + name_str=="_wassert") + { + return true; + } + if(name_str.find("$link")!=std::string::npos) return false; From 2f5b86689fb7aabd189ce038633c51a5f410dcd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Forejt?= Date: Fri, 20 Jan 2017 21:51:10 +0000 Subject: [PATCH 48/59] Autocomplete script for bash See documentation in scripts/bash-autocomplete/Readme.md --- scripts/bash-autocomplete/.gitignore | 1 + scripts/bash-autocomplete/Readme.md | 31 ++++++++++++ scripts/bash-autocomplete/cbmc.sh.template | 43 +++++++++++++++++ scripts/bash-autocomplete/extract_switches.sh | 48 +++++++++++++++++++ .../switch_extractor_helper.c | 3 ++ 5 files changed, 126 insertions(+) create mode 100644 scripts/bash-autocomplete/.gitignore create mode 100644 scripts/bash-autocomplete/Readme.md create mode 100644 scripts/bash-autocomplete/cbmc.sh.template create mode 100755 scripts/bash-autocomplete/extract_switches.sh create mode 100644 scripts/bash-autocomplete/switch_extractor_helper.c diff --git a/scripts/bash-autocomplete/.gitignore b/scripts/bash-autocomplete/.gitignore new file mode 100644 index 00000000000..1e0acedc4f2 --- /dev/null +++ b/scripts/bash-autocomplete/.gitignore @@ -0,0 +1 @@ +cbmc.sh diff --git a/scripts/bash-autocomplete/Readme.md b/scripts/bash-autocomplete/Readme.md new file mode 100644 index 00000000000..00101d99159 --- /dev/null +++ b/scripts/bash-autocomplete/Readme.md @@ -0,0 +1,31 @@ +# CBMC Autocomplete Scripts for Bash +This directory contains an autocomplete script for bash. +## Installation +1. Compile cbmc and + +2. `cd scripts/bash-autocomplete` + +3. `./extract-switches.sh` + +4. Put the following at the end of you in your `~/.bashrc`, with the directories adapted to your directory structure: + ```bash + cbmcautocomplete=~/diffblue/cbmc/scripts/bash-autocomplete/cbmc.sh + if [ -f $cbmcautocomplete ]; then + . $cbmcautocomplete + fi + ``` +## Usage +As with the usual autocomplete in bash, start typing a switch to complete it, for example: +``` +cbmc --clas +``` +will complete to +``` +cbmc --classpath +``` + +## Features implemented + +* Completing all switches +* Completing values for `--cover`, `--mm` and `--arch` +* When completing a name of a file to analyze, only files with supported extensions are shown. diff --git a/scripts/bash-autocomplete/cbmc.sh.template b/scripts/bash-autocomplete/cbmc.sh.template new file mode 100644 index 00000000000..cbd64762b2d --- /dev/null +++ b/scripts/bash-autocomplete/cbmc.sh.template @@ -0,0 +1,43 @@ +#!/bin/bash +_cbmc_autocomplete() +{ + #list of all switches cbmc has. IMPORTANT: in the template file, this variable must be defined on line 5. + local switches="" + #word on which the cursor is + local cur=${COMP_WORDS[COMP_CWORD]} + #previous word (in case it is a switch with a parameter) + local prev=${COMP_WORDS[COMP_CWORD-1]} + + #check if the command before cursor is a switch that takes parameters, if yes, + #offer a choice of parameters + case "$prev" in + --cover) #for coverage we list the options explicitly + COMPREPLY=( $( compgen -W "assertion path branch location decision condition mcdc cover" -- $cur ) ) + return 0 + ;; + --mm) #for memory models we list the options explicitly + COMPREPLY=( $( compgen -W "sc tso pso" -- $cur ) ) + return 0 + ;; + --arch) #for architecture we list the options explicitly + COMPREPLY=( $( compgen -W "i386 x86_64" -- $cur ) ) + return 0 + ;; + -I|--classpath|-cp|--outfile|--existing-coverage|--graphml-cex) + #a switch that takes a file parameter of which we don't know an extension + #TODO probably we can do more for -I, --classpath, -cp + _filedir + return 0 + ;; + esac + + #complete a switch from a standard list, if the parameter under cursor starts with a hyphen + if [[ "$cur" == -* ]]; then + COMPREPLY=( $( compgen -W "$switches" -- $cur ) ) + return 0 + fi + + #if none of the above applies, offer directories and files that we can analyze + _filedir "@(class|jar|cpp|cc|c\+\+|ii|cxx|c|i|gb)" +} +complete -F _cbmc_autocomplete cbmc diff --git a/scripts/bash-autocomplete/extract_switches.sh b/scripts/bash-autocomplete/extract_switches.sh new file mode 100755 index 00000000000..e000b469bea --- /dev/null +++ b/scripts/bash-autocomplete/extract_switches.sh @@ -0,0 +1,48 @@ +#!/bin/bash +echo "Compiling the helper file to extract the raw list of parameters from cbmc" +g++ -c -MMD -MP -std=c++11 -Wall -I ../../src/ -ftrack-macro-expansion=0 -fno-diagnostics-show-caret switch_extractor_helper.c -o tmp.o 2> pragma.txt + +retval=$? + +#clean up compiled files, we don't need them. +rm tmp.o 2> /dev/null +rm tmp.d 2> /dev/null + +#check if compilation went fine +if [ $retval -ne 0 ]; then + echo "Problem compiling the helper file, parameter list not extracted." + exit 1; +fi + +echo "Converting the raw parameter list to the format required by autocomplete scripts" +rawstring=`sed "s/^.*pragma message: \(.*\)/\1/" pragma.txt` +#delete pragma file, we won't need it +rm pragma.txt 2> /dev/null + +#now the main bit, convert from raw format to a proper list of switches +cleanstring=`( + #extract 2-hyphen switches, such as --foo + #grep for '(foo)' expressions, and then use sed to remove parantheses and put '--' at the start + (echo $rawstring | grep -o "([^)]*)" | sed "s/^.\(.*\).$/--\1/") ; + #extract 1-hyphen switches, such as -F + #use sed to remove all (foo) expressions, then you're left with switches and ':', so grep the colons out and then use sed to include the '-' + (echo $rawstring | sed "s/([^)]*)//g" | grep -o "[a-zA-Z0-9]" | sed "s/\(.*\)/-\1/") + ) | tr '\n' ' '` + +#sanity check that there is only one line of output +if [ `echo $cleanstring | wc -l | awk '{print $1}'` -ne 1 ]; then + echo "Problem converting the parameter list to the correct format, I was expecting one line but either got 0 or >2. This is likely to be an error in this conversion script." + exit 1; +fi + +#sanity check that there are no dangerous characters +echo $cleanstring | grep -q "[^a-zA-Z0-9 -]" +if [ $? -eq 0 ]; then + echo "Problem converting the parameter list to the correct format, illegal characters detected. This is likely to be an error in this conversion script." + exit 1; +fi + +echo "Injecting the parameter list to the autocomplete file." +sed "5 s/.*/ local switches=\"$cleanstring\"/" cbmc.sh.template > cbmc.sh + +rm pragma.txt 2> /dev/null diff --git a/scripts/bash-autocomplete/switch_extractor_helper.c b/scripts/bash-autocomplete/switch_extractor_helper.c new file mode 100644 index 00000000000..4d9cc2e56fe --- /dev/null +++ b/scripts/bash-autocomplete/switch_extractor_helper.c @@ -0,0 +1,3 @@ +#include "cbmc/cbmc_parse_options.h" + +#pragma message CBMC_OPTIONS From d485c88a2cc9bc72dcafcee97da98cadb73f4961 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Wed, 25 Jan 2017 15:11:44 +0000 Subject: [PATCH 49/59] Factor class identifier extraction out of remove virtuals This will be useful for other passes that inspect an object's dynamic clsid, such as the forthcoming lower-instanceof pass. --- src/goto-programs/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/goto-programs/Makefile b/src/goto-programs/Makefile index 485bc211e24..8b69282c381 100644 --- a/src/goto-programs/Makefile +++ b/src/goto-programs/Makefile @@ -22,6 +22,7 @@ SRC = goto_convert.cpp goto_convert_function_call.cpp \ show_goto_functions_xml.cpp \ remove_static_init_loops.cpp \ remove_instanceof.cpp \ + class_identifier.cpp \ system_library_symbols.cpp \ From 99eb1a0b3df91439d8fb635ceadacfe68b1e9c76 Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Tue, 24 Jan 2017 13:32:11 +0000 Subject: [PATCH 50/59] Discover lexical scopes for anonymous variables This enables tight variable scoping even when Java debug information is not available, which helps with analyses that benefit from DEAD instructions keeping their domains as small as possible. --- .../java_bytecode_convert_method.cpp | 37 +++++++++++++++++++ .../java_bytecode_convert_method_class.h | 4 ++ 2 files changed, 41 insertions(+) diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index f101d19c824..dda893544bc 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -804,6 +804,43 @@ static void gather_symbol_live_ranges( /*******************************************************************\ +Function: java_bytecode_convert_methodt::check_static_field_stub + + Inputs: `se`: Symbol expression referring to a static field + `basename`: The static field's basename + + Outputs: Creates a symbol table entry for the static field if one + doesn't exist already. + + Purpose: See above + +\*******************************************************************/ + +void java_bytecode_convert_methodt::check_static_field_stub( + const symbol_exprt &symbol_expr, + const irep_idt &basename) +{ + const auto &id=symbol_expr.get_identifier(); + if(symbol_table.symbols.find(id)==symbol_table.symbols.end()) + { + // Create a stub, to be overwritten if/when the real class is loaded. + symbolt new_symbol; + new_symbol.is_static_lifetime=true; + new_symbol.is_lvalue=true; + new_symbol.is_state_var=true; + new_symbol.name=id; + new_symbol.base_name=basename; + new_symbol.type=symbol_expr.type(); + new_symbol.pretty_name=new_symbol.name; + new_symbol.mode=ID_java; + new_symbol.is_type=false; + new_symbol.value.make_nil(); + symbol_table.add(new_symbol); + } +} + +/*******************************************************************\ + Function: java_bytecode_convert_methodt::convert_instructions Inputs: diff --git a/src/java_bytecode/java_bytecode_convert_method_class.h b/src/java_bytecode/java_bytecode_convert_method_class.h index ae4ba711640..6844e337f22 100644 --- a/src/java_bytecode/java_bytecode_convert_method_class.h +++ b/src/java_bytecode/java_bytecode_convert_method_class.h @@ -219,6 +219,10 @@ class java_bytecode_convert_methodt:public messaget const code_typet &); const bytecode_infot &get_bytecode_info(const irep_idt &statement); + + void check_static_field_stub( + const symbol_exprt &se, + const irep_idt &basename); }; #endif From 7ac505d22314729638c7ef40c121cb7872e2150b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=BCdemann?= Date: Sat, 21 Jan 2017 00:42:53 +0100 Subject: [PATCH 51/59] loop unwinding in static init of Java enum Static initialization of Java enums sometimes contains extra code that loops over the array of enum elements. This often prevents initialization of the enumeration and leads to zero coverage. This patch counts the number of enum elements, and explicitely unwinds all loops in to this number + 1. This acts as a heuristic to make static inits of enums finish. --- src/util/irep_ids.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/irep_ids.txt b/src/util/irep_ids.txt index 9bcb7807671..5ada8981c19 100644 --- a/src/util/irep_ids.txt +++ b/src/util/irep_ids.txt @@ -737,6 +737,7 @@ bswap java_bytecode_index java_instanceof java_super_method_call +skip_initialize java_enum_static_unwind string_constraint string_not_contains_constraint From 0cf34af4dcb60170b2c753d3aae5ac33e120dfe1 Mon Sep 17 00:00:00 2001 From: Cristina Date: Thu, 9 Feb 2017 15:36:36 +0000 Subject: [PATCH 52/59] Support for Java assume --- src/Makefile | 10 +++++++++- .../java_bytecode_convert_method.cpp | 20 ++++++++++++++++++- .../library/src/org/cprover/CProver.java | 11 ++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 src/java_bytecode/library/src/org/cprover/CProver.java diff --git a/src/Makefile b/src/Makefile index 269ddeda140..e4c62f33eed 100644 --- a/src/Makefile +++ b/src/Makefile @@ -108,4 +108,12 @@ libzip-build: @echo "Building libzip" @(cd ../libzip; BASE=`pwd`; ./configure --with-zlib=$(BASE)/zlib ; make) -.PHONY: minisat2-download glucose-download zlib-download libzip-download libzip-build +cprover-jar-build: + @echo "Building org.cprover.jar" + @(cd java_bytecode/library/; \ + mkdir -p target; \ + javac -d target/ `find src/ -name "*.java"`; \ + cd target; jar cf org.cprover.jar `find . -name "*.class"`; \ + mv org.cprover.jar ../../../) + +.PHONY: minisat2-download glucose-download zlib-download libzip-download libzip-build cprover-jar-build diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index dda893544bc..447b5dacb80 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -5,7 +5,6 @@ Module: JAVA Bytecode Language Conversion Author: Daniel Kroening, kroening@kroening.com \*******************************************************************/ - #ifdef DEBUG #include #endif @@ -1093,6 +1092,25 @@ codet java_bytecode_convert_methodt::convert_instructions( get_message_handler()); } } + // replace calls to CProver.assume + else if(statement=="invokestatic" && + id2string(arg0.get(ID_identifier))== + "java::org.cprover.CProver.assume:(Z)V") + { + const code_typet &code_type=to_code_type(arg0.type()); + // sanity check: function has the right number of args + assert(code_type.parameters().size()==1); + + exprt operand = pop(1)[0]; + // we may need to adjust the type of the argument + if(operand.type()!=bool_typet()) + operand.make_typecast(bool_typet()); + + c=code_assumet(operand); + source_locationt loc=i_it->source_location; + loc.set_function(method_id); + c.add_source_location()=loc; + } else if(statement=="invokeinterface" || statement=="invokespecial" || statement=="invokevirtual" || diff --git a/src/java_bytecode/library/src/org/cprover/CProver.java b/src/java_bytecode/library/src/org/cprover/CProver.java new file mode 100644 index 00000000000..72c3eeb1d70 --- /dev/null +++ b/src/java_bytecode/library/src/org/cprover/CProver.java @@ -0,0 +1,11 @@ +package org.cprover; + +public final class CProver +{ + public static boolean enableAssume=true; + public static void assume(boolean condition) + { + if(enableAssume) + throw new RuntimeException("Cannot execute program with CProver.assume()"); + } +} From 1436e39606ad256052d19eb874a26db101663552 Mon Sep 17 00:00:00 2001 From: Cristina Date: Thu, 9 Feb 2017 19:16:01 +0000 Subject: [PATCH 53/59] Regression tests for Java assume --- regression/cbmc-java/assume1/Assume1.class | Bin 0 -> 660 bytes regression/cbmc-java/assume1/Assume1.java | 10 ++++++++++ regression/cbmc-java/assume1/test.desc | 8 ++++++++ regression/cbmc-java/assume2/Assume2.class | Bin 0 -> 661 bytes regression/cbmc-java/assume2/Assume2.java | 10 ++++++++++ regression/cbmc-java/assume2/test.desc | 8 ++++++++ regression/cbmc-java/assume3/Assume3.class | Bin 0 -> 684 bytes regression/cbmc-java/assume3/Assume3.java | 10 ++++++++++ regression/cbmc-java/assume3/test.desc | 8 ++++++++ 9 files changed, 54 insertions(+) create mode 100644 regression/cbmc-java/assume1/Assume1.class create mode 100644 regression/cbmc-java/assume1/Assume1.java create mode 100644 regression/cbmc-java/assume1/test.desc create mode 100644 regression/cbmc-java/assume2/Assume2.class create mode 100644 regression/cbmc-java/assume2/Assume2.java create mode 100644 regression/cbmc-java/assume2/test.desc create mode 100644 regression/cbmc-java/assume3/Assume3.class create mode 100644 regression/cbmc-java/assume3/Assume3.java create mode 100644 regression/cbmc-java/assume3/test.desc diff --git a/regression/cbmc-java/assume1/Assume1.class b/regression/cbmc-java/assume1/Assume1.class new file mode 100644 index 0000000000000000000000000000000000000000..b9a49bc9971d81889935e4cefba60fffd292840c GIT binary patch literal 660 zcmZWmO>fgc5PcIn-o!OcnwAp6M*}U8a==3BjS3Y7kSc`_sZ}L%K-xIlvc=6-Yp3G3 zRN{uj8IULf3GVzT#H_KJ1Bda<&b)c^X8ill_n!bZupXj@PKYbGT1S9u0@p+M=m@NY z=;DUJO~T@u%ra$jZ6?`coyk$E#snG?f=xZq`9p%&Ti+x2eKS^s#z0Th^Xbt@*7KOOz00JZztI_?K6sR6(<62N0n_Xo!!*5Z$42kiwh0$@a+$n+CXdU$+GdiL zW5XRYwTXJF-H@o{xpyc}WP~|H0;>_$a4SL`A))OGaVjSVF+=|?^u$_Y38L&3xE_MCyTXUjp+<#ekzJV;{JJ~}gyD@9*r(7c}k5#6v8lMm4h4LvE z_-aGGa=`xppk~|2fJNYCk`r@=WkFXJv2CWPzIoh1@<+xu*ezL z{F>3O*6jozApDQ;y>F;|hIfia=RM|rz<+gy>MzIZ6}3); + assert x>0; + } +} diff --git a/regression/cbmc-java/assume1/test.desc b/regression/cbmc-java/assume1/test.desc new file mode 100644 index 00000000000..1f80a1c1e86 --- /dev/null +++ b/regression/cbmc-java/assume1/test.desc @@ -0,0 +1,8 @@ +CORE +Assume1.class +--function Assume1.foo +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring diff --git a/regression/cbmc-java/assume2/Assume2.class b/regression/cbmc-java/assume2/Assume2.class new file mode 100644 index 0000000000000000000000000000000000000000..36e09875d7d72406f27d2512b116cd7a586871d6 GIT binary patch literal 661 zcmZWmO>fgc5PcIn-qzUno^WK~BuixK(09eCnga*11F5qH_0G9+VNAS@VxDw$i zdIHx7iz_nEl`XWH<_~o)$C;WCXhaCs^;8%430{A7hu{y)L=l=pJylO<`(tId9hlG_ znp9>x(rS0F9{u9A&I#f0L7va{)!lnc^U4^e>2EqVddp{%aAvEJ>6<6=pz3R^r&%Q% zZJC)()nn~M;)>_ao;;K><`4^9kFkOqF+xOyjw>XYobDzJ{X5VjYmFs{s#oAy0JN~cv4J)g`NcKA zWVEaGy1{!0{{wvQD{7zM9ii0~?=bfr{)=POe>!5XB%Uwz1-CcYTlkMa4`;E&xMe;8 pyl{h-7<2B#=~^iTEVP3!5J#2XXL$d+b`*8g;te-jhc7jp{{vk5b}Ik? literal 0 HcmV?d00001 diff --git a/regression/cbmc-java/assume2/Assume2.java b/regression/cbmc-java/assume2/Assume2.java new file mode 100644 index 00000000000..6991167bfb8 --- /dev/null +++ b/regression/cbmc-java/assume2/Assume2.java @@ -0,0 +1,10 @@ +import org.cprover.CProver; + +class Assume2 +{ + static void foo(int x) + { + CProver.assume(x>3); + assert x>4; + } +} diff --git a/regression/cbmc-java/assume2/test.desc b/regression/cbmc-java/assume2/test.desc new file mode 100644 index 00000000000..35a954116f8 --- /dev/null +++ b/regression/cbmc-java/assume2/test.desc @@ -0,0 +1,8 @@ +CORE +Assume2.class +--function Assume2.foo +^EXIT=10$ +^SIGNAL=0$ +^VERIFICATION FAILED$ +-- +^warning: ignoring diff --git a/regression/cbmc-java/assume3/Assume3.class b/regression/cbmc-java/assume3/Assume3.class new file mode 100644 index 0000000000000000000000000000000000000000..916ad4065fb77e04ba492a6f7499799ea22c85f7 GIT binary patch literal 684 zcmZuvO>fgc5PcIn-qjFF61OtQv!_%-mcDc`H0~3xAqC{AfGBid#E$Dx0p|qd2PXj?l4be zx-X5k>w42I-|B+k51$mpVy+(UaD%zj8DYKuW_T!%Wt_@v7LQ7!v)N8HK$;m-qW_c$ z=SHPW-o21Vb^q3GlGgHqQNA#VdakXQu%7q8jtH@WP~dimP236LBOvsavl;rw_%ma2 zLl8Ar;BJU}=o30i@XN`eN=lZOn^~M3nfzFpc<`!!rOU4pOeM?WroX zQPZ=bY^YptflqhLx8dVCzK834g7dFP%Wt9)KDJhRylCLkZyo7^Z2$lO literal 0 HcmV?d00001 diff --git a/regression/cbmc-java/assume3/Assume3.java b/regression/cbmc-java/assume3/Assume3.java new file mode 100644 index 00000000000..895deee9ca0 --- /dev/null +++ b/regression/cbmc-java/assume3/Assume3.java @@ -0,0 +1,10 @@ +import org.cprover.CProver; + +class Assume3 +{ + public static void main(String[] args) + { + CProver.assume(false); + assert false; + } +} diff --git a/regression/cbmc-java/assume3/test.desc b/regression/cbmc-java/assume3/test.desc new file mode 100644 index 00000000000..0ad8c00399f --- /dev/null +++ b/regression/cbmc-java/assume3/test.desc @@ -0,0 +1,8 @@ +CORE +Assume3.class + +^EXIT=0$ +^SIGNAL=0$ +^VERIFICATION SUCCESSFUL$ +-- +^warning: ignoring From 5c309076a390ff8993ece33466f8b65005c14c4d Mon Sep 17 00:00:00 2001 From: Cristina Date: Tue, 20 Sep 2016 14:47:20 +0100 Subject: [PATCH 54/59] Remove assume as coverage target --- src/goto-instrument/cover.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/goto-instrument/cover.cpp b/src/goto-instrument/cover.cpp index fa92bc27cc7..991f91b75b7 100644 --- a/src/goto-instrument/cover.cpp +++ b/src/goto-instrument/cover.cpp @@ -35,7 +35,12 @@ class basic_blockst source_location_map[block_count]=it->source_location; next_is_target= +#if 0 + // Disabled for being too messy it->is_goto() || it->is_function_call() || it->is_assume(); +#else + it->is_goto() || it->is_function_call(); +#endif } } From e55f20b6f30656881f80090f098937206704d262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=BCdemann?= Date: Wed, 1 Feb 2017 16:05:54 +0100 Subject: [PATCH 55/59] output covered lines as CSV in show_properties --- src/goto-instrument/cover.cpp | 56 ++++++++++++++++++++++----- src/goto-programs/show_properties.cpp | 3 ++ src/util/irep_ids.txt | 3 +- src/util/source_location.h | 10 +++++ 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/goto-instrument/cover.cpp b/src/goto-instrument/cover.cpp index 991f91b75b7..489ee44eb5e 100644 --- a/src/goto-instrument/cover.cpp +++ b/src/goto-instrument/cover.cpp @@ -10,8 +10,10 @@ Date: May 2016 #include #include +#include #include +#include #include "cover.h" @@ -28,6 +30,11 @@ class basic_blockst if(next_is_target || it->is_target()) block_count++; + const irep_idt &line=it->source_location.get_line(); + if(!line.empty()) + block_line_cover_map[block_count] + .insert(unsafe_string2unsigned(id2string(line))); + block_map[it]=block_count; if(!it->source_location.is_nil() && @@ -42,6 +49,24 @@ class basic_blockst it->is_goto() || it->is_function_call(); #endif } + + // create list of covered lines as CSV string and set as property of source + // location of basic block + for(const auto &cover_set : block_line_cover_map) + { + std::string covered_lines; + bool first=true; + for(const auto &line_number : cover_set.second) + { + if(first) + first=false; + else + covered_lines+=","; + covered_lines+=std::to_string(line_number); + } + source_location_map[cover_set.first] + .set_basic_block_covered_lines(covered_lines); + } } // map program locations to block numbers @@ -52,6 +77,11 @@ class basic_blockst typedef std::map source_location_mapt; source_location_mapt source_location_map; + // map block numbers to set of line numbers + typedef std::map > + block_line_cover_mapt; + block_line_cover_mapt block_line_cover_map; + inline unsigned operator[](goto_programt::const_targett t) { return block_map[t]; @@ -419,7 +449,7 @@ std::set collect_mcdc_controlling_nested( const std::set &decisions) { // To obtain the 1st-level controlling conditions - std::set controlling = collect_mcdc_controlling(decisions); + std::set controlling=collect_mcdc_controlling(decisions); std::set result; // For each controlling condition, to check if it contains @@ -632,7 +662,7 @@ void remove_repetition(std::set &exprs) **/ for(auto &y : new_exprs) { - bool iden = true; + bool iden=true; for(auto &c : conditions) { std::set signs1=sign_of_expr(c, x); @@ -674,7 +704,7 @@ void remove_repetition(std::set &exprs) } // update the original ''exprs'' - exprs = new_exprs; + exprs=new_exprs; } /*******************************************************************\ @@ -843,7 +873,8 @@ bool is_mcdc_pair( if(diff_count==1) return true; - else return false; + else + return false; } /*******************************************************************\ @@ -968,7 +999,8 @@ void minimize_mcdc_controlling( { controlling=new_controlling; } - else break; + else + break; } } @@ -1302,9 +1334,12 @@ void instrument_cover_goals( const std::set decisions=collect_decisions(i_it); std::set both; - std::set_union(conditions.begin(), conditions.end(), - decisions.begin(), decisions.end(), - inserter(both, both.end())); + std::set_union( + conditions.begin(), + conditions.end(), + decisions.begin(), + decisions.end(), + inserter(both, both.end())); const source_locationt source_location=i_it->source_location; @@ -1402,6 +1437,9 @@ void instrument_cover_goals( f_it->first=="__CPROVER_initialize") continue; - instrument_cover_goals(symbol_table, f_it->second.body, criterion); + instrument_cover_goals( + symbol_table, + f_it->second.body, + criterion); } } diff --git a/src/goto-programs/show_properties.cpp b/src/goto-programs/show_properties.cpp index c7a6bdedf3f..edde459b933 100644 --- a/src/goto-programs/show_properties.cpp +++ b/src/goto-programs/show_properties.cpp @@ -130,6 +130,9 @@ void show_properties_json( json_properties.push_back(jsont()).make_object(); json_property["name"]=json_stringt(id2string(property_id)); json_property["class"]=json_stringt(id2string(property_class)); + if(!source_location.get_basic_block_covered_lines().empty()) + json_property["covered_lines"]= + json_stringt(id2string(source_location.get_basic_block_covered_lines())); json_property["sourceLocation"]=json(source_location); json_property["description"]=json_stringt(id2string(description)); json_property["expression"]= diff --git a/src/util/irep_ids.txt b/src/util/irep_ids.txt index 5ada8981c19..29907f11040 100644 --- a/src/util/irep_ids.txt +++ b/src/util/irep_ids.txt @@ -801,4 +801,5 @@ cprover_string_to_char_array_func cprover_string_to_lower_case_func cprover_string_to_upper_case_func cprover_string_trim_func -cprover_string_value_of_func \ No newline at end of file +cprover_string_value_of_func +basic_block_covered_lines \ No newline at end of file diff --git a/src/util/source_location.h b/src/util/source_location.h index b24befcb8c4..9d905c775cb 100644 --- a/src/util/source_location.h +++ b/src/util/source_location.h @@ -73,6 +73,11 @@ class source_locationt:public irept return get(ID_java_bytecode_index); } + const irep_idt &get_basic_block_covered_lines() const + { + return get(ID_basic_block_covered_lines); + } + void set_file(const irep_idt &file) { set(ID_file, file); @@ -128,6 +133,11 @@ class source_locationt:public irept set(ID_java_bytecode_index, index); } + void set_basic_block_covered_lines(const irep_idt &covered_lines) + { + return set(ID_basic_block_covered_lines, covered_lines); + } + void set_hide() { set(ID_hide, true); From 2ae1f47f3a3a5e0af15b022205df3f4942792a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=BCdemann?= Date: Mon, 13 Feb 2017 15:59:29 +0100 Subject: [PATCH 56/59] compress list of lines into line ranges --- src/goto-instrument/cover.cpp | 19 ++--- src/goto-programs/show_properties.cpp | 5 +- src/util/Makefile | 2 +- src/util/format_number_range.cpp | 114 ++++++++++++++++++++++++++ src/util/format_number_range.h | 21 +++++ 5 files changed, 147 insertions(+), 14 deletions(-) create mode 100644 src/util/format_number_range.cpp create mode 100644 src/util/format_number_range.h diff --git a/src/goto-instrument/cover.cpp b/src/goto-instrument/cover.cpp index 489ee44eb5e..9f1aa347679 100644 --- a/src/goto-instrument/cover.cpp +++ b/src/goto-instrument/cover.cpp @@ -12,6 +12,7 @@ Date: May 2016 #include #include +#include #include #include @@ -51,19 +52,15 @@ class basic_blockst } // create list of covered lines as CSV string and set as property of source - // location of basic block + // location of basic block, compress to ranges if applicable + format_number_ranget format_lines; for(const auto &cover_set : block_line_cover_map) { - std::string covered_lines; - bool first=true; - for(const auto &line_number : cover_set.second) - { - if(first) - first=false; - else - covered_lines+=","; - covered_lines+=std::to_string(line_number); - } + assert(!cover_set.second.empty()); + std::vector + line_list{cover_set.second.begin(), cover_set.second.end()}; + + std::string covered_lines=format_lines(line_list); source_location_map[cover_set.first] .set_basic_block_covered_lines(covered_lines); } diff --git a/src/goto-programs/show_properties.cpp b/src/goto-programs/show_properties.cpp index edde459b933..cbbb00225c7 100644 --- a/src/goto-programs/show_properties.cpp +++ b/src/goto-programs/show_properties.cpp @@ -131,8 +131,9 @@ void show_properties_json( json_property["name"]=json_stringt(id2string(property_id)); json_property["class"]=json_stringt(id2string(property_class)); if(!source_location.get_basic_block_covered_lines().empty()) - json_property["covered_lines"]= - json_stringt(id2string(source_location.get_basic_block_covered_lines())); + json_property["coveredLines"]= + json_stringt( + id2string(source_location.get_basic_block_covered_lines())); json_property["sourceLocation"]=json(source_location); json_property["description"]=json_stringt(id2string(description)); json_property["expression"]= diff --git a/src/util/Makefile b/src/util/Makefile index 6cc42a18fb8..c605d26c747 100644 --- a/src/util/Makefile +++ b/src/util/Makefile @@ -22,7 +22,7 @@ SRC = arith_tools.cpp base_type.cpp cmdline.cpp config.cpp symbol_table.cpp \ irep_ids.cpp byte_operators.cpp string2int.cpp file_util.cpp \ memory_info.cpp pipe_stream.cpp irep_hash.cpp endianness_map.cpp \ ssa_expr.cpp json_irep.cpp json_expr.cpp \ - string_utils.cpp + format_number_range.cpp string_utils.cpp INCLUDES= -I .. diff --git a/src/util/format_number_range.cpp b/src/util/format_number_range.cpp new file mode 100644 index 00000000000..146808118ce --- /dev/null +++ b/src/util/format_number_range.cpp @@ -0,0 +1,114 @@ +/*******************************************************************\ + +Module: Format vector of numbers into a compressed range + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + +#include +#include + +#include "format_number_range.h" + +/*******************************************************************\ + +Function: format_number_range::operator() + + Inputs: vector of numbers + + Outputs: string of compressed number range representation + + Purpose: create shorter representation for output + +\*******************************************************************/ + +std::string format_number_ranget::operator()(std::vector &numbers) +{ + std::string number_range; + std::sort(numbers.begin(), numbers.end()); + unsigned end_number=numbers.back(); + if(numbers.front()==end_number) + number_range=std::to_string(end_number); // only single number + else + { + bool next=true; + bool first=true; + bool range=false; + unsigned start_number=numbers.front(); + unsigned last_number=start_number; + + for(const auto &number : numbers) + { + if(next) + { + next=false; + start_number=number; + last_number=number; + } + // advance one forward + else + { + if(number==last_number+1 && !(number==end_number)) + { + last_number++; + if(last_number>start_number+1) + range=true; + } + // end this block range + else + { + if(first) + first=false; + else + number_range+=","; + if(last_number>start_number) + { + if(range) + { + if(number==end_number && number==last_number+1) + number_range+= + std::to_string(start_number)+"-"+std::to_string(end_number); + else if(number==end_number) + number_range+= + std::to_string(start_number)+"-"+std::to_string(last_number)+ + ","+std::to_string(end_number); + else + number_range+= + std::to_string(start_number)+"-"+std::to_string(last_number); + } + else + { + if(number!=end_number) + number_range+= + std::to_string(start_number)+","+std::to_string(last_number); + else + number_range+= + std::to_string(start_number)+","+std::to_string(last_number)+ + std::to_string(end_number); + } + start_number=number; + last_number=number; + range=false; + continue; + } + else + { + if(number!=end_number) + number_range+=std::to_string(start_number); + else + number_range+=std::to_string(start_number)+","+ + std::to_string(end_number); + start_number=number; + last_number=number; + range=false; + continue; // already set next start number + } + next=true; + } + } + } + } + assert(!number_range.empty()); + return number_range; +} diff --git a/src/util/format_number_range.h b/src/util/format_number_range.h new file mode 100644 index 00000000000..7ff016e9c4d --- /dev/null +++ b/src/util/format_number_range.h @@ -0,0 +1,21 @@ +/*******************************************************************\ + +Module: Format vector of numbers into a compressed range + +Author: Daniel Kroening, kroening@kroening.com + +\*******************************************************************/ + +#ifndef CPROVER_UTIL_FORMAT_NUMBER_RANGE_H +#define CPROVER_UTIL_FORMAT_NUMBER_RANGE_H + +#include +#include + +class format_number_ranget +{ +public: + std::string operator()(std::vector &); +}; + +#endif // CPROVER_UTIL_FORMAT_NUMBER_RANGE_H From f5f47a7043bf3389d41ca2a0628f58ec9b3670e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20G=C3=BCdemann?= Date: Wed, 15 Feb 2017 23:53:28 +0100 Subject: [PATCH 57/59] add regression test for coverage lines --- regression/cbmc-java/covered1/covered1.class | Bin 0 -> 750 bytes regression/cbmc-java/covered1/covered1.java | 37 +++++++++++++++++++ regression/cbmc-java/covered1/test.desc | 19 ++++++++++ 3 files changed, 56 insertions(+) create mode 100644 regression/cbmc-java/covered1/covered1.class create mode 100644 regression/cbmc-java/covered1/covered1.java create mode 100644 regression/cbmc-java/covered1/test.desc diff --git a/regression/cbmc-java/covered1/covered1.class b/regression/cbmc-java/covered1/covered1.class new file mode 100644 index 0000000000000000000000000000000000000000..7cb91496b7df5bc0b1e7f8b6db0aa9a4992bd947 GIT binary patch literal 750 zcmYk4TWb?h6ouEBOJ*jSCQa%+wf9SU)TC(>1*uXHiUBVVl?py}G8x*`n3Rwf?N9N^ zw?5lA2nzlHf0VlRp`r}?+xwiuIcx3B{QULp2Y?11WKlpRKptxXEx04NE4U}93TlFN zL0zyR*c3E8G(Fr`Q12Nn#s|ikf_1jeB4V@^>_Ml)>WysI1sj4*K||0~$ZU1{-O*zO zx6*2@?I}1<2AxEq@T}WUUYxvZC&O1!yT_f0-BA?3eI6Z~HT4zzt+;o2-LA;x?C#)X z7$-Yjb0Hp_Cc~stuO3CGQHU8VhnPe$L`g6uxGA_LC<|^2t_rRRt_ZHw`A%h|$M8{-GG5hkKSyRDeikN*$m^Iy)OhYEqlR2ll zS<@b~#hAe?6y{ichs_Uot-nHPCxxZm6t>Q!aHMjj%4jczr~MSZE>9n(2$=R$Wc3#W z Date: Fri, 17 Feb 2017 11:12:48 +0100 Subject: [PATCH 58/59] fix problem with missing comma / range fix for reaching end --- src/util/format_number_range.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/util/format_number_range.cpp b/src/util/format_number_range.cpp index 146808118ce..cca3bbf154c 100644 --- a/src/util/format_number_range.cpp +++ b/src/util/format_number_range.cpp @@ -8,6 +8,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include #include "format_number_range.h" @@ -83,9 +84,16 @@ std::string format_number_ranget::operator()(std::vector &numbers) number_range+= std::to_string(start_number)+","+std::to_string(last_number); else - number_range+= - std::to_string(start_number)+","+std::to_string(last_number)+ - std::to_string(end_number); + { + if(start_number+1==last_number && last_number+1==number) + number_range+= + std::to_string(start_number)+"-"+std::to_string(end_number); + else + number_range+= + std::to_string(start_number)+ + ","+std::to_string(last_number)+ + ","+std::to_string(end_number); + } } start_number=number; last_number=number; From b7d828bc18cf807c8b4c649f676e6945d2d9633f Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 16 Jan 2017 15:11:43 +0000 Subject: [PATCH 59/59] Updated dump-C to use the new class --- src/goto-instrument/dump_c.cpp | 260 +------------------ src/goto-instrument/dump_c_class.h | 11 +- src/goto-programs/system_library_symbols.cpp | 4 +- src/goto-programs/system_library_symbols.h | 3 +- 4 files changed, 11 insertions(+), 267 deletions(-) diff --git a/src/goto-instrument/dump_c.cpp b/src/goto-instrument/dump_c.cpp index d06a79e01d8..24005138109 100644 --- a/src/goto-instrument/dump_c.cpp +++ b/src/goto-instrument/dump_c.cpp @@ -163,7 +163,8 @@ void dump_ct::operator()(std::ostream &os) } // we don't want to dump in full all definitions - if(!tag_added && ignore(symbol)) + if(!tag_added && + system_symbols.is_symbol_internal_symbol(symbol, system_headers)) continue; if(!symbols_sorted.insert(name_str).second) @@ -344,7 +345,7 @@ void dump_ct::convert_compound( ns.lookup(to_symbol_type(type).get_identifier()); assert(symbol.is_type); - if(!ignore(symbol)) + if(!system_symbols.is_symbol_internal_symbol(symbol, system_headers)) convert_compound(symbol.type, unresolved, recursive, os); } else if(type.id()==ID_c_enum_tag) @@ -353,7 +354,7 @@ void dump_ct::convert_compound( ns.lookup(to_c_enum_tag_type(type).get_identifier()); assert(symbol.is_type); - if(!ignore(symbol)) + if(!system_symbols.is_symbol_internal_symbol(symbol, system_headers)) convert_compound(symbol.type, unresolved, recursive, os); } else if(type.id()==ID_array || type.id()==ID_pointer) @@ -610,259 +611,6 @@ void dump_ct::convert_compound_enum( /*******************************************************************\ -Function: dump_ct::init_system_library_map - -Inputs: - -Outputs: - -Purpose: - -\*******************************************************************/ - -#define ADD_TO_SYSTEM_LIBRARY(v, header) \ - for(size_t i=0; isecond); - return true; - } - - return false; -} - -/*******************************************************************\ - Function: dump_ct::cleanup_decl Inputs: diff --git a/src/goto-instrument/dump_c_class.h b/src/goto-instrument/dump_c_class.h index 6bb7b79638e..c8c77da5102 100644 --- a/src/goto-instrument/dump_c_class.h +++ b/src/goto-instrument/dump_c_class.h @@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +#include class dump_ct { @@ -30,7 +31,7 @@ class dump_ct language(factory()) { if(use_system_headers) - init_system_library_map(); + system_symbols=system_library_symbolst(); } virtual ~dump_ct() @@ -51,21 +52,15 @@ class dump_ct std::set system_headers; - typedef std::unordered_map - system_library_mapt; - system_library_mapt system_library_map; + system_library_symbolst system_symbols; typedef std::unordered_map declared_enum_constants_mapt; declared_enum_constants_mapt declared_enum_constants; - void init_system_library_map(); - std::string type_to_string(const typet &type); std::string expr_to_string(const exprt &expr); - bool ignore(const symbolt &symbol); - static std::string indent(const unsigned n) { return std::string(2*n, ' '); diff --git a/src/goto-programs/system_library_symbols.cpp b/src/goto-programs/system_library_symbols.cpp index 76023d0c455..250eb3b1cdb 100644 --- a/src/goto-programs/system_library_symbols.cpp +++ b/src/goto-programs/system_library_symbols.cpp @@ -284,7 +284,7 @@ Purpose: To find out if a symbol is an internal symbol. bool system_library_symbolst::is_symbol_internal_symbol( const symbolt &symbol, - std::set &out_system_headers) const + std::set &out_system_headers) const { const std::string &name_str=id2string(symbol.name); @@ -345,7 +345,7 @@ bool system_library_symbolst::is_symbol_internal_symbol( if(it!=system_library_map.end()) { - out_system_headers.insert(it->second); + out_system_headers.insert(id2string(it->second)); return true; } diff --git a/src/goto-programs/system_library_symbols.h b/src/goto-programs/system_library_symbols.h index a253b903bd8..9438e052a76 100644 --- a/src/goto-programs/system_library_symbols.h +++ b/src/goto-programs/system_library_symbols.h @@ -11,6 +11,7 @@ Author: Thomas Kiley #include #include +#include #include class symbolt; @@ -22,7 +23,7 @@ class system_library_symbolst bool is_symbol_internal_symbol( const symbolt &symbol, - std::set &out_system_headers) const; + std::set &out_system_headers) const; private: void init_system_library_map();