25 #include "pips_config.h"
80 #include "resources.h"
119 #define array_dimension_bound_test_undefined ((array_dimension_bound_test) {NIL,NIL,NIL,NIL} )
120 #define Index_range_undefined ((Index_range) {NIL,NIL})
139 user_log(
"* There are %d array bound checks *\n",
143 user_log(
"* There %s %d array bound check%s added *\n",
149 user_log(
"* There %s %d bound violation%s *\n",
167 return "wrt common size";
169 return "1st dimension";
171 return "2nd dimension";
173 return "3rd dimension";
175 return "4th dimension";
177 return "5th dimension";
179 return "6th dimension";
181 return "7th dimension";
285 for (i=1; i<= num_dim; i++)
350 pips_debug(3,
"\n Lower bound check expression:");
374 pips_debug(3,
"\n Upper bound check expression:");
412 pips_debug(3,
"\n Array bound check for reference:");
447 pips_debug(3,
"\n Lower bound check expression:");
474 pips_debug(3,
"\n Upper bound check expression:");
533 pips_debug(3,
"\n Lower bound check expression:");
559 pips_debug(3,
"Upper bound check expression:");
608 list list_index = ir.
ind, list_range = ir.
ran;
609 while (!
ENDP(list_index))
616 list_index =
CDR(list_index);
617 list_range =
CDR(list_range);
736 fprintf(stderr,
"\n Implied DO expression:\n");
794 user_log(
"\n Warning : READ statement with write effect on array subscript. \n This case has not been treated yet :-( \n");
856 string string_delimiter =
865 string stop_message =
867 "Bound violation: array \"",
870 string_delimiter, NULL));
871 string print_message =
950 pips_debug(5,
"Unstructured case, insert a test:\n");
1005 printf(
"Insertion d'un statement ---->\n");
1102 debug_on(
"ARRAY_BOUND_CHECK_BOTTOM_UP_DEBUG_LEVEL");
1130 #define cf_ge_expression(e1, e2) \
1131 ( 1 ? binary_intrinsic_expression(">=", e1, e2) : ge_expression(e1, e2) )
1133 #define cf_gt_expression(e1, e2) \
1134 ( 1 ? binary_intrinsic_expression(">", e1, e2) : gt_expression(e1, e2) )
1136 #define cf_lt_expression(e1, e2) \
1137 ( 1 ? binary_intrinsic_expression("<", e1, e2) : lt_expression(e1, e2) )
1139 #define cf_and_expression(e1, e2) \
1140 ( 1 ? binary_intrinsic_expression("&&", e1, e2) : and_expression(e1, e2) )
1142 #define cf_or_expression(e1, e2) \
1143 ( 1 ? binary_intrinsic_expression("||", e1, e2) : or_expression(e1, e2) )
1154 #define make_add_expression(e1, e2) make_bin_expression("TOP-LEVEL:+", e1, e2)
1155 #define make_sub_expression(e1, e2) make_bin_expression("TOP-LEVEL:-", e1, e2)
1156 #define make_mul_expression(e1, e2) make_bin_expression("TOP-LEVEL:*", e1, e2)
1170 pips_assert(
"true", abort_program==abort_program);
1180 stop_func =
"TOP-LEVEL:abort";
1182 stop_func =
"TOP-LEVEL:exit";
1238 static const char prefix []=
"PIPS_size_";
1241 int i, len = strlen(name);
1243 if ((uname =
malloc(len + 1 +
sizeof(
prefix))) == NULL) {
1247 sprintf(uname,
"%s%s",
prefix, name);
1248 len = strlen(uname);
1249 for (i = 0; i < len; i++) {
1250 if (uname[i] ==
':' || uname[i] ==
'-') {
1300 }
else if (!
ENDP(acc) && !
ENDP(dims)) {
1337 if (strcmp(fun_name,
"TOP-LEVEL:+C") == 0) {
1446 #define CHECK_NARGS(n) if (nargs != (n)) return expression_undefined
1665 entity snprintf_ent, tmpbuf_ent;
1681 for (k = nargs - 1; k >= 2; k--)
1740 entity ptr, size_holder_ent;
1741 string func_name, size_holder_name;
1768 if (strcmp(func_name,
"TOP-LEVEL:malloc") == 0) {
1769 if (func_nargs != 1)
1772 }
else if (strcmp(func_name,
"TOP-LEVEL:realloc") == 0
1773 || strcmp(func_name,
"TOP-LEVEL:memalign") == 0) {
1774 if (func_nargs != 2)
1777 }
else if (strcmp(func_name,
"TOP-LEVEL:calloc") == 0) {
1778 if (func_nargs != 2)
1827 for (k = 0; k < nargs; k++) {
1833 if (strcmp(func_name,
"TOP-LEVEL:=") == 0
1841 }
else if (strcmp(func_name,
"TOP-LEVEL:free") == 0) {
1842 entity arg_ent, size_holder;
1864 if (strncmp(func_name,
"TOP-LEVEL:", 10) != 0) {
1871 if (strcmp(p->
function, func_name + 10) == 0) {
1891 for (k = 0; k < nargs; k++)
void user_log(const char *format,...)
persistant_statement_to_control make_persistant_statement_to_control(void)
entity gen_find_entity(char *s)
basic make_basic_int(intptr_t _field_)
expression copy_expression(expression p)
EXPRESSION.
statement copy_statement(statement p)
STATEMENT.
bool statement_consistent_p(statement p)
test make_test(expression a1, statement a2, statement a3)
dimension copy_dimension(dimension p)
DIMENSION.
control apply_persistant_statement_to_control(persistant_statement_to_control f, statement k)
instruction make_instruction(enum instruction_utype tag, void *val)
bool bound_persistant_statement_to_control_p(persistant_statement_to_control f, statement k)
sequence make_sequence(list a)
control make_control(statement a1, list a2, list a3)
void extend_persistant_statement_to_control(persistant_statement_to_control f, statement k, control v)
void free_persistant_statement_to_control(persistant_statement_to_control p)
static reference ref
Current stmt (an integer)
static statement module_statement
struct _newgen_struct_expression_ * expression
void const char const char const int
static expression expression_try_find_size(expression expr)
static expression sprintf_check_expression(expression args[], int nargs)
expression subscript_value(entity arr, list l_inds)
static expression bcmp_check_expression(expression args[], int nargs)
static bool push_uns(unstructured u, bottom_up_abc_context_p context)
static expression snprintf_check_expression(expression args[], int nargs)
struct bottom_up_abc_context_t * bottom_up_abc_context_p
static int entity_constant_string_size(entity e)
bool array_bound_check_bottom_up(const char *module_name)
static expression make_bin_expression(string name, expression e1, expression e2)
static array_dimension_bound_test make_array_dimension_bound_test(entity e, int i, bool low, expression exp)
static statement alloc_instrumentation(expression args[], int nargs)
static expression memcmp_check_expression(expression args[], int nargs)
#define Index_range_undefined
#define cf_or_expression(e1, e2)
static expression array_check_add(expression array_expr, expression expr)
static array_dimension_bound_test make_true_array_dimension_bound_test(entity e, int i, bool low)
static array_dimension_bound_test add_array_dimension_bound_test(array_dimension_bound_test retour, array_dimension_bound_test temp)
static bool expression_in_array_subscript(expression e, list args)
static statement make_bottom_up_abc_tests(array_dimension_bound_test adt)
static array_dimension_bound_test bottom_up_abc_base_reference_implied_do(reference re, expression ind, range ran)
#define cf_and_expression(e1, e2)
static bool store_mapping(control c, bottom_up_abc_context_p context)
static expression make_strlen_expression(expression arg)
static statement make_c_stop_statement(int abort_program)
#define make_sub_expression(e1, e2)
static array_dimension_bound_test bottom_up_abc_expression_implied_do(expression e, Index_range ir)
static array_dimension_bound_test bottom_up_abc_expression(expression e)
static array_dimension_bound_test abc_with_allocation_size(reference r)
The test is: 1 <= offset(e) + subscript_value(r) <= area_size(common)
static expression strncat_check_expression(expression args[], int nargs)
static int number_of_added_checks
static expression expression_try_find_string_size(expression expr)
static int number_of_bound_checks
Statistic variables:
static expression array_indices_check(expression expr)
struct Index_range Index_range
Data structure to support abc Implied DO.
static array_dimension_bound_test bottom_up_abc_reference_implied_do(expression e, Index_range ir)
static array_dimension_bound_test bottom_up_abc_reference(reference r)
statement emit_message_and_stop(string stop_message)
static bool read_statement_with_write_effect_on_array_subscript(call c)
static bool array_dimension_bound_test_undefined_p(array_dimension_bound_test x)
static struct checkfn checkfns[]
#define array_dimension_bound_test_undefined
static array_dimension_bound_test bottom_up_abc_call(call cal)
static void bottom_up_abc_statement_rwt(statement s, bottom_up_abc_context_p context)
static void initialize_bottom_up_abc_statistics()
static int number_of_bound_violations
static expression memmove_check_expression(expression args[], int nargs)
bool array_need_bound_check_p(entity e)
This function returns true, if the array needs bound checks false, otherwise.
#define cf_lt_expression(e1, e2)
static void bottom_up_abc_insert_before_statement(statement s, statement s1, bottom_up_abc_context_p context)
#define cf_ge_expression(e1, e2)
#define make_add_expression(e1, e2)
static statement cstr_args_check(statement)
forward declaration
static expression memcpy_check_expression(expression args[], int nargs)
#define cf_gt_expression(e1, e2)
static expression bcopy_check_expression(expression args[], int nargs)
static void display_bottom_up_abc_statistics()
static void pop_uns(unstructured u, bottom_up_abc_context_p context)
static expression strncpy_check_expression(expression args[], int nargs)
static expression strcpy_check_expression(expression args[], int nargs)
string print_variables(expression e)
static expression bzero_check_expression(expression args[], int nargs)
static void bottom_up_abc_statement(statement module_statement)
static expression memset_check_expression(expression args[], int nargs)
string int_to_dimension(int i)
Warning! Do not modify this file that is automatically generated!
struct array_dimension_bound_test array_dimension_bound_test
As we create checks with stop error message who tell us there are bound violations for which array,...
static string entity_size_uname(entity e)
static expression strcat_check_expression(expression args[], int nargs)
string bool_to_bound(bool b)
array_bound_check_top_down.c
bdt base
Current expression.
struct _newgen_struct_statement_ * statement
const char * module_name(const char *s)
Return the module part of an entity name.
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
statement make_block_statement(list)
Make a block statement from a list of statement.
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
void reset_current_module_entity(void)
Reset the current module entity.
void reset_current_module_statement(void)
Reset the current module statement.
statement set_current_module_statement(statement)
Set the current module statement.
entity set_current_module_entity(entity)
static.c
entity get_current_module_entity(void)
Get the entity of the current module.
void gen_context_multi_recurse(void *o, void *context,...)
Multi-recursion with context function visitor.
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
#define ENDP(l)
Test if a list is empty.
#define NIL
The empty list (nil in Lisp)
size_t gen_length(const list l)
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
#define CAR(pcons)
Get the value of the first element of a list.
#define CDR(pcons)
Get the list less its first element.
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
bool statement_test_p(statement)
statement make_any_print_statement(string)
Generate a print of a constant character string on stderr for C or on stdout for Fortran.
statement make_assign_statement(expression, expression)
void put_a_comment_on_a_statement(statement, string)
Similar to try_to_put_a_comment_on_a_statement() but insert a CONTINUE to put the comment on it if th...
statement make_print_statement(string)
Make a Fortran print statement.
statement make_stop_statement(string)
This function returns a Fortran stop statement with an error message.
statement make_call_statement(string, list, entity, string)
This function is limited to intrinsics calls...
void insert_statement(statement, statement, bool)
This is the normal entry point.
statement make_exit_statement(int, string)
This function returns a statement ending with a C exit statement.
bool expression_constant_p(expression)
HPFC module by Fabien COELHO.
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
#define pips_internal_error
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
#define TOP_LEVEL_MODULE_NAME
Module containing the global variables in Fortran and C.
string concatenate(const char *,...)
Return the concatenation of the given strings.
void * stack_head(const stack)
returns the item on top of stack s
int stack_size(const stack)
observers
void stack_push(void *, stack)
stack use
void stack_free(stack *)
type, bucket_size, policy
stack stack_make(int, int, int)
allocation
void * stack_pop(stack)
POPs one item from stack s.
hash_table set_ordering_to_statement(statement s)
To be used instead of initialize_ordering_to_statement() to make sure that the hash table ots is in s...
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
string reference_to_string(reference r)
void print_expression(expression e)
no file descriptor is passed to make is easier to use in a debugging stage.
string expression_to_string(expression e)
void print_reference(reference r)
void print_statement(statement)
Print a statement on stderr.
static const char * prefix
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
#define READ_FUNCTION_NAME
#define IO_EFFECTS_PACKAGE_NAME
Implicit variables to handle IO effetcs.
#define MINUS_OPERATOR_NAME
#define PLUS_OPERATOR_NAME
#define gt_expression(e1, e2)
#define test_to_statement(t)
#define binary_intrinsic_expression(name, e1, e2)
#define MULTIPLY_OPERATOR_NAME
#define lt_expression(e1, e2)
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
entity FindOrCreateEntity(const char *package, const char *local_name)
Problem: A functional global entity may be referenced without parenthesis or CALL keyword in a functi...
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
entity FindOrCreateTopLevelEntity(const char *name)
Return a top-level entity.
bool fortran_module_p(entity m)
Test if a module is in Fortran.
const char * entity_module_name(entity e)
See comments about module_name().
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
expression make_entity_expression(entity e, cons *inds)
void clean_all_normalized(expression e)
bool same_expression_in_list_p(expression e, list le)
This function returns true, if there exists a same expression in the list false, otherwise.
bool expression_call_p(expression e)
int expression_to_int(expression exp)
================================================================
int trivial_expression_p(expression e)
This function returns:
bool true_expression_p(expression e)
expression make_call_expression(entity e, list l)
Build an expression that call an function entity with an argument list.
bool expression_equal_p(expression e1, expression e2)
Syntactic equality e1==e2.
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
expression find_ith_argument(list args, int n)
bool unbounded_dimension_p(dimension dim)
bool unbounded_dimension_p(dim) input : a dimension of an array entity.
bool array_reference_p(reference r)
predicates on references
bool expression_reference_p(expression e)
Test if an expression is a reference.
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
bool expression_implied_do_p(e)
bool same_expression_p(expression e1, expression e2)
this is slightly different from expression_equal_p, as it will return true for a+b vs b+a
expression make_true_expression()
dimension find_ith_dimension(list, int)
This function returns the ith dimension of a list of dimensions.
entity make_scalar_entity(const char *, const char *, basic)
entity make_scalar_entity(name, module_name, base)
bool variable_in_common_p(entity)
true if v is in a common.
_int SizeOfElements(basic)
This function returns the length in bytes of the Fortran or C type represented by a basic,...
#define type_functional_p(x)
#define functional_result(x)
#define unstructured_domain
newgen_type_domain_defined
#define value_constant(x)
#define syntax_reference(x)
#define reference_variable(x)
#define control_predecessors(x)
struct _newgen_struct_unstructured_ * unstructured
#define type_functional(x)
#define dimension_lower(x)
#define entity_storage(x)
#define statement_domain
newgen_sizeofexpression_domain_defined
#define control_domain
newgen_controlmap_domain_defined
#define CONTROL(x)
CONTROL.
#define range_increment(x)
#define value_constant_p(x)
#define EXPRESSION(x)
EXPRESSION.
#define constant_int_p(x)
#define expression_undefined
@ is_instruction_unstructured
@ is_instruction_whileloop
@ is_instruction_sequence
#define instruction_tag(x)
#define dimension_upper(x)
#define reference_indices(x)
#define control_successors(x)
#define dimension_undefined
#define expression_undefined_p(x)
#define test_condition(x)
#define instruction_whileloop(x)
#define unstructured_entry(x)
#define variable_dimensions(x)
#define statement_instruction(x)
#define instruction_call(x)
#define call_arguments(x)
#define control_statement(x)
#define instruction_test(x)
#define statement_undefined_p(x)
#define whileloop_condition(x)
#define basic_string_p(x)
#define expression_syntax(x)
#define type_variable_p(x)
#define variable_basic(x)
#define statement_undefined
#define STATEMENT(x)
STATEMENT.
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
Data structure to support abc Implied DO.
As we create checks with stop error message who tell us there are bound violations for which array,...
context data structure for bottom_up_abc newgen recursion
persistant_statement_to_control map
expression(* check_statement)(expression *, int)
The structure used to build lists in NewGen.
#define exp
Avoid some warnings from "gcc -Wshadow".