@@ -73,6 +73,8 @@ class IDETypeStateAnalysisFileIOTest : public ::testing::Test {
7373 IDETypeStateAnalysis::i_t > &solver) {
7474 for (auto InstToGroundTruth : groundTruth) {
7575 auto Inst = IRDB->getInstruction (InstToGroundTruth.first );
76+ // std::cout << "Handle results at " << InstToGroundTruth.first <<
77+ // std::endl;
7678 auto GT = InstToGroundTruth.second ;
7779 std::map<std::string, int > results;
7880 for (auto Result : solver.resultsAt (Inst, true )) {
@@ -151,11 +153,15 @@ TEST_F(IDETypeStateAnalysisFileIOTest, HandleTypeState_04) {
151153 llvmtssolver (*TSProblem);
152154
153155 llvmtssolver.solve ();
156+
154157 const std::map<std::size_t , std::map<std::string, int >> gt = {
155158 // At exit in foo()
156159 {6 , {{" 2" , IOSTATE::OPENED}, {" 8" , IOSTATE::OPENED}}},
160+ // Before closing in main()
161+ {12 , {{" 2" , IOSTATE::UNINIT}, {" 8" , IOSTATE::UNINIT}}},
157162 // At exit in main()
158- {14 , {{" 2" , IOSTATE::CLOSED}, {" 8" , IOSTATE::CLOSED}}}};
163+ {14 , {{" 2" , IOSTATE::ERROR}, {" 8" , IOSTATE::ERROR}}}};
164+
159165 compareResults (gt, llvmtssolver);
160166}
161167
@@ -170,17 +176,14 @@ TEST_F(IDETypeStateAnalysisFileIOTest, HandleTypeState_05) {
170176 llvmtssolver.solve ();
171177 const std::map<std::size_t , std::map<std::string, int >> gt = {
172178 // Before if statement
173- {10 ,
174- {{" 4" , IOSTATE::OPENED},
175- {" 6" , IOSTATE::OPENED},
176- {" 11" , IOSTATE::OPENED}}},
179+ {10 , {{" 4" , IOSTATE::OPENED}, {" 6" , IOSTATE::OPENED}}},
177180 // Inside if statement at last instruction
178181 {13 ,
179182 {{" 4" , IOSTATE::CLOSED},
180183 {" 6" , IOSTATE::CLOSED},
181184 {" 11" , IOSTATE::CLOSED}}},
182185 // After if statement
183- {14 , {{" 4" , IOSTATE::BOT}, {" 6" , IOSTATE::BOT}, { " 11 " , IOSTATE::BOT} }}};
186+ {14 , {{" 4" , IOSTATE::BOT}, {" 6" , IOSTATE::BOT}}}};
184187 compareResults (gt, llvmtssolver);
185188}
186189
@@ -251,7 +254,7 @@ TEST_F(IDETypeStateAnalysisFileIOTest, HandleTypeState_07) {
251254 // After store
252255 {14 ,
253256 {{" 8" , IOSTATE::OPENED},
254- {" 10" , IOSTATE::OPENED },
257+ {" 10" , IOSTATE::ERROR },
255258 {" 12" , IOSTATE::OPENED}}},
256259 // At exit in main()
257260 {16 , {{" 2" , IOSTATE::CLOSED}, {" 8" , IOSTATE::CLOSED}}}};
@@ -327,21 +330,18 @@ TEST_F(IDETypeStateAnalysisFileIOTest, HandleTypeState_11) {
327330
328331 llvmtssolver.solve ();
329332 const std::map<std::size_t , std::map<std::string, int >> gt = {
330- // At exit in bar()
333+ // At exit in bar(): closing uninitialized file-handle gives error-state
331334 {6 ,
332- {{" 2" , IOSTATE::CLOSED},
333- {" 7" , IOSTATE::CLOSED},
334- {" 13" , IOSTATE::CLOSED}}},
335+ {{" 2" , IOSTATE::ERROR}, {" 7" , IOSTATE::ERROR}, {" 13" , IOSTATE::ERROR}}},
335336 // At exit in foo()
336337 {11 ,
337338 {{" 2" , IOSTATE::OPENED},
338339 {" 7" , IOSTATE::OPENED},
339340 {" 13" , IOSTATE::OPENED}}},
340- // At exit in main()
341+ // At exit in main(): due to aliasing the error-state from bar is
342+ // propagated back to main
341343 {19 ,
342- {{" 2" , IOSTATE::CLOSED},
343- {" 7" , IOSTATE::CLOSED},
344- {" 13" , IOSTATE::CLOSED}}}};
344+ {{" 2" , IOSTATE::ERROR}, {" 7" , IOSTATE::ERROR}, {" 13" , IOSTATE::ERROR}}}};
345345 compareResults (gt, llvmtssolver);
346346}
347347
@@ -422,37 +422,52 @@ TEST_F(IDETypeStateAnalysisFileIOTest, HandleTypeState_15) {
422422 const std::map<std::size_t , std::map<std::string, int >> gt = {
423423 // After store of ret val of first fopen()
424424 {9 ,
425- {{" 5" , IOSTATE::OPENED},
426- {" 7" , IOSTATE::OPENED},
427- {" 9" , IOSTATE::OPENED},
428- {" 11" , IOSTATE::OPENED},
429- {" 13" , IOSTATE::OPENED}}},
425+ {
426+ {" 5" , IOSTATE::OPENED}, {" 7" , IOSTATE::OPENED},
427+ // for 9, 11, 13 state is top
428+ // {"9", IOSTATE::OPENED},
429+ // {"11", IOSTATE::OPENED},
430+ // {"13", IOSTATE::OPENED}
431+ }},
430432 // After first fclose()
431433 {11 ,
432- {{" 5" , IOSTATE::CLOSED},
433- {" 7" , IOSTATE::CLOSED},
434- {" 9" , IOSTATE::CLOSED},
435- {" 11" , IOSTATE::CLOSED},
436- {" 13" , IOSTATE::CLOSED}}},
434+ {
435+ {" 5" , IOSTATE::CLOSED},
436+ {" 7" , IOSTATE::CLOSED},
437+ {" 9" , IOSTATE::CLOSED},
438+ // for 11 and 13 state is top
439+ // {"11", IOSTATE::CLOSED},
440+ // {"13", IOSTATE::CLOSED}
441+ }},
437442 // After second fopen() but before storing ret val
438443 {12 ,
439- {{" 5" , IOSTATE::CLOSED},
440- {" 7" , IOSTATE::CLOSED},
441- {" 9" , IOSTATE::CLOSED},
442- {" 11" , IOSTATE::OPENED},
443- {" 13" , IOSTATE::CLOSED}}},
444+ {
445+ {" 5" , IOSTATE::CLOSED},
446+ {" 7" , IOSTATE::CLOSED},
447+ {" 9" , IOSTATE::CLOSED},
448+ {" 11" , IOSTATE::OPENED},
449+ // for 13 state is top
450+ // {"13", IOSTATE::CLOSED}
451+ }},
444452 // After storing ret val of second fopen()
445453 {13 ,
446- {{" 5" , IOSTATE::OPENED},
447- {" 7" , IOSTATE::OPENED},
448- {" 9" , IOSTATE::OPENED},
449- {" 11" , IOSTATE::OPENED},
450- {" 13" , IOSTATE::OPENED}}},
454+ {
455+ {" 5" , IOSTATE::OPENED},
456+ {" 7" , IOSTATE::CLOSED}, // 7 and 9 do not alias 11
457+ {" 9" , IOSTATE::CLOSED},
458+ {" 11" , IOSTATE::OPENED},
459+ // for 13 state is top
460+ // {"13", IOSTATE::OPENED}
461+ }},
451462 // At exit in main()
452463 {15 ,
453464 {{" 5" , IOSTATE::CLOSED},
454- {" 7" , IOSTATE::CLOSED},
455- {" 9" , IOSTATE::CLOSED},
465+ // Due to flow-insensitive alias information, the
466+ // closed file-handle (which has ID 13) may alias
467+ // the closed file handles 7 and 9. Hence closed
468+ // + closed gives error for 7 and 9 => false positive
469+ {" 7" , IOSTATE::ERROR},
470+ {" 9" , IOSTATE::ERROR},
456471 {" 11" , IOSTATE::CLOSED},
457472 {" 13" , IOSTATE::CLOSED}}}};
458473 compareResults (gt, llvmtssolver);
0 commit comments