This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ping: Generate diagnostic with source line number in the trans-*.c functions


I'd still very much appreciate help on the following question:

Is there a clean way to get t he source line number inside
gfc_trans_runtime_check(), for example from the cond tree (first
argument), or is it too late to do anything like this?

The complete story:


Right now, calls to library function _gfortran_runtime_check (for
example for out of bounds checking) are generated in the following
way:
    _gfortran_runtime_error ("Array reference out of bounds", "a.f90", 1);
But _gfortran_runtime_error is declared in the library as:
    void runtime_error (const char *);

So the source filename and line number are never used. I'm modifying
the front-end to directly generate error messages including filename
and line number (and, later, the name of the variable involved and
other things): the patch to do that is at the end of the mail. But
existing code in trans.c takes the line number from the input_line
variable, which appears to be wrong (in my simple tests, input_line is
off by one).

Is there a clean way to get t he source line number inside
gfc_trans_runtime_check(), for example from the cond tree (first
argument), or is it too late to do anything like this?

Thanks,
FX



Index: trans.c
===================================================================
--- trans.c     (revision 113849)
+++ trans.c     (working copy)
@@ -302,12 +306,14 @@
 /* Generate a runtime error if COND is true.  */

 void
-gfc_trans_runtime_check (tree cond, tree msg, stmtblock_t * pblock)
+gfc_trans_runtime_check (tree cond, const char * msgid, stmtblock_t * pblock)
 {
   stmtblock_t block;
   tree body;
   tree tmp;
   tree args;
+  char * message, buf[1];
+  int len;

   if (integer_zerop (cond))
     return;
@@ -315,19 +321,15 @@
   /* The code to generate the error.  */
   gfc_start_block (&block);

-  gcc_assert (TREE_CODE (msg) == STRING_CST);
+  len = snprintf (buf, 0, "%s (in file '%s', at line %d)", _(msgid),
+                 gfc_source_file, input_line) + 1;
+  message = alloca (len);
+  snprintf (message, len, "%s (in file '%s', at line %d)", _(msgid),
+           gfc_source_file, input_line);

-  TREE_USED (msg) = 1;
-
-  tmp = gfc_build_addr_expr (pchar_type_node, msg);
+  tmp = gfc_build_addr_expr (pchar_type_node,
gfc_build_cstring_const(message));
   args = gfc_chainon_list (NULL_TREE, tmp);

-  tmp = gfc_build_addr_expr (pchar_type_node, gfc_strconst_current_filename);
-  args = gfc_chainon_list (args, tmp);
-
-  tmp = build_int_cst (NULL_TREE, input_line);
-  args = gfc_chainon_list (args, tmp);
-
   tmp = build_function_call_expr (gfor_fndecl_runtime_error, args);
   gfc_add_expr_to_block (&block, tmp);



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]