Patchwork [2/2] Better system header location detection for built-in macro tokens

login
register
mail settings
Submitter Paolo Carlini
Date June 3, 2012, 10:04 p.m.
Message ID <4FCBDF68.9090602@oracle.com>
Download mbox | patch
Permalink /patch/162606/
State New
Headers show

Comments

Paolo Carlini - June 3, 2012, 10:04 p.m.
On 06/03/2012 05:27 AM, Jason Merrill wrote:
> On 06/02/2012 12:40 PM, Paolo Carlini wrote:
>> That said, the tricks we are playing with the global input_location 
>> vs the loc we are passing around still confuse me quite a lot. 
>> Actually any *assignment* to input_location makes me a bit more 
>> nervous than I was already ;) Do you have any idea whether just 
>> passing down to build_x_modify_expr a different value for loc instead 
>> of assigning to input_location would also work for you? Maybe 
>> together with more throughly forwarding the loc from 
>> build_x_modify_expr itself to the build_min* functions (ie the 
>> project I mentioned above)??
>
> We already pass to build_x_modify_expr the location that he is 
> assigning to input_location.  I would guess that the issue in this 
> case is with the "in_system_header" macro, which uses input_location.
>
> I think the input_location hack here is OK until we improve our use of 
> explicit locations to make it unnecessary.
Good.

In any case, as far as I can see, the assignment Dodji is adding just 
before calling build_x_modify_expr doesn't change anything for "my" 
issue, which actually has to do with build_x_binary_op: if I apply to 
below, thus passing an actual loc to build_min_non_dep_loc, there is a 
diagnostic regression for the locations of 
libstdc++-v3/testsuite/20_util/bind_ref_neg.cc. If you see something 
obviously wrong somewhere, just let me know...

Paolo.

///////////////////
Jason Merrill - June 4, 2012, 12:04 a.m.
On 06/03/2012 06:04 PM, Paolo Carlini wrote:
> if I apply to
> below, thus passing an actual loc to build_min_non_dep_loc, there is a
> diagnostic regression for the locations of
> libstdc++-v3/testsuite/20_util/bind_ref_neg.cc. If you see something
> obviously wrong somewhere, just let me know...

Nope, it looks fine to me.  I guess the change is due to having an 
explicit location on a tree that used to have none.

Jason

Patch

Index: typeck.c
===================================================================
--- typeck.c	(revision 188155)
+++ typeck.c	(working copy)
@@ -2696,9 +2696,8 @@  finish_class_member_access_expr (tree object, tree
 	    BASELINK_QUALIFIED_P (member) = 1;
 	  orig_name = member;
 	}
-      return build_min_non_dep (COMPONENT_REF, expr,
-				orig_object, orig_name,
-				NULL_TREE);
+      return build_min_non_dep_loc (UNKNOWN_LOCATION, COMPONENT_REF, expr,
+				    orig_object, orig_name, NULL_TREE);
     }
 
   return expr;
@@ -2763,7 +2762,7 @@  build_x_indirect_ref (location_t loc, tree expr, r
     rval = cp_build_indirect_ref (expr, errorstring, complain);
 
   if (processing_template_decl && rval != error_mark_node)
-    return build_min_non_dep (INDIRECT_REF, rval, orig_expr);
+    return build_min_non_dep_loc (loc, INDIRECT_REF, rval, orig_expr);
   else
     return rval;
 }
@@ -3631,7 +3630,7 @@  build_x_binary_op (location_t loc, enum tree_code
     warn_about_parentheses (code, arg1_code, orig_arg1, arg2_code, orig_arg2);
 
   if (processing_template_decl && expr != error_mark_node)
-    return build_min_non_dep (code, expr, orig_arg1, orig_arg2);
+    return build_min_non_dep_loc (loc, code, expr, orig_arg1, orig_arg2);
 
   return expr;
 }
@@ -3660,8 +3659,8 @@  build_x_array_ref (location_t loc, tree arg1, tree
 		       NULL_TREE, /*overload=*/NULL, complain);
 
   if (processing_template_decl && expr != error_mark_node)
-    return build_min_non_dep (ARRAY_REF, expr, orig_arg1, orig_arg2,
-			      NULL_TREE, NULL_TREE);
+    return build_min_non_dep_loc (loc, ARRAY_REF, expr, orig_arg1, orig_arg2,
+				  NULL_TREE, NULL_TREE);
   return expr;
 }
 
@@ -4764,7 +4763,7 @@  build_x_unary_op (location_t loc, enum tree_code c
     }
 
   if (processing_template_decl && exp != error_mark_node)
-    exp = build_min_non_dep (code, exp, orig_expr,
+    exp = build_min_non_dep_loc (loc, code, exp, orig_expr,
 			     /*For {PRE,POST}{INC,DEC}REMENT_EXPR*/NULL_TREE);
   if (TREE_CODE (exp) == ADDR_EXPR)
     PTRMEM_OK_P (exp) = ptrmem;
@@ -5624,8 +5623,8 @@  build_x_conditional_expr (location_t loc, tree ife
   expr = build_conditional_expr (ifexp, op1, op2, complain);
   if (processing_template_decl && expr != error_mark_node)
     {
-      tree min = build_min_non_dep (COND_EXPR, expr,
-				    orig_ifexp, orig_op1, orig_op2);
+      tree min = build_min_non_dep_loc (loc, COND_EXPR, expr,
+					orig_ifexp, orig_op1, orig_op2);
       /* In C++11, remember that the result is an lvalue or xvalue.
          In C++98, lvalue_kind can just assume lvalue in a template.  */
       if (cxx_dialect >= cxx0x
@@ -5742,7 +5741,8 @@  build_x_compound_expr (location_t loc, tree op1, t
     result = cp_build_compound_expr (op1, op2, complain);
 
   if (processing_template_decl && result != error_mark_node)
-    return build_min_non_dep (COMPOUND_EXPR, result, orig_op1, orig_op2);
+    return build_min_non_dep_loc (loc, COMPOUND_EXPR, result,
+				  orig_op1, orig_op2);
 
   return result;
 }
Index: tree.c
===================================================================
--- tree.c	(revision 188155)
+++ tree.c	(working copy)
@@ -2086,7 +2086,7 @@  build_min (enum tree_code code, tree tt, ...)
    built.  */
 
 tree
-build_min_non_dep (enum tree_code code, tree non_dep, ...)
+build_min_non_dep_loc (location_t loc, enum tree_code code, tree non_dep, ...)
 {
   tree t;
   int length;
@@ -2101,6 +2101,7 @@  tree
     non_dep = TREE_OPERAND (non_dep, 0);
 
   t = make_node (code);
+  SET_EXPR_LOCATION (t, loc);
   length = TREE_CODE_LENGTH (code);
   TREE_TYPE (t) = TREE_TYPE (non_dep);
   TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep);
Index: decl2.c
===================================================================
--- decl2.c	(revision 188155)
+++ decl2.c	(working copy)
@@ -407,8 +407,8 @@  grok_array_decl (location_t loc, tree array_expr,
       expr = build_array_ref (input_location, array_expr, index_exp);
     }
   if (processing_template_decl && expr != error_mark_node)
-    return build_min_non_dep (ARRAY_REF, expr, orig_array_expr, orig_index_exp,
-			      NULL_TREE, NULL_TREE);
+    return build_min_non_dep_loc (loc, ARRAY_REF, expr, orig_array_expr,
+				  orig_index_exp, NULL_TREE, NULL_TREE);
   return expr;
 }
 
Index: cp-tree.h
===================================================================
--- cp-tree.h	(revision 188155)
+++ cp-tree.h	(working copy)
@@ -5697,7 +5697,8 @@  extern bool builtin_valid_in_constant_expr_p    (c
 extern tree build_min				(enum tree_code, tree, ...);
 extern tree build_min_nt_loc			(location_t, enum tree_code,
 						 ...);
-extern tree build_min_non_dep			(enum tree_code, tree, ...);
+extern tree build_min_non_dep_loc		(location_t, enum tree_code,
+						 tree, ...);
 extern tree build_min_non_dep_call_vec		(tree, tree, VEC(tree,gc) *);
 extern tree build_cplus_new			(tree, tree, tsubst_flags_t);
 extern tree build_aggr_init_expr		(tree, tree, tsubst_flags_t);