From bf911928850d193880d024f953cffb6caeeaa741 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 28 Aug 2015 11:42:08 -0400
Subject: [PATCH 55/56] C/C family: use token ranges for various diagnostics

These ones don't yet have test explicit coverage.

FIXME: this doesn't work yet, since for some reason we don't
yet get ranges for CPP_PRAGMA tokens.

gcc/c-family/ChangeLog:
	* c-common.c (c_alignof_expr): Convert param 1 from location_t to
	source_range.
	* c-common.h (c_alignof_expr): Likewise.

gcc/c/ChangeLog:
	* c-parser.c (c_parser_initelt): Use token range for
	"obsolete use of designated initializer" warnings.
	(c_parser_statement_after_labels): Likewise for
	missing -fcilkplus errors.
	(c_parser_asm_statement): Likewise for "qualifier ignored"
	warning.
	(c_parser_alignof_expression): Likewise for various warnings and
	call to c_alignof_expr.
	(c_parser_pragma): Likewise for two errors.
---
 gcc/c-family/c-common.c |  5 +++--
 gcc/c-family/c-common.h |  2 +-
 gcc/c/c-parser.c        | 25 +++++++++++++------------
 3 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index d900386..224f490 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -5476,9 +5476,10 @@ c_sizeof_or_alignof_type (location_t loc,
    location of the ALIGNOF operator.  */
 
 tree
-c_alignof_expr (location_t loc, tree expr)
+c_alignof_expr (source_range tok_range, tree expr)
 {
   tree t;
+  location_t loc = tok_range.m_start;
 
   if (VAR_OR_FUNCTION_DECL_P (expr))
     t = size_int (DECL_ALIGN_UNIT (expr));
@@ -5486,7 +5487,7 @@ c_alignof_expr (location_t loc, tree expr)
   else if (TREE_CODE (expr) == COMPONENT_REF
 	   && DECL_C_BIT_FIELD (TREE_OPERAND (expr, 1)))
     {
-      error_at (loc, "%<__alignof%> applied to a bit-field");
+      error_at (tok_range, "%<__alignof%> applied to a bit-field");
       t = size_one_node;
     }
   else if (TREE_CODE (expr) == COMPONENT_REF
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index a64f5f8..825922b 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -802,7 +802,7 @@ extern tree c_save_expr (tree);
 extern tree c_common_truthvalue_conversion (location_t, tree);
 extern void c_apply_type_quals_to_decl (int, tree);
 extern tree c_sizeof_or_alignof_type (location_t, tree, bool, bool, int);
-extern tree c_alignof_expr (location_t, tree);
+extern tree c_alignof_expr (source_range, tree);
 /* Print an error message for invalid operands to arith operation CODE.
    NOP_EXPR is used as a special case (see truthvalue_conversion).  */
 extern void binary_op_error (location_t, enum tree_code, tree, tree,
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 0ff1558..9068f24 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -4273,7 +4273,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
 		      c_parser_peek_token (parser)->value,
 		      braced_init_obstack);
       /* Use the colon as the error location.  */
-      pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic,
+      pedwarn (c_parser_peek_2nd_token (parser)->range, OPT_Wpedantic,
 	       "obsolete use of designated initializer with %<:%>");
       c_parser_consume_token (parser);
       c_parser_consume_token (parser);
@@ -4437,7 +4437,7 @@ c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack)
 	  else
 	    {
 	      if (des_seen == 1)
-		pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic,
+		pedwarn (c_parser_peek_token (parser)->range, OPT_Wpedantic,
 			 "obsolete use of designated initializer without %<=%>");
 	      else
 		{
@@ -5017,7 +5017,7 @@ c_parser_statement_after_labels (c_parser *parser)
 	case RID_CILK_FOR:
 	  if (!flag_cilkplus)
 	    {
-	      error_at (c_parser_peek_token (parser)->location,
+	      error_at (c_parser_peek_token (parser)->range,
 			"-fcilkplus must be enabled to use %<_Cilk_for%>");
 	      c_parser_skip_to_end_of_block_or_statement (parser);
 	    }
@@ -5028,7 +5028,8 @@ c_parser_statement_after_labels (c_parser *parser)
 	  c_parser_consume_token (parser);
 	  c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>");
 	  if (!flag_cilkplus) 
-	    error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>");
+	    error_at (tok_range,
+		      "-fcilkplus must be enabled to use %<_Cilk_sync%>");
 	  else 
 	    add_stmt (build_cilk_sync ());
 	  break;
@@ -5767,7 +5768,7 @@ c_parser_asm_statement (c_parser *parser)
   else if (c_parser_next_token_is_keyword (parser, RID_CONST)
 	   || c_parser_next_token_is_keyword (parser, RID_RESTRICT))
     {
-      warning_at (c_parser_peek_token (parser)->location,
+      warning_at (c_parser_peek_token (parser)->range,
 		  0,
 		  "%E qualifier ignored on asm",
 		  c_parser_peek_token (parser)->value);
@@ -6778,7 +6779,7 @@ static struct c_expr
 c_parser_alignof_expression (c_parser *parser)
 {
   struct c_expr expr;
-  location_t loc = c_parser_peek_token (parser)->location;
+  source_range tok_range = c_parser_peek_token (parser)->range;
   tree alignof_spelling = c_parser_peek_token (parser)->value;
   gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
   bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling),
@@ -6789,10 +6790,10 @@ c_parser_alignof_expression (c_parser *parser)
   if (is_c11_alignof)
     {
       if (flag_isoc99)
-	pedwarn_c99 (loc, OPT_Wpedantic, "ISO C99 does not support %qE",
+	pedwarn_c99 (tok_range, OPT_Wpedantic, "ISO C99 does not support %qE",
 		     alignof_spelling);
       else
-	pedwarn_c99 (loc, OPT_Wpedantic, "ISO C90 does not support %qE",
+	pedwarn_c99 (tok_range, OPT_Wpedantic, "ISO C90 does not support %qE",
 		     alignof_spelling);
     }
   c_parser_consume_token (parser);
@@ -6845,9 +6846,9 @@ c_parser_alignof_expression (c_parser *parser)
       mark_exp_read (expr.value);
       c_inhibit_evaluation_warnings--;
       in_alignof--;
-      pedwarn (loc, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
+      pedwarn (tok_range, OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>",
 	       alignof_spelling);
-      ret.value = c_alignof_expr (loc, expr.value);
+      ret.value = c_alignof_expr (tok_range, expr.value);
       ret.original_code = ERROR_MARK;
       ret.original_type = NULL;
       return ret;
@@ -9860,7 +9861,7 @@ c_parser_pragma (c_parser *parser, enum pragma_context context)
       return false;
 
     case PRAGMA_OMP_SECTION:
-      error_at (c_parser_peek_token (parser)->location,
+      error_at (c_parser_peek_token (parser)->range,
 		"%<#pragma omp section%> may only be used in "
 		"%<#pragma omp sections%> construct");
       c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
@@ -9908,7 +9909,7 @@ c_parser_pragma (c_parser *parser, enum pragma_context context)
 	}
       if (context == pragma_external)
 	{
-	  error_at (c_parser_peek_token (parser)->location,
+	  error_at (c_parser_peek_token (parser)->range,
 		    "%<#pragma grainsize%> must be inside a function");
 	  c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL);
 	  return false;
-- 
1.8.5.3

