diff mbox

RFA: fairly mechanical PATCH for EXPR_LOC_OR_HERE macro

Message ID 4CC75720.5050004@redhat.com
State New
Headers show

Commit Message

Jason Merrill Oct. 26, 2010, 10:33 p.m. UTC
While working on constexpr I noticed that I wanted a simple way to say 
"either EXPR_LOCATION or input_location", but there wasn't one at the 
time.  So I added one, and changed all the other places that wanted it 
to use it.

Tested x86_64-pc-linux-gnu.  OK for trunk?

Comments

Richard Henderson Oct. 31, 2010, 9:11 p.m. UTC | #1
On 10/26/2010 03:33 PM, Jason Merrill wrote:
> Author: Jason Merrill <jason@redhat.com>
> Date:   Tue Oct 26 14:38:00 2010 -0400
> 
>     	* tree.h (EXPR_LOC_OR_HERE): New macro.
>     	* builtins.c (c_strlen): Use it.
>     	* c-decl.c (build_enumerator): Likewise.
>     	* gimplify.c (internal_get_tmp_var): Likewise.
>     	(shortcut_cond_expr): Likewise.
>     	(gimplify_one_sizepos): Likewise.
>     c-family/
>     	* c-common.c (conversion_warning, warn_for_collisions_1): Use
>     	EXPR_LOC_OR_HERE.
>     cp/
>     	* decl.c (pop_switch): Use EXPR_LOC_OR_HERE.
>     	* typeck.c (convert_for_assignment): Likewise.

Ok.


r~
diff mbox

Patch

commit 7a25c303a16d3693e61a471461d9cb7da600ff36
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Oct 26 14:38:00 2010 -0400

    	* tree.h (EXPR_LOC_OR_HERE): New macro.
    	* builtins.c (c_strlen): Use it.
    	* c-decl.c (build_enumerator): Likewise.
    	* gimplify.c (internal_get_tmp_var): Likewise.
    	(shortcut_cond_expr): Likewise.
    	(gimplify_one_sizepos): Likewise.
    c-family/
    	* c-common.c (conversion_warning, warn_for_collisions_1): Use
    	EXPR_LOC_OR_HERE.
    cp/
    	* decl.c (pop_switch): Use EXPR_LOC_OR_HERE.
    	* typeck.c (convert_for_assignment): Likewise.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index ca69efa..0e3d5e2 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -506,10 +506,7 @@  c_strlen (tree src, int only_value)
       && (only_value || !TREE_SIDE_EFFECTS (TREE_OPERAND (src, 0))))
     return c_strlen (TREE_OPERAND (src, 1), only_value);
 
-  if (EXPR_HAS_LOCATION (src))
-    loc = EXPR_LOCATION (src);
-  else
-    loc = input_location;
+  loc = EXPR_LOC_OR_HERE (src);
 
   src = string_constant (src, &offset_node);
   if (src == 0)
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index a06d073..bb7cf64 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -7499,9 +7499,8 @@  build_enumerator (location_t decl_loc, location_t loc,
 
   /* Set basis for default for next value.  */
   the_enum->enum_next_value
-    = build_binary_op
-         (EXPR_HAS_LOCATION (value) ? EXPR_LOCATION (value) : input_location,
-	 PLUS_EXPR, value, integer_one_node, 0);
+    = build_binary_op (EXPR_LOC_OR_HERE (value),
+		       PLUS_EXPR, value, integer_one_node, 0);
   the_enum->enum_overflow = tree_int_cst_lt (the_enum->enum_next_value, value);
 
   /* Now create a declaration for the enum value name.  */
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 2f205ad..95ab32a 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -1859,8 +1859,7 @@  conversion_warning (tree type, tree expr)
   int i;
   const int expr_num_operands = TREE_OPERAND_LENGTH (expr);
   tree expr_type = TREE_TYPE (expr);
-  location_t loc = EXPR_HAS_LOCATION (expr)
-    ? EXPR_LOCATION (expr) : input_location;
+  location_t loc = EXPR_LOC_OR_HERE (expr);
 
   if (!warn_conversion && !warn_sign_conversion)
     return;
@@ -2293,8 +2292,7 @@  warn_for_collisions_1 (tree written, tree writer, struct tlist *list,
 	  && (!only_writes || list->writer))
 	{
 	  warned_ids = new_tlist (warned_ids, written, NULL_TREE);
-	  warning_at (EXPR_HAS_LOCATION (writer)
-		      ? EXPR_LOCATION (writer) : input_location,
+	  warning_at (EXPR_LOC_OR_HERE (writer),
 		      OPT_Wsequence_point, "operation on %qE may be undefined",
 		      list->expr);
 	}
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index e513bc0..e5a1613 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -2868,10 +2868,7 @@  pop_switch (void)
   location_t switch_location;
 
   /* Emit warnings as needed.  */
-  if (EXPR_HAS_LOCATION (cs->switch_stmt))
-    switch_location = EXPR_LOCATION (cs->switch_stmt);
-  else
-    switch_location = input_location;
+  switch_location = EXPR_LOC_OR_HERE (cs->switch_stmt);
   if (!processing_template_decl)
     c_do_switch_warnings (cs->cases, switch_location,
 			  SWITCH_STMT_TYPE (cs->switch_stmt),
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 160198b..6d061e7 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -7529,8 +7529,7 @@  convert_for_assignment (tree type, tree rhs,
       && TREE_CODE (TREE_TYPE (rhs)) != BOOLEAN_TYPE
       && (complain & tf_warning))
     {
-      location_t loc = EXPR_HAS_LOCATION (rhs) 
-	? EXPR_LOCATION (rhs) : input_location;
+      location_t loc = EXPR_LOC_OR_HERE (rhs);
 
       warning_at (loc, OPT_Wparentheses,
 		  "suggest parentheses around assignment used as truth value");
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 542c223..ea7e85a 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -587,10 +587,7 @@  internal_get_tmp_var (tree val, gimple_seq *pre_p, gimple_seq *post_p,
 
   mod = build2 (INIT_EXPR, TREE_TYPE (t), t, unshare_expr (val));
 
-  if (EXPR_HAS_LOCATION (val))
-    SET_EXPR_LOCATION (mod, EXPR_LOCATION (val));
-  else
-    SET_EXPR_LOCATION (mod, input_location);
+  SET_EXPR_LOCATION (mod, EXPR_LOC_OR_HERE (val));
 
   /* gimplify_modify_expr might want to reduce this further.  */
   gimplify_and_add (mod, pre_p);
@@ -2620,8 +2617,7 @@  shortcut_cond_expr (tree expr)
       while (TREE_CODE (pred) == TRUTH_ANDIF_EXPR)
 	{
 	  /* Keep the original source location on the first 'if'.  */
-	  location_t locus = EXPR_HAS_LOCATION (expr)
-			     ? EXPR_LOCATION (expr) : input_location;
+	  location_t locus = EXPR_LOC_OR_HERE (expr);
 	  TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1);
 	  /* Set the source location of the && on the second 'if'.  */
 	  if (EXPR_HAS_LOCATION (pred))
@@ -2643,8 +2639,7 @@  shortcut_cond_expr (tree expr)
       while (TREE_CODE (pred) == TRUTH_ORIF_EXPR)
 	{
 	  /* Keep the original source location on the first 'if'.  */
-	  location_t locus = EXPR_HAS_LOCATION (expr)
-			     ? EXPR_LOCATION (expr) : input_location;
+	  location_t locus = EXPR_LOC_OR_HERE (expr);
 	  TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1);
 	  /* Set the source location of the || on the second 'if'.  */
 	  if (EXPR_HAS_LOCATION (pred))
@@ -2708,8 +2703,7 @@  shortcut_cond_expr (tree expr)
   /* If there was nothing else in our arms, just forward the label(s).  */
   if (!then_se && !else_se)
     return shortcut_cond_r (pred, true_label_p, false_label_p,
-			    EXPR_HAS_LOCATION (expr)
-			    ? EXPR_LOCATION (expr) : input_location);
+			    EXPR_LOC_OR_HERE (expr));
 
   /* If our last subexpression already has a terminal label, reuse it.  */
   if (else_se)
@@ -2741,8 +2735,7 @@  shortcut_cond_expr (tree expr)
   jump_over_else = block_may_fallthru (then_);
 
   pred = shortcut_cond_r (pred, true_label_p, false_label_p,
-			  EXPR_HAS_LOCATION (expr)
-			  ? EXPR_LOCATION (expr) : input_location);
+			  EXPR_LOC_OR_HERE (expr));
 
   expr = NULL;
   append_to_statement_list (pred, &expr);
@@ -7638,10 +7631,7 @@  gimplify_one_sizepos (tree *expr_p, gimple_seq *stmt_p)
       *expr_p = create_tmp_var (type, NULL);
       tmp = build1 (NOP_EXPR, type, expr);
       stmt = gimplify_assign (*expr_p, tmp, stmt_p);
-      if (EXPR_HAS_LOCATION (expr))
-	gimple_set_location (stmt, EXPR_LOCATION (expr));
-      else
-	gimple_set_location (stmt, input_location);
+      gimple_set_location (stmt, EXPR_LOC_OR_HERE (expr));
     }
 }
 
diff --git a/gcc/tree.h b/gcc/tree.h
index 968a1bc..b799aaa 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -1598,6 +1598,7 @@  struct GTY(()) tree_constructor {
   (EXPR_P ((NODE)) ? (NODE)->exp.locus : UNKNOWN_LOCATION)
 #define SET_EXPR_LOCATION(NODE, LOCUS) EXPR_CHECK ((NODE))->exp.locus = (LOCUS)
 #define EXPR_HAS_LOCATION(NODE) (EXPR_LOCATION (NODE) != UNKNOWN_LOCATION)
+#define EXPR_LOC_OR_HERE(NODE) (EXPR_HAS_LOCATION (NODE) ? (NODE)->exp.locus : input_location)
 #define EXPR_FILENAME(NODE) LOCATION_FILE (EXPR_CHECK ((NODE))->exp.locus)
 #define EXPR_LINENO(NODE) LOCATION_LINE (EXPR_CHECK (NODE)->exp.locus)