This is the mail archive of the 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]

Re: [patch] location for unary operators

> Ok.
> r~

Hi folks.

Sorry I took so long to commit this (just did), but the patch caused a
regression on the GDB testsuite that I wanted to address.

With more location granularity in expressions, arguments in function
calls now have the location of the actual argument, not the beginning of
the function call.  For example:

	line1    funccall(arg1,
	line2             x=arg2);

With the patch in question, ``x=arg2'' now has a location of line #2
(not line#1 as before), which is confusing to the debugger.  For
example, if we put a breakpoint on SOME-STATEMENT, on x86 the debugger
will stop right after line0, which is now line2 because code generation
has evaluated ``x=arg2'' before calling ``funccall''.  Needless to say,
this is highly confusing, especially with multiple complex arguments.

Daniel beat me over the head explaining why "correct" location doesn't
necessarily mean good debug info.  There was some discussion on using
the ``is_stmt'' DWARF flag to mark the beginning/end of statements.
However, this being stage3 and all, and me being inherently lazy... I
figured it is easier to make gimplify_arg() set the location from the
CALL_EXPR (patch below), thus ensuring that arguments have the location
of the original call.

If we encounter problems in which we need the original location (for
diagnostics in the gimplifier or later), but the resulting debug
information is not useful/accurate, we may have to use a DWARF flag, or
alternate solution.  But this alas, will need a new branch.

For now, this works wonders.

In addition to the patch Richard approved, I am committing the patch
below tweaking gimplify_arg().  It was tested on x86-64 Linux for both
the GCC and GDB testsuite.

	* gimplify.c (gimplify_arg): Add location argument.  Use it.
	(gimplify_call_expr): Pass location to gimplify_arg.
	(gimplify_modify_expr_to_memcpy): Same.
	(gimplify_modify_expr_to_memset): Same.

Index: gimplify.c
--- gimplify.c	(revision 140913)
+++ gimplify.c	(working copy)
@@ -2238,10 +2238,11 @@ maybe_with_size_expr (tree *expr_p)
 /* Helper for gimplify_call_expr.  Gimplify a single argument *ARG_P
-   Store any side-effects in PRE_P.  */
+   Store any side-effects in PRE_P.  CALL_LOCATION is the location of
+   the CALL_EXPR.  */
 static enum gimplify_status
-gimplify_arg (tree *arg_p, gimple_seq *pre_p)
+gimplify_arg (tree *arg_p, gimple_seq *pre_p, location_t call_location)
   bool (*test) (tree);
   fallback_t fb;
@@ -2259,6 +2260,10 @@ gimplify_arg (tree *arg_p, gimple_seq *p
   /* If this is a variable sized type, we must remember the size.  */
   maybe_with_size_expr (arg_p);
+  /* Make sure arguments have the same location as the function call
+     itself.  */
+  protected_set_expr_location (*arg_p, call_location);
   /* There is a sequence point before a function call.  Side effects in
      the argument list must occur before the actual call. So, when
      gimplifying arguments, force gimplify_expr to use an internal
@@ -2448,7 +2453,8 @@ gimplify_call_expr (tree *expr_p, gimple
              be the plain PARM_DECL.  */
           if ((i != 1) || !builtin_va_start_p)
-              t = gimplify_arg (&CALL_EXPR_ARG (*expr_p, i), pre_p);
+              t = gimplify_arg (&CALL_EXPR_ARG (*expr_p, i), pre_p,
+				EXPR_LOCATION (*expr_p));
               if (t == GS_ERROR)
                 ret = GS_ERROR;
@@ -3095,10 +3101,10 @@ gimplify_modify_expr_to_memcpy (tree *ex
   from = TREE_OPERAND (*expr_p, 1);
   from_ptr = build_fold_addr_expr (from);
-  gimplify_arg (&from_ptr, seq_p);
+  gimplify_arg (&from_ptr, seq_p, EXPR_LOCATION (*expr_p));
   to_ptr = build_fold_addr_expr (to);
-  gimplify_arg (&to_ptr, seq_p);
+  gimplify_arg (&to_ptr, seq_p, EXPR_LOCATION (*expr_p));
   t = implicit_built_in_decls[BUILT_IN_MEMCPY];
@@ -3145,7 +3151,7 @@ gimplify_modify_expr_to_memset (tree *ex
   to = TREE_OPERAND (*expr_p, 0);
   to_ptr = build_fold_addr_expr (to);
-  gimplify_arg (&to_ptr, seq_p);
+  gimplify_arg (&to_ptr, seq_p, EXPR_LOCATION (*expr_p));
   t = implicit_built_in_decls[BUILT_IN_MEMSET];
   gs = gimple_build_call (t, 3, to_ptr, integer_zero_node, size);

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