Skip to content

Add function that checks if function id represents a clinit. #4706

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions jbmc/src/java_bytecode/java_static_initializers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ bool is_clinit_wrapper_function(const irep_idt &function_id)
return has_suffix(id2string(function_id), clinit_wrapper_suffix);
}

/// Check if function_id is a clinit
/// \param function_id: some function identifier
/// \return true if the passed identifier is a clinit
bool is_clinit_function(const irep_idt &function_id)
{
return has_suffix(id2string(function_id), clinit_function_suffix);
}

/// Add a new symbol to the symbol table.
/// Note: assumes that a symbol with this name does not exist.
/// /param name: name of the symbol to be generated
Expand Down
1 change: 1 addition & 0 deletions jbmc/src/java_bytecode/java_static_initializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ irep_idt clinit_wrapper_name(const irep_idt &class_name);
irep_idt user_specified_clinit_name(const irep_idt &class_name);

bool is_clinit_wrapper_function(const irep_idt &function_id);
bool is_clinit_function(const irep_idt &function_id);

void create_static_initializer_symbols(
symbol_tablet &symbol_table,
Expand Down
1 change: 1 addition & 0 deletions jbmc/unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SRC += java_bytecode/ci_lazy_methods/lazy_load_lambdas.cpp \
java_bytecode/java_object_factory/gen_nondet_string_init.cpp \
java_bytecode/java_object_factory/struct_tag_types.cpp \
java_bytecode/java_replace_nondet/replace_nondet.cpp \
java_bytecode/java_static_initializers/java_static_initializers.cpp \
java_bytecode/java_string_library_preprocess/convert_exprt_to_string_exprt.cpp \
java_bytecode/java_types/erase_type_arguments.cpp \
java_bytecode/java_types/generic_type_index.cpp \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************\

Module: Unit tests for java_types

Author: Diffblue Ltd.

\*******************************************************************/

#include <java_bytecode/java_static_initializers.h>
#include <testing-utils/use_catch.h>

SCENARIO("is_clinit_function", "[core][java_static_initializers]")
{
GIVEN("A function id that represents a clinit")
THEN("is_clinit_function should return true.")
{
const std::string input = "com.something.package.TestClass.<clinit>:()V";
REQUIRE(is_clinit_function(input));
}
GIVEN("A function id that does not represent a clinit")
THEN("is_clinit_function should return false.")
{
const std::string input = "com.something.package.TestClass.<notclinit>:()V";
REQUIRE_FALSE(is_clinit_function(input));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
java_bytecode
testing-utils