substring boundardy check (PR27588): writing a dg tests case
Tobias Burnus
burnus@net-b.de
Tue Oct 3 21:28:00 GMT 2006
Hello,
I have two questions:
a) Are there any pre-review comments to the following patch? It
currently writes such error messages:
Fortran runtime error: Substring out of bounds: lower bound less than
one (in file 'string2.f90', at line 5)
Fortran runtime error: Substring out of bounds: upper bound exceeds
string length (in file 'cbnd1.for', at line 5)
Is it ok like that?
b) I would like to add a test case to the test suit, but how does one
test for run-time errors?
If I have a solution for (b), I will submit a proper patch.
(With this patch, gfortran detects cbnd1, cbnd2 and cbnd4 of
http://www.polyhedron.com/pb05/linux/diagnose.html; cbnd3 can only be
detected when cross analysing in the file [e.g. "-gen-interface" in
Intel] or passing a specially crafted argument ["-C call" in NAG f95].)
Tobias
Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c (revision 117391)
--- gcc/fortran/trans-expr.c (working copy)
*************** gfc_conv_substring (gfc_se * se, gfc_ref
*** 239,246 ****
--- 239,249 ----
tree tmp;
tree type;
tree var;
+ tree fault;
gfc_se start;
gfc_se end;
+ locus loc;
+ char *msg;
type = gfc_get_character_type (kind, ref->u.ss.length);
type = build_pointer_type (type);
*************** gfc_conv_substring (gfc_se * se, gfc_ref
*** 272,277 ****
--- 275,292 ----
gfc_conv_expr_type (&end, ref->u.ss.end, gfc_charlen_type_node);
gfc_add_block_to_block (&se->pre, &end.pre);
}
+ if (flag_bounds_check) {
+ gfc_get_backend_locus(&loc);
+ fault = fold_build2 (LT_EXPR, boolean_type_node, start.expr,
build_int_cst (gfc_charlen_type_node, 1));
+ asprintf (&msg, "Substring out of bounds: lower bound less than
one");
+ gfc_trans_runtime_check (fault, msg, &se->pre, &loc);
+
+ /* Check upper bound. */
+ fault = fold_build2 (GT_EXPR, boolean_type_node, end.expr,
se->string_length);
+ asprintf (&msg, "Substring out of bounds: upper bound exceeds
string length");
+ gfc_trans_runtime_check (fault, msg, &se->pre, &loc);
+ }
+
tmp = fold_build2 (MINUS_EXPR, gfc_charlen_type_node,
build_int_cst (gfc_charlen_type_node, 1),
start.expr);
More information about the Fortran
mailing list