Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Unreachable code" messages when using gtest #177

Open
mjeronimo opened this issue Oct 22, 2021 · 2 comments
Open

"Unreachable code" messages when using gtest #177

mjeronimo opened this issue Oct 22, 2021 · 2 comments
Labels
L-c++ Language: C++

Comments

@mjeronimo
Copy link

mjeronimo commented Oct 22, 2021

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 mjeronimo changed the title Unreachable code messages when using gtest "Unreachable code" messages when using gtest Oct 25, 2021
@lightspot21
Copy link

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

@ivanperez-keera
Copy link
Collaborator

ivanperez-keera commented Nov 4, 2023

@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 ivanperez-keera added the L-c++ Language: C++ label Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L-c++ Language: C++
Projects
None yet
Development

No branches or pull requests

3 participants