This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[tree-ssa] Fix gcc.dg/noreturn-*.c


This patch fixes line number information we emit for warnings diagnosed
after parsing the function which are based on the current line number.
An example would be the warnings generated if we have a missing noreturn
attribute.

What makes this even mildly interesting is the fact that we only have
a single node for a binding contour (BIND_EXPR), but the front-end has
two -- one SCOPE_STMT for the start and the end of the contour.

The net result is that when we're done simplifying SCOPE_STMTs, we
want to set the current line number to the line number associated with
the closing SCOPE_STMT.

Once that tidbit is in place, it's just a matter of making sure the
current line number isn't clobbered by inlining, optimization, etc etc.

        * c-decl.c (finish_function): No longer save/restore the
        current filename or linenumber around simplification.  Instead
        save/restore it around inlining.
        (c_expand_body_1): Save/restore current filename and linenumber
        around expansion of trees into RTL.
        * gimplify.c (simplify_function_tree): Make the current file/line
        number match the non-gimple code at the end of a function.

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.334.2.40
diff -c -3 -p -r1.334.2.40 c-decl.c
*** c-decl.c	10 Mar 2003 20:18:40 -0000	1.334.2.40
--- c-decl.c	13 Mar 2003 21:53:17 -0000
*************** finish_function (nested, can_defer_p)
*** 6351,6358 ****
       int can_defer_p;
  {
    tree fndecl = current_function_decl;
-   int saved_lineno;
-   const char *saved_filename;
  
  #if 0
    /* This caused &foo to be of type ptr-to-const-function which then
--- 6351,6356 ----
*************** finish_function (nested, can_defer_p)
*** 6409,6420 ****
        && DECL_INLINE (fndecl))
      warning ("no return statement in function returning non-void");
  
-   /* Genericizing can change the current line number and filename.
-      We need to save/restore so that we can emit the proper line
-      note for the end of the function later.  */
-   saved_lineno = lineno;
-   saved_filename = input_filename;
- 
    /* Genericize before inlining.  */
    if (!flag_disable_simple)
      c_genericize (fndecl);
--- 6407,6412 ----
*************** finish_function (nested, can_defer_p)
*** 6426,6435 ****
    free_after_compilation (cfun);
    cfun = NULL;
  
-   /* Restore file and line information.  */
-   lineno = saved_lineno;
-   input_filename = saved_filename;
- 
    if (flag_unit_at_a_time && can_defer_p)
      {
        cgraph_finalize_function (fndecl, DECL_SAVED_TREE (fndecl));
--- 6418,6423 ----
*************** finish_function (nested, can_defer_p)
*** 6466,6471 ****
--- 6454,6465 ----
  
        if (flag_inline_trees)
  	{
+ 	  /* Inlining can change the current line number and filename.
+ 	     We need to save/restore so that we can emit the proper line
+ 	     note for the end of the function later.  */
+ 	  int saved_lineno = lineno;
+ 	  const char *saved_filename = input_filename;
+ 
  	  /* First, cache whether the current function is inlinable.  Some
  	     predicates depend on cfun and current_function_decl to
  	     function completely.  */
*************** finish_function (nested, can_defer_p)
*** 6487,6492 ****
--- 6481,6489 ----
  	  
  	  /* Then, inline any functions called in it.  */
  	  optimize_inline_calls (fndecl);
+ 
+ 	  lineno = saved_lineno;
+ 	  saved_filename = input_filename;
  	  timevar_pop (TV_INTEGRATION);
  	}
  
*************** c_expand_body_1 (fndecl, nested_p)
*** 6536,6541 ****
--- 6533,6540 ----
       tree fndecl;
       int nested_p;
  {
+   const char *saved_input_filename = input_filename;
+   int saved_lineno = lineno;
    timevar_push (TV_EXPAND);
  
    if (nested_p)
*************** c_expand_body_1 (fndecl, nested_p)
*** 6627,6632 ****
--- 6626,6634 ----
       above us from being collected while we're compiling this function.  */
    if (nested_p)
      ggc_push_context ();
+ 
+   input_filename = saved_input_filename;
+   lineno = saved_lineno;
  
    /* Run the optimizers and output the assembler code for this function.  */
    rest_of_compilation (fndecl);
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.29
diff -c -3 -p -r1.1.2.29 gimplify.c
*** gimplify.c	13 Mar 2003 00:30:24 -0000	1.1.2.29
--- gimplify.c	13 Mar 2003 21:53:29 -0000
*************** simplify_function_tree (fndecl)
*** 194,199 ****
--- 194,201 ----
    int done;
    tree oldfn;
    tree tmp;
+   const char *saved_input_filename = input_filename;
+   int saved_lineno = lineno;
  
    /* Don't bother doing anything if the program has errors.  */
    if (errorcount || sorrycount)
*************** simplify_function_tree (fndecl)
*** 230,235 ****
--- 232,244 ----
      {
        fnbody = build (BIND_EXPR, void_type_node, NULL_TREE, fnbody, 
NULL_TREE);
        TREE_SIDE_EFFECTS (fnbody) = 1;
+       lineno = get_lineno (fndecl);
+       input_filename = get_filename (fndecl);
+     }
+   else
+     {
+       lineno = saved_lineno;
+       input_filename = saved_input_filename;
      }
  
    DECL_SAVED_TREE (fndecl) = fnbody;





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