Static Value-Flow Analysis
Loading...
Searching...
No Matches
ae.cpp
Go to the documentation of this file.
1//===- ae.cpp -- Abstract Execution -------------------------------------//
2//
3// SVF: Static Value-Flow Analysis
4//
5// Copyright (C) <2013-2017> <Yulei Sui>
6//
7
8// This program is free software: you can redistribute it and/or modify
9// it under the terms of the GNU Affero General Public License as published by
10// the Free Software Foundation, either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU Affero General Public License for more details.
17
18// You should have received a copy of the GNU Affero General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21//===-----------------------------------------------------------------------===//
22
23/*
24 // Abstract Execution
25 //
26 // Author: Jiawei Wang, Xiao Cheng, Jiawei Yang, Jiawei Ren, Yulei Sui
27 */
29#include "WPA/WPAPass.h"
30#include "Util/CommandLine.h"
31#include "Util/Options.h"
32#include "WPA/Andersen.h"
33
34#include "AE/Core/RelExeState.h"
37#include <chrono>
38
39using namespace SVF;
40using namespace SVFUtil;
41
42
44 "symabs",
45 "symbolic abstraction test",
46 false
47);
48
50 "aetest",
51 "abstract execution basic function test",
52 false
53);
54
56{
57public:
59
61
62 static z3::context& getContext()
63 {
64 return Z3Expr::getContext();
65 }
66
68 {
69 outs() << "hello print\n";
70 }
71
74 {
75 auto start_time = std::chrono::high_resolution_clock::now();
77 auto end_time = std::chrono::high_resolution_clock::now();
78 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
80 outs() << "running time of RSY : " << duration.count()
81 << " microseconds\n";
82 return resRSY;
83 }
86 {
87 auto start_time = std::chrono::high_resolution_clock::now();
88 AbstractState resBilateral = rs.bilateral(inv, phi);
89 auto end_time = std::chrono::high_resolution_clock::now();
90 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
92 outs() << "running time of Bilateral: " << duration.count()
93 << " microseconds\n";
94 return resBilateral;
95 }
98 {
99 auto start_time = std::chrono::high_resolution_clock::now();
101 auto end_time = std::chrono::high_resolution_clock::now();
102 auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
104 outs() << "running time of BS : " << duration.count()
105 << " microseconds\n";
106 return resBS;
107 }
108
110 {
111 outs() << sucMsg("\t SUCCESS :") << "test1_1 start\n";
114 // var0 := [0, 1];
115 itv[0] = IntervalValue(0, 1);
116 relation[0] = getContext().int_const("0");
117 // var1 := var0 + 1;
118 relation[1] =
119 getContext().int_const("1") == getContext().int_const("0") + 1;
120 itv[1] = itv[0].getInterval() + IntervalValue(1);
121 // Test extract sub vars
122 Set<u32_t> res;
123 relation.extractSubVars(relation[1], res);
124 assert(res == Set<u32_t>({0, 1}) && "inconsistency occurs");
127 const Z3Expr& relExpr = relation[1];
128 const Z3Expr& initExpr = rs.gamma_hat(inv);
129 const Z3Expr& phi = (relExpr && initExpr).simplify();
130 AbstractState resRSY = rs.RSY(inv, phi);
131 AbstractState resBilateral = rs.bilateral(inv, phi);
133 // 0:[0,1] 1:[1,2]
134 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
135 for (auto r : resRSY.getVarToVal())
136 {
137 outs() << r.first << " " << r.second.getInterval() << "\n";
138 }
140 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
141 }
142
144 {
145 outs() << "test1_2 start\n";
148 // var0 := [0, 1];
149 relation[0] = getContext().int_const("0");
150 itv[0] = IntervalValue(0, 1);
151 // var1 := var0 + 1;
152 relation[1] =
153 getContext().int_const("1") == getContext().int_const("0") * 2;
154 itv[1] = itv[0].getInterval() * IntervalValue(2);
155
156 // Test extract sub vars
157 Set<u32_t> res;
158 relation.extractSubVars(relation[1], res);
159 assert(res == Set<u32_t>({0, 1}) && "inconsistency occurs");
162 const Z3Expr& relExpr = relation[1];
163 const Z3Expr& initExpr = rs.gamma_hat(inv);
164 const Z3Expr& phi = (relExpr && initExpr).simplify();
165 AbstractState resRSY = rs.RSY(inv, phi);
166 AbstractState resBilateral = rs.bilateral(inv, phi);
168 // 0:[0,1] 1:[0,2]
169 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
170 for (auto r : resRSY.getVarToVal())
171 {
172 outs() << r.first << " " << r.second.getInterval() << "\n";
173 }
175 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
176 }
177
179 {
180 outs() << "test2_1 start\n";
183 // var0 := [0, 10];
184 relation[0] = getContext().int_const("0");
185 itv[0] = IntervalValue(0, 10);
186 // var1 := var0;
187 relation[1] =
188 getContext().int_const("1") == getContext().int_const("0");
189 itv[1] = itv[0];
190 // var2 := var1 - var0;
191 relation[2] = getContext().int_const("2") ==
192 getContext().int_const("1") - getContext().int_const("0");
193 itv[2] = itv[1].getInterval() - itv[0].getInterval();
194 // Test extract sub vars
195 Set<u32_t> res;
196 relation.extractSubVars(relation[2], res);
197 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
200 const Z3Expr& relExpr = relation[2] && relation[1];
201 const Z3Expr& initExpr = rs.gamma_hat(inv);
202 const Z3Expr& phi = (relExpr && initExpr).simplify();
203 AbstractState resRSY = rs.RSY(inv, phi);
204 AbstractState resBilateral = rs.bilateral(inv, phi);
206 // 0:[0,10] 1:[0,10] 2:[0,0]
207 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
208 for (auto r : resRSY.getVarToVal())
209 {
210 outs() << r.first << " " << r.second.getInterval() << "\n";
211 }
212 // ground truth
214 {1, IntervalValue(0, 10)},
215 {2, IntervalValue(0, 0)}
216 };
217 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
218 }
219
221 {
222 outs() << "test2_2 start\n";
225 // var0 := [0, 100];
226 relation[0] = getContext().int_const("0");
227 itv[0] = IntervalValue(0, 100);
228 // var1 := var0;
229 relation[1] =
230 getContext().int_const("1") == getContext().int_const("0");
231 itv[1] = itv[0];
232 // var2 := var1 - var0;
233 relation[2] = getContext().int_const("2") ==
234 getContext().int_const("1") - getContext().int_const("0");
235 itv[2] = itv[1].getInterval() - itv[0].getInterval();
236
237 // Test extract sub vars
238 Set<u32_t> res;
239 relation.extractSubVars(relation[2], res);
240 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
243 const Z3Expr& relExpr = relation[2] && relation[1];
244 const Z3Expr& initExpr = rs.gamma_hat(inv);
245 const Z3Expr& phi = (relExpr && initExpr).simplify();
246 AbstractState resRSY = rs.RSY(inv, phi);
247 AbstractState resBilateral = rs.bilateral(inv, phi);
249 // 0:[0,100] 1:[0,100] 2:[0,0]
250 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
251 for (auto r : resRSY.getVarToVal())
252 {
253 outs() << r.first << " " << r.second.getInterval() << "\n";
254 }
255 // ground truth
257 {1, IntervalValue(0, 100)},
258 {2, IntervalValue(0, 0)}
259 };
260 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
261 }
262
264 {
265 outs() << "test2_3 start\n";
268 // var0 := [0, 1000];
269 relation[0] = getContext().int_const("0");
270 itv[0] = IntervalValue(0, 1000);
271 // var1 := var0;
272 relation[1] =
273 getContext().int_const("1") == getContext().int_const("0");
274 itv[1] = itv[0];
275 // var2 := var1 - var0;
276 relation[2] = getContext().int_const("2") ==
277 getContext().int_const("1") - getContext().int_const("0");
278 itv[2] = itv[1].getInterval() - itv[0].getInterval();
279
280 // Test extract sub vars
281 Set<u32_t> res;
282 relation.extractSubVars(relation[2], res);
283 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
286 const Z3Expr& relExpr = relation[2] && relation[1];
287 const Z3Expr& initExpr = rs.gamma_hat(inv);
288 const Z3Expr& phi = (relExpr && initExpr).simplify();
289 AbstractState resRSY = rs.RSY(inv, phi);
290 AbstractState resBilateral = rs.bilateral(inv, phi);
292 // 0:[0,1000] 1:[0,1000] 2:[0,0]
293 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
294 for (auto r : resRSY.getVarToVal())
295 {
296 outs() << r.first << " " << r.second.getInterval() << "\n";
297 }
298 // ground truth
300 {1, IntervalValue(0, 1000)},
301 {2, IntervalValue(0, 0)}
302 };
303 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
304 }
305
307 {
308 outs() << "test2_4 start\n";
311 // var0 := [0, 10000];
312 relation[0] = getContext().int_const("0");
313 itv[0] = IntervalValue(0, 10000);
314 // var1 := var0;
315 relation[1] =
316 getContext().int_const("1") == getContext().int_const("0");
317 itv[1] = itv[0];
318 // var2 := var1 - var0;
319 relation[2] = getContext().int_const("2") ==
320 getContext().int_const("1") - getContext().int_const("0");
321 itv[2] = itv[1].getInterval() - itv[0].getInterval();
322
323 // Test extract sub vars
324 Set<u32_t> res;
325 relation.extractSubVars(relation[2], res);
326 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
329 const Z3Expr& relExpr = relation[2] && relation[1];
330 const Z3Expr& initExpr = rs.gamma_hat(inv);
331 const Z3Expr& phi = (relExpr && initExpr).simplify();
335 // 0:[0,10000] 1:[0,10000] 2:[0,0]
336 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
337 for (auto r : resRSY.getVarToVal())
338 {
339 outs() << r.first << " " << r.second.getInterval() << "\n";
340 }
341 // ground truth
343 {1, IntervalValue(0, 10000)},
344 {2, IntervalValue(0, 0)}
345 };
346 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
347 }
348
350 {
351 outs() << "test2_5 start\n";
354 // var0 := [0, 100000];
355 relation[0] = getContext().int_const("0");
356 itv[0] = IntervalValue(0, 100000);
357 // var1 := var0;
358 relation[1] =
359 getContext().int_const("1") == getContext().int_const("0");
360 itv[1] = itv[0];
361 // var2 := var1 - var0;
362 relation[2] = getContext().int_const("2") ==
363 getContext().int_const("1") - getContext().int_const("0");
364 itv[2] = itv[1].getInterval() - itv[0].getInterval();
365
366 // Test extract sub vars
367 Set<u32_t> res;
368 relation.extractSubVars(relation[2], res);
369 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
372 const Z3Expr& relExpr = relation[2] && relation[1];
373 const Z3Expr& initExpr = rs.gamma_hat(inv);
374 const Z3Expr& phi = (relExpr && initExpr).simplify();
378 // 0:[0,100000] 1:[0,100000] 2:[0,0]
379 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
380 for (auto r : resRSY.getVarToVal())
381 {
382 outs() << r.first << " " << r.second.getInterval() << "\n";
383 }
384 // ground truth
386 {1, IntervalValue(0, 100000)},
387 {2, IntervalValue(0, 0)}
388 };
389 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
390 }
391
393 {
394 outs() << "test3_1 start\n";
397 // var0 := [1, 10];
398 relation[0] = getContext().int_const("0");
399 itv[0] = IntervalValue(1, 10);
400 // var1 := var0;
401 relation[1] =
402 getContext().int_const("1") == getContext().int_const("0");
403 itv[1] = itv[0];
404 // var2 := var1 / var0;
405 relation[2] = getContext().int_const("2") ==
406 getContext().int_const("1") / getContext().int_const("0");
407 itv[2] = itv[1].getInterval() / itv[0].getInterval();
408 // Test extract sub vars
409 Set<u32_t> res;
410 relation.extractSubVars(relation[2], res);
411 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
414 const Z3Expr& relExpr = relation[2] && relation[1];
415 const Z3Expr& initExpr = rs.gamma_hat(inv);
416 const Z3Expr& phi = (relExpr && initExpr).simplify();
417 AbstractState resRSY = rs.RSY(inv, phi);
418 AbstractState resBilateral = rs.bilateral(inv, phi);
420 // 0:[1,10] 1:[1,10] 2:[1,1]
421 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
422 for (auto r : resRSY.getVarToVal())
423 {
424 outs() << r.first << " " << r.second.getInterval() << "\n";
425 }
426 // ground truth
428 {1, IntervalValue(1, 10)},
429 {2, IntervalValue(1, 1)}
430 };
431 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
432 }
433
435 {
436 outs() << "test3_2 start\n";
439 // var0 := [1, 1000];
440 relation[0] = getContext().int_const("0");
441 itv[0] = IntervalValue(1, 1000);
442 // var1 := var0;
443 relation[1] =
444 getContext().int_const("1") == getContext().int_const("0");
445 itv[1] = itv[0];
446 // var2 := var1 / var0;
447 relation[2] = getContext().int_const("2") ==
448 getContext().int_const("1") / getContext().int_const("0");
449 itv[2] = itv[1].getInterval() / itv[0].getInterval();
450 // Test extract sub vars
451 Set<u32_t> res;
452 relation.extractSubVars(relation[2], res);
453 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
456 const Z3Expr& relExpr = relation[2] && relation[1];
457 const Z3Expr& initExpr = rs.gamma_hat(inv);
458 const Z3Expr& phi = (relExpr && initExpr).simplify();
459 AbstractState resRSY = rs.RSY(inv, phi);
460 AbstractState resBilateral = rs.bilateral(inv, phi);
462 // 0:[1,1000] 1:[1,1000] 2:[1,1]
463 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
464 for (auto r : resRSY.getVarToVal())
465 {
466 outs() << r.first << " " << r.second.getInterval() << "\n";
467 }
468 // ground truth
470 {1, IntervalValue(1, 1000)},
471 {2, IntervalValue(1, 1)}
472 };
473 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
474 }
475
477 {
478 outs() << "test3_3 start\n";
481 // var0 := [1, 10000];
482 relation[0] = getContext().int_const("0");
483 itv[0] = IntervalValue(1, 10000);
484 // var1 := var0;
485 relation[1] =
486 getContext().int_const("1") == getContext().int_const("0");
487 itv[1] = itv[0];
488 // var2 := var1 / var0;
489 relation[2] = getContext().int_const("2") ==
490 getContext().int_const("1") / getContext().int_const("0");
491 itv[2] = itv[1].getInterval() / itv[0].getInterval();
492 // Test extract sub vars
493 Set<u32_t> res;
494 relation.extractSubVars(relation[2], res);
495 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
498 const Z3Expr& relExpr = relation[2] && relation[1];
499 const Z3Expr& initExpr = rs.gamma_hat(inv);
500 const Z3Expr& phi = (relExpr && initExpr).simplify();
504 // 0:[1,10000] 1:[1,10000] 2:[1,1]
505 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
506 for (auto r : resRSY.getVarToVal())
507 {
508 outs() << r.first << " " << r.second.getInterval() << "\n";
509 }
510 // ground truth
512 {1, IntervalValue(1, 10000)},
513 {2, IntervalValue(1, 1)}
514 };
515 }
516
518 {
519 outs() << "test3_4 start\n";
522 // var0 := [1, 100000];
523 relation[0] = getContext().int_const("0");
524 itv[0] = IntervalValue(1, 100000);
525 // var1 := var0;
526 relation[1] =
527 getContext().int_const("1") == getContext().int_const("0");
528 itv[1] = itv[0];
529 // var2 := var1 / var0;
530 relation[2] = getContext().int_const("2") ==
531 getContext().int_const("1") / getContext().int_const("0");
532 itv[2] = itv[1].getInterval() / itv[0].getInterval();
533 // Test extract sub vars
534 Set<u32_t> res;
535 relation.extractSubVars(relation[2], res);
536 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
539 const Z3Expr& relExpr = relation[2] && relation[1];
540 const Z3Expr& initExpr = rs.gamma_hat(inv);
541 const Z3Expr& phi = (relExpr && initExpr).simplify();
545 // 0:[1,100000] 1:[1,100000] 2:[1,1]
546 assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
547 for (auto r : resRSY.getVarToVal())
548 {
549 outs() << r.first << " " << r.second.getInterval() << "\n";
550 }
551 // ground truth
553 {1, IntervalValue(1, 100000)},
554 {2, IntervalValue(1, 1)}
555 };
556 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
557 }
558
560 {
561 outs() << "test4_1 start\n";
564 // var0 := [0, 10];
565 relation[0] = getContext().int_const("0");
566 itv[0] = IntervalValue(0, 10);
567 // var1 := var0;
568 relation[1] =
569 getContext().int_const("1") == getContext().int_const("0");
570 itv[1] = itv[0];
571 // var2 := var1 / var0;
572 relation[2] = getContext().int_const("2") ==
573 getContext().int_const("1") / getContext().int_const("0");
574 itv[2] = itv[1].getInterval() / itv[0].getInterval();
575 // Test extract sub vars
576 Set<u32_t> res;
577 relation.extractSubVars(relation[2], res);
578 assert(res == Set<u32_t>({0, 1, 2}) && "inconsistency occurs");
581 const Z3Expr& relExpr = relation[2] && relation[1];
582 const Z3Expr& initExpr = rs.gamma_hat(inv);
583 const Z3Expr& phi = (relExpr && initExpr).simplify();
584 // IntervalExeState resRSY = rs.RSY(inv, phi);
585 outs() << "rsy done\n";
586 // IntervalExeState resBilateral = rs.bilateral(inv, phi);
587 outs() << "bilateral done\n";
589 outs() << "bs done\n";
590 // 0:[0,10] 1:[0,10] 2:[-00,+00]
591 // assert(resRSY == resBS && resBS == resBilateral);
592 for (auto r : resBS.getVarToVal())
593 {
594 outs() << r.first << " " << r.second.getInterval() << "\n";
595 }
596 // ground truth
598 {1, IntervalValue(0, 10)},
599 {2, IntervalValue(0, 10)}
600 };
601 assert(resBS.eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
602 }
603
605 {
608 saTest.testRelExeState1_2();
609
610 saTest.testRelExeState2_1();
611 saTest.testRelExeState2_2();
612 saTest.testRelExeState2_3();
613 // saTest.testRelExeState2_4(); /// 10000
614 // saTest.testRelExeState2_5(); /// 100000
615
616 saTest.testRelExeState3_1();
617 saTest.testRelExeState3_2();
618 // saTest.testRelExeState3_3(); /// 10000
619 // saTest.testRelExeState3_4(); /// 100000
620
621 outs() << "start top\n";
622 saTest.testRelExeState4_1();
623 }
624};
625
627{
628public:
629 AETest() = default;
630
631 ~AETest() = default;
632
634 {
635 // test division /
639 assert((IntervalValue(4) / IntervalValue(2)).equals(IntervalValue(2)));
640 assert((IntervalValue(3) / IntervalValue(2)).equals(IntervalValue(1))); //
641 assert((IntervalValue(-3) / IntervalValue(2)).equals(IntervalValue(-1))); //
642 assert((IntervalValue(1, 3) / IntervalValue(2)).equals(IntervalValue(0, 1))); //
643 assert((IntervalValue(2, 7) / IntervalValue(2)).equals(IntervalValue(1, 3))); //
644 assert((IntervalValue(-3, 3) / IntervalValue(2)).equals(IntervalValue(-1, 1)));
647 assert((IntervalValue(1, 3) / IntervalValue(1, 2)).equals(IntervalValue(0, 3)));//
648 assert((IntervalValue(-3, 3) / IntervalValue(1, 2)).equals(IntervalValue(-3, 3)));
649 assert((IntervalValue(2, 7) / IntervalValue(-2, 3)).equals(IntervalValue(-7, 7))); //
650 assert((IntervalValue(-2, 7) / IntervalValue(-2, 3)).equals(IntervalValue(-7, 7))); //
653
656 assert((IntervalValue(-6, -3) / IntervalValue(3, 9)).equals(IntervalValue(-2, 0)));
657 assert((IntervalValue(-6, 6) / IntervalValue(3, 9)).equals(IntervalValue(-2, 2)));
658
659 // test remainder %
663 assert((IntervalValue(4) % IntervalValue(2)).equals(IntervalValue(0)));
664 assert((IntervalValue(3) % IntervalValue(2)).equals(IntervalValue(1)));
665 assert((IntervalValue(-3) % IntervalValue(2)).equals(IntervalValue(-1)));
666 assert((IntervalValue(1, 3) % IntervalValue(2)).equals(IntervalValue(0, 1)));
667 assert((IntervalValue(2, 7) % IntervalValue(2)).equals(IntervalValue(0, 1)));
668 assert((IntervalValue(-3, 3) % IntervalValue(2)).equals(IntervalValue(-1, 1)));
671 assert((IntervalValue(1, 3) % IntervalValue(1, 2)).equals(IntervalValue(0, 1)));
672 assert((IntervalValue(-3, 3) % IntervalValue(1, 2)).equals(IntervalValue(-1, 1)));
673 assert((IntervalValue(2, 7) % IntervalValue(-2, 3)).equals(IntervalValue::top())); //
674 assert((IntervalValue(-2, 7) % IntervalValue(-2, 3)).equals(IntervalValue::top())); //
679 assert((IntervalValue(-6, -3) % IntervalValue(3, 9)).equals(IntervalValue(-6, 0)));
680 assert((IntervalValue(-6, 6) % IntervalValue(3, 9)).equals(IntervalValue(-6, 6)));
681
682 // shl <<
690 assert((IntervalValue(0, 0) << IntervalValue(2, 2)).equals(IntervalValue(0, 0)));
691 assert((IntervalValue(2, 2) << IntervalValue(3, 3)).equals(IntervalValue(16, 16)));
692 assert((IntervalValue(-2, -2) << IntervalValue(3, 3)).equals(IntervalValue(-16, -16)));
693
697 assert((IntervalValue(4) << IntervalValue(2)).equals(IntervalValue(16)));
698 assert((IntervalValue(3) << IntervalValue(2)).equals(IntervalValue(12)));
699 assert((IntervalValue(-3) << IntervalValue(2)).equals(IntervalValue(-12)));
701 assert((IntervalValue(1, 3) << IntervalValue(2)).equals(IntervalValue(4, 12)));
702 assert((IntervalValue(2, 7) << IntervalValue(2)).equals(IntervalValue(8, 28)));
703 assert((IntervalValue(-3, 3) << IntervalValue(2)).equals(IntervalValue(-12, 12)));
706 assert((IntervalValue(1, 3) << IntervalValue(1, 2)).equals(IntervalValue(2, 12)));
707 assert((IntervalValue(-3, 3) << IntervalValue(1, 2)).equals(IntervalValue(-12, 12)));
708 assert((IntervalValue(2, 7) << IntervalValue(-2, 3)).equals(IntervalValue(2, 56)));
709 assert((IntervalValue(-2, 7) << IntervalValue(-2, 3)).equals(IntervalValue(-16, 56)));
714 assert((IntervalValue(-6, -3) << IntervalValue(3, 9)).equals(IntervalValue(-3072, -24)));
715 assert((IntervalValue(-6, 6) << IntervalValue(3, 9)).equals(IntervalValue(-3072, 3072)));
718
719
720 // shr >>
728 assert((IntervalValue(0) >> IntervalValue(2)).equals(IntervalValue(0)));
729 assert((IntervalValue(15) >> IntervalValue(2)).equals(IntervalValue(3)));
730 assert((IntervalValue(-15) >> IntervalValue(2)).equals(IntervalValue(-4)));
731
735 assert((IntervalValue(15) >> IntervalValue(2)).equals(IntervalValue(3)));
736 assert((IntervalValue(1) >> IntervalValue(2)).equals(IntervalValue(0)));
737 assert((IntervalValue(-15) >> IntervalValue(2)).equals(IntervalValue(-4)));
739 assert((IntervalValue(1, 3) >> IntervalValue(2)).equals(IntervalValue(0)));
740 assert((IntervalValue(2, 7) >> IntervalValue(2)).equals(IntervalValue(0, 1)));
741 assert((IntervalValue(-15, 15) >> IntervalValue(2)).equals(IntervalValue(-4, 3)));
744 assert((IntervalValue(0, 15) >> IntervalValue(1, 2)).equals(IntervalValue(0, 7)));
745 assert((IntervalValue(-17, 15) >> IntervalValue(1, 2)).equals(IntervalValue(-9, 7)));
746 assert((IntervalValue(2, 7) >> IntervalValue(-2, 3)).equals(IntervalValue(0, 7)));
747 assert((IntervalValue(-2, 7) >> IntervalValue(-2, 3)).equals(IntervalValue(-2, 7)));
752 assert((IntervalValue(-6, -3) >> IntervalValue(2, 3)).equals(IntervalValue(-2, -1)));
753 assert((IntervalValue(-6, 6) >> IntervalValue(2, 3)).equals(IntervalValue(-2, 1)));
756
757 // and &
761 assert((IntervalValue(4) & IntervalValue(2)).equals(IntervalValue(0)));
762 assert((IntervalValue(3) & IntervalValue(2)).equals(IntervalValue(2)));
763 assert((IntervalValue(-3) & IntervalValue(2)).equals(IntervalValue(0)));
764 assert((IntervalValue(1, 3) & IntervalValue(2)).equals(IntervalValue(0, 2)));
765 assert((IntervalValue(2, 7) & IntervalValue(2)).equals(IntervalValue(0, 2)));
766 assert((IntervalValue(-3, 3) & IntervalValue(2)).equals(IntervalValue(0, 2)));
769 assert((IntervalValue(1, 3) & IntervalValue(1, 2)).equals(IntervalValue(0, 2)));
770 assert((IntervalValue(-3, 3) & IntervalValue(1, 2)).equals(IntervalValue(0, 2)));
771 assert((IntervalValue(2, 7) & IntervalValue(-2, 3)).equals(IntervalValue(0, 7)));
772 assert((IntervalValue(-2, 7) & IntervalValue(-2, 3)).equals(IntervalValue::top()));
777 assert((IntervalValue(-6, -3) & IntervalValue(3, 9)).equals(IntervalValue(0, 9)));
778 assert((IntervalValue(-6, 6) & IntervalValue(3, 9)).equals(IntervalValue(0, 9)));
779
780 // Or |
785 assert((IntervalValue(4) | IntervalValue(2)).equals(IntervalValue(6)));
786 assert((IntervalValue(3) | IntervalValue(2)).equals(IntervalValue(3)));
787 assert((IntervalValue(-3) | IntervalValue(2)).equals(IntervalValue(-1)));
788 assert((IntervalValue(1, 3) | IntervalValue(2)).equals(IntervalValue(0, 3)));
789 assert((IntervalValue(2, 7) | IntervalValue(2)).equals(IntervalValue(0, 7)));
790 assert((IntervalValue(-3, 3) | IntervalValue(2)).equals(IntervalValue::top()));
793 assert((IntervalValue(1, 3) | IntervalValue(1, 2)).equals(IntervalValue(0, 3)));
794 assert((IntervalValue(-3, 3) | IntervalValue(1, 2)).equals(IntervalValue::top()));
795 assert((IntervalValue(2, 7) | IntervalValue(-2, 3)).equals(IntervalValue::top()));
796 assert((IntervalValue(-2, 7) | IntervalValue(-2, 3)).equals(IntervalValue::top()));
801 assert((IntervalValue(-6, -3) | IntervalValue(3, 9)).equals(IntervalValue::top()));
802 assert((IntervalValue(-6, 6) | IntervalValue(3, 9)).equals(IntervalValue::top()));
803
804 // Xor ^
809 assert((IntervalValue(4) ^ IntervalValue(2)).equals(IntervalValue(6)));
810 assert((IntervalValue(3) ^ IntervalValue(2)).equals(IntervalValue(1)));
811 assert((IntervalValue(-3) ^ IntervalValue(2)).equals(IntervalValue(-1)));
812 assert((IntervalValue(1, 3) ^ IntervalValue(2)).equals(IntervalValue(0, 3)));
813 assert((IntervalValue(2, 7) ^ IntervalValue(2)).equals(IntervalValue(0, 7)));
814 assert((IntervalValue(-3, 3) ^ IntervalValue(2)).equals(IntervalValue::top()));
817 assert((IntervalValue(1, 3) ^ IntervalValue(1, 2)).equals(IntervalValue(0, 3)));
818 assert((IntervalValue(-3, 3) ^ IntervalValue(1, 2)).equals(IntervalValue::top()));
819 assert((IntervalValue(2, 7) ^ IntervalValue(-2, 3)).equals(IntervalValue::top()));
820 assert((IntervalValue(-2, 7) ^ IntervalValue(-2, 3)).equals(IntervalValue::top()));
825 assert((IntervalValue(-6, -3) ^ IntervalValue(3, 9)).equals(IntervalValue::top()));
826 assert((IntervalValue(-6, 6) ^ IntervalValue(3, 9)).equals(IntervalValue::top()));
827 }
828
830 {
832 as[1] = IntervalValue(1, 3);
833 as[2] = IntervalValue(2, 7);
834 as[3] = AddressValue(0x7f000007);
835 as[4] = AddressValue(0x7f000008);
836 // store: *as[3] = as[1], *as[4] = as[2]
837 for (auto addr : as[3].getAddrs()) as.store(addr, as[1]);
838 for (auto addr : as[4].getAddrs()) as.store(addr, as[2]);
839 as.printAbstractState();
840 // load: verify *as[3] == as[1] && *as[4] == as[2]
842 for (auto addr : as[3].getAddrs()) v3.join_with(as.load(addr));
843 for (auto addr : as[4].getAddrs()) v4.join_with(as.load(addr));
844 assert(v3.equals(as[1]) && v4.equals(as[2]));
845 }
846};
847
848
849int main(int argc, char** argv)
850{
851 int arg_num = 0;
852 int extraArgc = 3;
853 char **arg_value = new char *[argc + extraArgc];
854 for (; arg_num < argc; ++arg_num)
855 {
857 }
858 // add extra options
859 arg_value[arg_num++] = (char*) "-model-consts=true";
860 arg_value[arg_num++] = (char*) "-model-arrays=true";
861 arg_value[arg_num++] = (char*) "-pre-field-sensitive=false";
862 assert(arg_num == (argc + extraArgc) && "more extra arguments? Change the value of extraArgc");
863
864 std::vector<std::string> moduleNameVec;
866 arg_num, arg_value, "Static Symbolic Execution", "[options] <input-bitcode...>"
867 );
868 delete[] arg_value;
869 if (SYMABS())
870 {
873 return 0;
874 }
875
876 if (AETEST())
877 {
880 aeTest.testAbsState();
881 return 0;
882 }
883
886 SVFIR* pag = builder.build();
887 // Run Andersen's to resolve indirect calls, then update SVFIR with resolved targets.
888 // The Andersen singleton will be reused inside AbstractInterpretation::runOnModule().
890 builder.updateCallGraph(ander->getCallGraph());
893 ae.addDetector(std::make_unique<BufOverflowDetector>());
895 ae.addDetector(std::make_unique<NullptrDerefDetector>());
896 ae.runOnModule();
897
900
901 return 0;
902}
int main(int argc, char **argv)
Definition ae.cpp:849
static Option< bool > SYMABS("symabs", "symbolic abstraction test", false)
static Option< bool > AETEST("aetest", "abstract execution basic function test", false)
Definition ae.cpp:627
~AETest()=default
AETest()=default
void testBinaryOpStmt()
Definition ae.cpp:633
void testAbsState()
Definition ae.cpp:829
static std::vector< std::string > parseOptions(int argc, char *argv[], std::string description, std::string callFormat)
Definition CommandLine.h:75
void addDetector(std::unique_ptr< AEDetector > detector)
static AbstractInterpretation & getAEInstance()
Map< u32_t, AbstractValue > VarToAbsValMap
AbstractState sliceState(Set< u32_t > &sl)
Copy some values and return a new IntervalExeState.
void join_with(const AbstractValue &other)
static AndersenWaveDiff * createAndersenWaveDiff(SVFIR *_pag)
Create an singleton instance directly instead of invoking llvm pass manager.
Definition Andersen.h:430
static void releaseAndersenWaveDiff()
Definition Andersen.h:440
static BoundedInt minus_infinity()
Get minus infinity -inf.
static IntervalValue bottom()
Create the bottom IntervalValue [+inf, -inf].
static BoundedInt plus_infinity()
Get plus infinity +inf.
static IntervalValue top()
Create the IntervalValue [-inf, +inf].
static LLVMModuleSet * getLLVMModuleSet()
Definition LLVMModule.h:137
static void releaseLLVMModuleSet()
Definition LLVMModule.h:144
static void buildSVFModule(Module &mod)
static const Option< bool > NullDerefCheck
nullptr dereference checker, Default: false
Definition Options.h:249
static const Option< bool > BufferOverflowCheck
buffer overflow checker, Default: false
Definition Options.h:247
CallGraph * getCallGraph() const
Return call graph.
static z3::context & getContext()
Get z3 context, singleton design here to make sure we only have one context.
Definition Z3Expr.cpp:66
AbstractState BS_time(AbstractState &inv, const Z3Expr &phi, RelationSolver &rs)
Definition ae.cpp:96
void testRelExeState1_2()
Definition ae.cpp:143
SymblicAbstractionTest()=default
void testRelExeState2_4()
Definition ae.cpp:306
void testRelExeState2_1()
Definition ae.cpp:178
void testRelExeState2_2()
Definition ae.cpp:220
void testRelExeState3_2()
Definition ae.cpp:434
~SymblicAbstractionTest()=default
void testsValidation()
Definition ae.cpp:604
void testRelExeState2_3()
Definition ae.cpp:263
void testRelExeState3_3()
Definition ae.cpp:476
AbstractState RSY_time(AbstractState &inv, const Z3Expr &phi, RelationSolver &rs)
Definition ae.cpp:72
void testRelExeState4_1()
Definition ae.cpp:559
void testRelExeState2_5()
Definition ae.cpp:349
void testRelExeState3_1()
Definition ae.cpp:392
void testRelExeState1_1()
Definition ae.cpp:109
AbstractState Bilateral_time(AbstractState &inv, const Z3Expr &phi, RelationSolver &rs)
Definition ae.cpp:84
static z3::context & getContext()
Definition ae.cpp:62
void testRelExeState3_4()
Definition ae.cpp:517
std::string sucMsg(const std::string &msg)
Returns successful message by converting a string into green string output.
Definition SVFUtil.cpp:75
std::ostream & outs()
Overwrite llvm::outs()
Definition SVFUtil.h:58
for isBitcode
Definition BasicTypes.h:70
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76