PIPS
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "text-util.h"
#include "database.h"
#include "pipsdbm.h"
#include "resources.h"
#include "misc.h"
#include "control.h"
#include "properties.h"
#include "semantics.h"
#include "transformer.h"
#include "conversion.h"
#include "alias_private.h"
#include "instrumentation.h"
#include "transformations.h"
Go to the source code of this file.
Data Structures | |
struct | array_test |
struct | interprocedural_abc_context_t |
context data structure for interprocedural_abc newgen recursion More... | |
Macros | |
#define | PREFIX "$IABC" |
This phase checks for out of bound error when passing arrays or array elements as arguments in procedure call. More... | |
#define | array_test_undefined ((array_test) {NIL,NIL}) |
Typedefs | |
typedef struct array_test | array_test |
typedef struct interprocedural_abc_context_t * | interprocedural_abc_context_p |
Variables | |
static int | number_of_added_tests |
static int | number_of_bound_violations |
static int | total_number_of_added_tests = 0 |
static int | total_number_of_bound_violations = 0 |
#define array_test_undefined ((array_test) {NIL,NIL}) |
Definition at line 143 of file array_bound_check_interprocedural.c.
#define PREFIX "$IABC" |
This phase checks for out of bound error when passing arrays or array elements as arguments in procedure call.
It ensures that there is no bound violation in every array access in the callee procedure, with respect to the array declarations in the caller procedure
The association rules for dummy and actual arrays in Fortran standard (ANSI) Section 15.9.3.3 are verified by this checking
Remarks to simplify our checking :
size_from_position(dummy_array,k+1) = size_from_position(actual_array,k+1) +1
ATTENTION : FORTRAN standard (15.9.3) says that an association of dummy and actual arguments is valid only if the type of the actual argument is the same as the type of the corresponding dummy argument. But in practice, not much program respect this rule , so we have to multiply the array size by its element size in order to compare 2 arrays for Psysteme_to_expression As we create checks with stop error message who tell us there are bound violations for which array in which call, the following typedef array_test permits us to create a sequence of tests for each statement more easier. The functions interprocedural_abc_call, interprocedural_abc_expression return results of type array_test
Definition at line 96 of file array_bound_check_interprocedural.c.
typedef struct array_test array_test |
typedef struct interprocedural_abc_context_t * interprocedural_abc_context_p |
|
static |
If in temp.exp, there are expressions that exist in retour.exp, we don't have to add those expressions to retour.exp
Definition at line 165 of file array_bound_check_interprocedural.c.
References array_test::arr, array_test_undefined_p(), CAR, CDR, CONS, ENDP, ENTITY, exp, array_test::exp, EXPRESSION, gen_nconc(), NIL, and same_expression_in_list_p().
Referenced by interprocedural_abc_call().
bool array_bound_check_interprocedural | ( | const char * | module_name | ) |
array_bound_check_interprocedural.c
s bound checks are added
module_name | odule_name |
Definition at line 749 of file array_bound_check_interprocedural.c.
References db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug(), debug_off, debug_on, display_interprocedural_abc_statistics(), ifdebug, initialize_interprocedural_abc_statistics(), interprocedural_abc_statement(), local_name_to_top_level_entity(), module_name(), module_reorder(), module_statement, pips_assert, reset_current_module_entity(), reset_ordering_to_statement(), reset_precondition_map(), set_current_module_entity(), set_ordering_to_statement(), set_precondition_map(), statement_consistent_p(), total_number_of_added_tests, total_number_of_bound_violations, and user_log().
|
static |
Definition at line 145 of file array_bound_check_interprocedural.c.
Referenced by add_array_test(), and interprocedural_abc_statement_rwt().
|
static |
Definition at line 124 of file array_bound_check_interprocedural.c.
References number_of_added_tests, number_of_bound_violations, total_number_of_added_tests, total_number_of_bound_violations, and user_log().
Referenced by array_bound_check_interprocedural().
|
static |
his function returns a true expression if (e1 < e2) = TRUE expression undefined if (e1 < e2) = FALSE a test e1 < e2
See if e is true or false if we have already the preconditions ps if ps := ps + e ps = sc_strong_normalize3(ps) if (ps = sc_empty) => not feasible, no bound violation if (ps = sc_rn) => bound violation else => test to put
Trivial test : e1 = 1200, e2 = 1 => e1 < e2 = FALSE
Tets if v_init < 0
False => no bound violation
True => bound violation
False => no bound violation
Constraint form: v +1 <= 0
try fast check
ok, e1<e2 is redundant wrt ps => bound violation
ok, system {ps + {e1<e2}} is infeasible => no bound violation
no result, try slow version
Attention : sc_strong_normalize3 returns SC_UNDEFINED for 103.su2cor
Before using the system, we have to porject variables such as V::init from PIPS
There are V::init variables
Definition at line 224 of file array_bound_check_interprocedural.c.
References Ssysteme::base, contrainte_make(), entity_local_name(), expression_undefined, fprint_transformer(), fprintf(), ifdebug, lt_expression, make_true_expression(), NORMALIZE_EXPRESSION, normalized_linear, normalized_linear_p, old_value_entity_p(), predicate_system, print_expression(), Psysteme_to_expression(), sc_check_inequality_redundancy(), sc_constraint_add(), sc_dup(), sc_empty_p(), sc_fprint(), sc_rn_p(), sc_strong_normalize2(), Svecteur::succ, TCST, transformer_relation, val_of, value_neg_p, VALUE_ONE, value_posz_p, vect_add(), vect_add_elem(), vect_constant_p(), vect_new(), vect_rm(), vect_substract(), VECTEUR_NUL_P, and vecteur_var.
Referenced by interprocedural_abc_arrays().
|
static |
Definition at line 118 of file array_bound_check_interprocedural.c.
References number_of_added_tests, and number_of_bound_violations.
Referenced by array_bound_check_interprocedural().
|
static |
If statement is unreachable => do we need check here ?
Compute the number of same dimensions of the actual array, dummy array and actual array element, based on association information, common variables,
preconditions for more informations)
same_dim < number of dimension of the dummy array
translate the size of dummy array from the current callee to the frame of current module
The size of the dummy array is translated to the caller's frame
As the size of the dummy array is translated, we need only precondition of the call in the current context
Now, compare the element size of actual and dummy arrays
same_dim < number of dimension of the actual array
Actual and formal arguments have different types
Add to Logfile some information:
same_dim == number of dimension of the actual array If the size of the dummy array is greater than 1 => violation For example : actual array A(M,N), dummy array D(M,N,K) or D(M,N,1,K)
Actual and formal arguments have different types
This case is rare, because size of dummy array = constants or formal parameters or commons
else, dummy_array_size == expression_undefined because same_dim == number of dimensions of dummy array, the inequation (1) or (2) is always true (suppose that there is no intraprocedural bound violation)
Definition at line 345 of file array_bound_check_interprocedural.c.
References binary_intrinsic_expression, call_function, current_callee, entity_local_name(), entity_module_name(), entity_type, expression_less_than_in_context(), expression_to_string(), expression_undefined, expression_undefined_p, formal_and_actual_parameters_association(), fprintf(), get_current_module_entity(), ifdebug, int_to_expression(), load_statement_precondition(), MULTIPLY_OPERATOR_NAME, pips_user_warning, PREFIX, print_expression(), same_dimension_p(), same_expression_p(), size_of_actual_array(), size_of_dummy_array(), SizeOfElements(), statement_weakly_feasible_p(), transformer_dup(), transformer_identity(), translate_to_module_frame(), type_variable, user_log(), and variable_basic.
Referenced by interprocedural_abc_call().
|
static |
More efficient : same call, same actual array ?
Traverse the argument list => check for argument which is a function call
ATTENTION : we have to compute the callgraph before (make CALLGRAPH_FILE[ALL]) in order to have the initial value of f is recognized by PIPS as value code. If not => core dumped. I should add a user warning here !!!
c is a call to a function or subroutine
find corresponding formal argument in f : f -> value -> code -> declaration -> formal variable -> offset == i ?
We have found the corresponding dummy argument
Formal parameter is an assumed-size array => what to do ?
Actual argument is an assumed-size array => what to do ?
Definition at line 449 of file array_bound_check_interprocedural.c.
References add_array_test(), array_argument_p(), array_test_undefined, assumed_size_array_p(), call_arguments, call_function, code_declarations, ENTITY, entity_code(), entity_initial, entity_local_name(), entity_name, entity_storage, EXPRESSION, expression_reference(), expression_undefined_p, f(), formal_offset, formal_parameter_p(), fprintf(), ifdebug, interprocedural_abc_arrays(), interprocedural_abc_expression(), make_array_test(), MAP, pips_user_warning, reference_indices, reference_variable, storage_formal, and value_code_p.
Referenced by interprocedural_abc_expression(), and interprocedural_abc_statement_rwt().
|
static |
Definition at line 527 of file array_bound_check_interprocedural.c.
References array_test_undefined, expression_call_p(), expression_syntax, interprocedural_abc_call(), and syntax_call.
Referenced by interprocedural_abc_call(), and interprocedural_abc_statement_rwt().
|
static |
If s is in an unstructured instruction, we must pay attention when inserting s1 before s.
take the control that has s as its statement
take the unstructured correspond to the control c
for a consistent unstructured, a test must have 2 successors, so if s1 is a test, we transform it into sequence in order to avoid this constraint.
Then we create a new control for it, with the predecessors are those of c and the only one successor is c. The new predecessors of c are only the new control
if c is the entry node of the correspond unstructured u, the newc will become the new entry node of u
Definition at line 585 of file array_bound_check_interprocedural.c.
References apply_persistant_statement_to_control(), bound_persistant_statement_to_control_p(), CAR, CONS, CONTROL, CONTROL_, control_predecessors, control_successors, fprintf(), ifdebug, insert_statement(), instruction_to_statement(), is_instruction_sequence, make_control(), make_instruction(), make_sequence(), MAP, MAPL, NIL, print_statement(), s1, stack_head(), stack_size(), STATEMENT, statement_test_p(), and unstructured_control.
Referenced by interprocedural_abc_statement_rwt().
|
static |
Definition at line 733 of file array_bound_check_interprocedural.c.
References control_domain, free_persistant_statement_to_control(), gen_context_multi_recurse(), gen_null(), gen_true(), interprocedural_abc_statement_rwt(), make_persistant_statement_to_control(), module_statement, pop_uns(), push_uns(), stack_free(), stack_make(), statement_domain, store_mapping(), and unstructured_domain.
Referenced by array_bound_check_interprocedural().
|
static |
because we use gen_recurse with statement domain, we don't have to check unstructured instruction here
Definition at line 649 of file array_bound_check_interprocedural.c.
References array_test_undefined_p(), instruction_call, instruction_tag, instruction_test, instruction_whileloop, interprocedural_abc_call(), interprocedural_abc_expression(), interprocedural_abc_insert_before_statement(), is_instruction_call, is_instruction_loop, is_instruction_sequence, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, make_interprocedural_abc_tests(), pips_internal_error, statement_instruction, stop_statement_p(), test_condition, user_log(), and whileloop_condition.
Referenced by interprocedural_abc_statement().
|
static |
Definition at line 153 of file array_bound_check_interprocedural.c.
References array_test::arr, array_test_undefined, CONS, ENTITY, exp, array_test::exp, EXPRESSION, expression_undefined_p, gen_nconc(), and NIL.
Referenced by interprocedural_abc_call().
|
static |
There is a bound violation, we can return a stop statement immediately, but for debugging purpose, it is better to display all bound violations
Definition at line 535 of file array_bound_check_interprocedural.c.
References array_test::arr, CAR, CDR, concatenate(), copy_statement(), ENDP, ENTITY, entity_name, array_test::exp, EXPRESSION, expression_to_string(), fprintf(), get_bool_property(), ifdebug, insert_statement(), make_block_statement(), make_print_statement(), make_stop_statement(), make_test(), NIL, number_of_added_tests, number_of_bound_violations, print_statement(), print_variables(), statement_undefined, statement_undefined_p, strdup(), test_to_statement, and true_expression_p().
Referenced by interprocedural_abc_statement_rwt().
|
static |
Definition at line 727 of file array_bound_check_interprocedural.c.
References pips_assert, and stack_pop().
Referenced by interprocedural_abc_statement().
|
static |
Definition at line 721 of file array_bound_check_interprocedural.c.
References stack_push().
Referenced by interprocedural_abc_statement().
|
static |
Definition at line 191 of file array_bound_check_interprocedural.c.
References binary_intrinsic_expression, copy_expression(), dimension_lower, dimension_upper, entity_type, expression_constant_p(), expression_to_int(), expression_undefined, expression_undefined_p, find_ith_dimension(), fprintf(), gen_length(), ifdebug, int_to_expression(), MINUS_OPERATOR_NAME, MULTIPLY_OPERATOR_NAME, PLUS_OPERATOR_NAME, print_expression(), type_variable, and variable_dimensions.
Referenced by interprocedural_abc_arrays().
|
static |
Definition at line 714 of file array_bound_check_interprocedural.c.
References control_statement, and extend_persistant_statement_to_control().
Referenced by interprocedural_abc_statement().
|
static |
Definition at line 113 of file array_bound_check_interprocedural.c.
Referenced by display_interprocedural_abc_statistics(), initialize_interprocedural_abc_statistics(), and make_interprocedural_abc_tests().
|
static |
Definition at line 114 of file array_bound_check_interprocedural.c.
Referenced by display_interprocedural_abc_statistics(), initialize_interprocedural_abc_statistics(), and make_interprocedural_abc_tests().
|
static |
Definition at line 115 of file array_bound_check_interprocedural.c.
Referenced by array_bound_check_interprocedural(), and display_interprocedural_abc_statistics().
|
static |
Definition at line 116 of file array_bound_check_interprocedural.c.
Referenced by array_bound_check_interprocedural(), and display_interprocedural_abc_statistics().