ikos icon indicating copy to clipboard operation
ikos copied to clipboard

"Unreachable code" messages when using gtest

Open mjeronimo opened this issue 3 years ago • 2 comments

Using IKOS in Google tests projects results in IKOS detecting unreachable code in global C++ objects. Apparently, IKOS is examining these global functions/constructors but sees no path to them from main (since they aren't called from main, but are invoked by the application startup-code before main is called). This was detected on Ubuntu 20.04.

To reproduce:

    $ unzip ikos-gtest-issue.zip
    $ ./doit
You should see the following results at the end of the output:

# Results
Report is too big (> 15 entries)

Use `ikos-report output.db` to examine the report in your terminal.
Use `ikos-view output.db` to examine the report in a web interface.
../../src/hello_test.cc: In function '_GLOBAL__sub_I_hello_test.cc':
?:?:?: unreachable: code is dead
_deps/googletest-src/googletest/src/gtest_main.cc: In function '_GLOBAL__sub_I_gtest_main.cc':
?:?:?: unreachable: code is dead
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
?:?:?: unreachable: code is dead
../../src/hello_test.cc: In function '_GLOBAL__sub_I_hello_test.cc':
../../src/hello_test.cc:0:0: unreachable: code is dead
}
^
_deps/googletest-src/googletest/src/gtest_main.cc: In function 'main':
_deps/googletest-src/googletest/src/gtest_main.cc:51:3: unreachable: code is dead
  testing::InitGoogleTest(&argc, argv);
  ^
_deps/googletest-src/googletest/src/gtest_main.cc: In function 'main':
_deps/googletest-src/googletest/src/gtest_main.cc:52:3: unreachable: code is dead
  return RUN_ALL_TESTS();
  ^
_deps/googletest-src/googletest/src/gtest_main.cc: In function 'main':
_deps/googletest-src/googletest/src/gtest_main.cc:52:10: unreachable: code is dead
  return RUN_ALL_TESTS();
         ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^
_deps/googletest-src/googletest/src/gtest-all.cc: In function '_GLOBAL__sub_I_gtest_all.cc':
_deps/googletest-src/googletest/src/gtest-all.cc:0:0: unreachable: code is dead
#include "src/gtest-typed-test.cc"
                                 ^

ikos-gtest-issue-1.zip

mjeronimo avatar Oct 22 '21 23:10 mjeronimo

Seconding. Not just with googletest, but also Catch2 presents the same issue.

lightspot21 avatar Nov 03 '21 14:11 lightspot21

@mjeronimo I'm missing some details to reproduce exactly this message. There's no doit in the file you provided. A dockerfile would help immensely.

It seems like you are probably using this but just for info, I'll include a couple of details on related parameters that can be used.

The first one is --entry-points. You can call:

$ ikos --entry-points <alternative_main_function> hello_test.cc

Gtest in particular provides a gtest_main (which I think you are using).

However, that option to ikos also accepts wildcards, a feature included in #93. So, you can just run:

$ ikos --entry-points '*' hello_test.cc

Using --proc=intra may give you different results, mainly because the entry point analysis is only done in interprocedural analysis (the default). You'll still need to provide an entry point (or -e '*'), though.

As per Catch2, I get similar errors to the ones reported in this issue with:

$ ikos /usr/share/doc/catch2/examples/020-TestCase-2.cpp 
[*] Compiling /usr/share/doc/catch2/examples/020-TestCase-2.cpp
[*] Running ikos preprocessor
[*] Running ikos analyzer
[*] Translating LLVM bitcode to AR
ikos-analyzer: /tmp/ikos-q62p8585/020-TestCase-2.pp.bc: error: could not find function 'main'
ikos: error: a run-time error occurred
$ ikos /usr/share/doc/catch2/examples/020-TestCase-2.cpp -e '*'
[...]
/usr/share/doc/catch2/examples/020-TestCase-2.cpp: In function 'C_A_T_C_H_T_E_S_T_2()':
/usr/share/doc/catch2/examples/020-TestCase-2.cpp:21:1: unreachable: code is dead
}
^
/usr/share/doc/catch2/examples/020-TestCase-2.cpp: In function 'C_A_T_C_H_T_E_S_T_2()':
/usr/share/doc/catch2/examples/020-TestCase-2.cpp:21:1: unreachable: code is dead
}
^
/usr/share/doc/catch2/examples/020-TestCase-2.cpp: In function 'C_A_T_C_H_T_E_S_T_2()':
/usr/share/doc/catch2/examples/020-TestCase-2.cpp:21:1: unreachable: code is dead
}
^
/usr/include/catch2/catch.hpp: In function 'Catch::BinaryExpr<int const&, int const&> const Catch::ExprLhs<int const&>::operator==<int>(int const&)':
/usr/include/catch2/catch.hpp:2345:13: unreachable: code is dead
            return { compareEqual( m_lhs, rhs ), m_lhs, "==", rhs };
            ^

ivanperez-keera avatar Nov 04 '23 10:11 ivanperez-keera