Skip to content

introduce rounding_mode_identifier() #6289

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 1 commit into from
Aug 16, 2021
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
6 changes: 4 additions & 2 deletions jbmc/src/java_bytecode/java_bytecode_internal_additions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ Author: Daniel Kroening, [email protected]
#include <util/std_types.h>
#include <util/symbol_table_base.h>

#include <goto-programs/adjust_float_expressions.h>

void java_internal_additions(symbol_table_baset &dest)
{
// add __CPROVER_rounding_mode

{
symbolt symbol;
symbol.base_name = CPROVER_PREFIX "rounding_mode";
symbol.name=CPROVER_PREFIX "rounding_mode";
symbol.name = rounding_mode_identifier();
symbol.base_name = symbol.name;
symbol.type=signed_int_type();
symbol.mode=ID_C;
symbol.is_lvalue=true;
Expand Down
3 changes: 2 additions & 1 deletion jbmc/src/java_bytecode/java_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
#include <util/nondet.h>
#include <util/suffix.h>

#include <goto-programs/adjust_float_expressions.h>
#include <goto-programs/class_identifier.h>
#include <goto-programs/goto_functions.h>

Expand Down Expand Up @@ -120,7 +121,7 @@ void java_static_lifetime_init(
code_blockt code_block;

const symbol_exprt rounding_mode =
symbol_table.lookup_ref(CPROVER_PREFIX "rounding_mode").symbol_expr();
symbol_table.lookup_ref(rounding_mode_identifier()).symbol_expr();
code_block.add(
code_assignt{rounding_mode, from_integer(0, rounding_mode.type())});

Expand Down
6 changes: 4 additions & 2 deletions src/analyses/constant_propagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Author: Peter Schrammel

#include "constant_propagator.h"

#include <goto-programs/adjust_float_expressions.h>

#ifdef DEBUG
#include <iostream>
#include <util/format_expr.h>
Expand Down Expand Up @@ -655,7 +657,7 @@ bool constant_propagator_domaint::partial_evaluate(
// if the current rounding mode is top we can
// still get a non-top result by trying all rounding
// modes and checking if the results are all the same
if(!known_values.is_constant(ID_cprover_rounding_mode_str))
if(!known_values.is_constant(rounding_mode_identifier()))
return partial_evaluate_with_all_rounding_modes(known_values, expr, ns);

return replace_constants_and_simplify(known_values, expr, ns);
Expand Down Expand Up @@ -685,7 +687,7 @@ bool constant_propagator_domaint::partial_evaluate_with_all_rounding_modes(
{
valuest tmp_values = known_values;
tmp_values.set_to(
symbol_exprt(ID_cprover_rounding_mode_str, integer_typet()),
symbol_exprt(rounding_mode_identifier(), integer_typet()),
from_integer(rounding_modes[i], integer_typet()));
exprt result = expr;
if(replace_constants_and_simplify(tmp_values, result, ns))
Expand Down
5 changes: 4 additions & 1 deletion src/ansi-c/ansi_c_internal_additions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Author: Daniel Kroening, [email protected]

#include <linking/static_lifetime_init.h>

#include <goto-programs/adjust_float_expressions.h>

const char gcc_builtin_headers_types[]=
"# 1 \"gcc_builtin_headers_types.h\"\n"
#include "gcc_builtin_headers_types.inc"
Expand Down Expand Up @@ -205,7 +207,8 @@ void ansi_c_internal_additions(std::string &code)
CPROVER_PREFIX "constant_infinity_uint];\n"

// float stuff
"int " CPROVER_PREFIX "thread_local " CPROVER_PREFIX "rounding_mode="+
"int " CPROVER_PREFIX "thread_local " +
id2string(rounding_mode_identifier()) + '='+
std::to_string(config.ansi_c.rounding_mode)+";\n"

// pipes, write, read, close
Expand Down
4 changes: 3 additions & 1 deletion src/cpp/cpp_internal_additions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Author: Daniel Kroening, [email protected]

#include <linking/static_lifetime_init.h>

#include <goto-programs/adjust_float_expressions.h>

std::string c2cpp(const std::string &s)
{
std::string result;
Expand Down Expand Up @@ -108,7 +110,7 @@ void cpp_internal_additions(std::ostream &out)

// float
// TODO: should be thread_local
out << "int " CPROVER_PREFIX "rounding_mode = "
out << "int " << rounding_mode_identifier() << " = "
<< std::to_string(config.ansi_c.rounding_mode) << ';' << '\n';

// pipes, write, read, close
Expand Down
1 change: 1 addition & 0 deletions src/cpp/module_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ansi-c
cpp
goto-programs
langapi # should go away
linking
util
3 changes: 2 additions & 1 deletion src/goto-instrument/full_slicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Author: Daniel Kroening, [email protected]
#include <util/find_symbols.h>
#include <util/cprover_prefix.h>

#include <goto-programs/adjust_float_expressions.h>
#include <goto-programs/remove_skip.h>

void full_slicert::add_dependencies(
Expand Down Expand Up @@ -248,7 +249,7 @@ static bool implicit(goto_programt::const_targett target)

const symbol_exprt &s=to_symbol_expr(a.lhs());

return s.get_identifier()==CPROVER_PREFIX "rounding_mode";
return s.get_identifier() == rounding_mode_identifier();
}

void full_slicert::operator()(
Expand Down
7 changes: 6 additions & 1 deletion src/goto-programs/adjust_float_expressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ Author: Daniel Kroening, [email protected]

#include "goto_model.h"

irep_idt rounding_mode_identifier()
{
return CPROVER_PREFIX "rounding_mode";
}

/// Iterate over an expression and check it or any of its subexpressions are
/// floating point operations that haven't been adjusted with a rounding mode
/// yet.
Expand Down Expand Up @@ -186,7 +191,7 @@ void adjust_float_expressions(exprt &expr, const namespacet &ns)
return;

symbol_exprt rounding_mode =
ns.lookup(CPROVER_PREFIX "rounding_mode").symbol_expr();
ns.lookup(rounding_mode_identifier()).symbol_expr();

rounding_mode.add_source_location() = expr.source_location();

Expand Down
4 changes: 4 additions & 0 deletions src/goto-programs/adjust_float_expressions.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ void adjust_float_expressions(
/// \see adjust_float_expressions(goto_functionst &, const namespacet &)
void adjust_float_expressions(goto_modelt &goto_model);

/// Return the identifier of the program symbol used to
/// store the current rounding mode.
irep_idt rounding_mode_identifier();

#endif // CPROVER_GOTO_PROGRAMS_ADJUST_FLOAT_EXPRESSIONS_H
5 changes: 3 additions & 2 deletions src/jsil/jsil_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Author: Michael Tautschnig, [email protected]
#include <util/message.h>
#include <util/range.h>

#include <goto-programs/adjust_float_expressions.h>
#include <goto-programs/goto_functions.h>

#include <linking/static_lifetime_init.h>
Expand All @@ -33,8 +34,8 @@ static void create_initialize(symbol_tablet &symbol_table)

namespacet ns(symbol_table);

symbol_exprt rounding_mode=
ns.lookup(CPROVER_PREFIX "rounding_mode").symbol_expr();
symbol_exprt rounding_mode =
ns.lookup(rounding_mode_identifier()).symbol_expr();

code_assignt a(rounding_mode, from_integer(0, rounding_mode.type()));
init_code.add(a);
Expand Down
6 changes: 4 additions & 2 deletions src/jsil/jsil_internal_additions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Author: Michael Tautschnig, [email protected]

#include "jsil_internal_additions.h"

#include <goto-programs/adjust_float_expressions.h>

#include <util/std_types.h>
#include <util/cprover_prefix.h>
#include <util/symbol_table.h>
Expand All @@ -25,8 +27,8 @@ void jsil_internal_additions(symbol_tablet &dest)

{
symbolt symbol;
symbol.base_name = CPROVER_PREFIX "rounding_mode";
symbol.name=CPROVER_PREFIX "rounding_mode";
symbol.name = rounding_mode_identifier();
symbol.base_name = symbol.name;
symbol.type=signed_int_type();
symbol.mode=ID_C;
symbol.is_lvalue=true;
Expand Down
4 changes: 3 additions & 1 deletion src/linking/remove_internal_symbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Author: Daniel Kroening

#include "remove_internal_symbols.h"

#include <goto-programs/adjust_float_expressions.h>

#include <util/config.h>
#include <util/find_symbols.h>
#include <util/message.h>
Expand Down Expand Up @@ -119,7 +121,7 @@ void remove_internal_symbols(
special.insert(CPROVER_PREFIX "malloc_size");
special.insert(CPROVER_PREFIX "deallocated");
special.insert(CPROVER_PREFIX "dead_object");
special.insert(CPROVER_PREFIX "rounding_mode");
special.insert(rounding_mode_identifier());
special.insert("__new");
special.insert("__new_array");
special.insert("__placement_new");
Expand Down
6 changes: 2 additions & 4 deletions src/statement-list/statement_list_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Author: Matthias Weiss, [email protected]

#include "statement_list_entry_point.h"

#include <goto-programs/adjust_float_expressions.h>
#include <goto-programs/goto_functions.h>

#include <linking/static_lifetime_init.h>
Expand All @@ -21,9 +22,6 @@ Author: Matthias Weiss, [email protected]
#include <util/pointer_expr.h>
#include <util/std_code.h>

/// Name of the CPROVER-specific variable that specifies the rounding mode.
#define ROUNDING_MODE_NAME CPROVER_PREFIX "rounding_mode"

/// Postfix for the artificial data block that is created when calling a main
/// symbol that is a function block.
#define DB_ENTRY_POINT_POSTFIX "_entry_point"
Expand Down Expand Up @@ -146,7 +144,7 @@ static void generate_statement_list_init_function(symbol_tablet &symbol_table)
static void generate_rounding_mode(symbol_tablet &symbol_table)
{
symbolt rounding_mode;
rounding_mode.name = ROUNDING_MODE_NAME;
rounding_mode.name = rounding_mode_identifier();
rounding_mode.type = signed_int_type();
rounding_mode.is_thread_local = true;
rounding_mode.is_static_lifetime = true;
Expand Down
2 changes: 0 additions & 2 deletions src/util/ieee_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Author: Daniel Kroening, [email protected]
class constant_exprt;
class floatbv_typet;

const char ID_cprover_rounding_mode_str[] = CPROVER_PREFIX "rounding_mode";

class ieee_float_spect
{
public:
Expand Down