aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2008-09-03 01:00:04 +0000
committerAldy Hernandez <aldyh@gcc.gnu.org>2008-09-03 01:00:04 +0000
commita63068b6dd49f620e85c95f1dfed8f7d7473e17c (patch)
treee8cf01ea25ea102fb71086ca128988be07714307 /gcc
parentaeb76a25a759aac503037bad8f1dc07b8dd1e9a7 (diff)
downloadgcc-a63068b6dd49f620e85c95f1dfed8f7d7473e17c.zip
gcc-a63068b6dd49f620e85c95f1dfed8f7d7473e17c.tar.gz
gcc-a63068b6dd49f620e85c95f1dfed8f7d7473e17c.tar.bz2
diagnostic.c (error_at): New.
* diagnostic.c (error_at): New. * toplev.h (error_at): New prototype. * c-typeck.c (build_array_ref): Call error_at instead of error. Pass location to pedwarn. cp/ * typeck.c (build_array_ref): Use new location argument. * class.c (build_vtbl_ref_1): Pass location to build_array_ref. * call.c (build_new_op): Same. * decl2.c (grok_array_decl): Same. * cp-tree.h (build_array_ref): Add location argument to prototype. From-SVN: r139924
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/c-typeck.c10
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/call.c2
-rw-r--r--gcc/cp/class.c2
-rw-r--r--gcc/cp/cp-tree.h2
-rw-r--r--gcc/cp/decl2.c2
-rw-r--r--gcc/cp/typeck.c56
-rw-r--r--gcc/diagnostic.c13
-rw-r--r--gcc/toplev.h1
10 files changed, 73 insertions, 30 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e14b559..ee3bf7d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2008-09-02 Aldy Hernandez <aldyh@redhat.com>
+
+ * diagnostic.c (error_at): New.
+ * toplev.h (error_at): New prototype.
+ * c-typeck.c (build_array_ref): Call error_at instead of error.
+ Pass location to pedwarn.
+
2008-09-02 Adam Nemet <anemet@caviumnetworks.com>
* sel-sched.c (sel_hard_regno_rename_ok): Mark arguments unused.
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 2246526..e9f3fc7 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -2061,7 +2061,7 @@ build_array_ref (tree array, tree index, location_t loc)
if (TREE_CODE (TREE_TYPE (index)) != ARRAY_TYPE
&& TREE_CODE (TREE_TYPE (index)) != POINTER_TYPE)
{
- error ("subscripted value is neither array nor pointer");
+ error_at (loc, "subscripted value is neither array nor pointer");
return error_mark_node;
}
temp = array;
@@ -2072,13 +2072,13 @@ build_array_ref (tree array, tree index, location_t loc)
if (!INTEGRAL_TYPE_P (TREE_TYPE (index)))
{
- error ("array subscript is not an integer");
+ error_at (loc, "array subscript is not an integer");
return error_mark_node;
}
if (TREE_CODE (TREE_TYPE (TREE_TYPE (array))) == FUNCTION_TYPE)
{
- error ("subscripted value is pointer to function");
+ error_at (loc, "subscripted value is pointer to function");
return error_mark_node;
}
@@ -2125,10 +2125,10 @@ build_array_ref (tree array, tree index, location_t loc)
while (TREE_CODE (foo) == COMPONENT_REF)
foo = TREE_OPERAND (foo, 0);
if (TREE_CODE (foo) == VAR_DECL && C_DECL_REGISTER (foo))
- pedwarn (input_location, OPT_pedantic,
+ pedwarn (loc, OPT_pedantic,
"ISO C forbids subscripting %<register%> array");
else if (!flag_isoc99 && !lvalue_p (foo))
- pedwarn (input_location, OPT_pedantic,
+ pedwarn (loc, OPT_pedantic,
"ISO C90 forbids subscripting non-lvalue array");
}
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 67f3f2b..c5ccb40 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2008-09-02 Aldy Hernandez <aldyh@redhat.com>
+
+ * typeck.c (build_array_ref): Use new location argument.
+ * class.c (build_vtbl_ref_1): Pass location to build_array_ref.
+ * call.c (build_new_op): Same.
+ * decl2.c (grok_array_decl): Same.
+ * cp-tree.h (build_array_ref): Add location argument to prototype.
+
2008-09-01 Aldy Hernandez <aldyh@redhat.com>
* typeck.c (build_x_indirect_ref): Add location argument.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 6a6c2c2..571f36f 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4214,7 +4214,7 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3,
return cp_build_unary_op (code, arg1, candidates != 0, complain);
case ARRAY_REF:
- return build_array_ref (arg1, arg2);
+ return build_array_ref (arg1, arg2, input_location);
case COND_EXPR:
return build_conditional_expr (arg1, arg2, arg3, complain);
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 5f7d4a2..4f69c7e 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -627,7 +627,7 @@ build_vtbl_ref_1 (tree instance, tree idx)
assemble_external (vtbl);
- aref = build_array_ref (vtbl, idx);
+ aref = build_array_ref (vtbl, idx, input_location);
TREE_CONSTANT (aref) |= TREE_CONSTANT (vtbl) && TREE_CONSTANT (idx);
return aref;
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index a01d981..09b3b2f 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4911,7 +4911,7 @@ extern tree build_x_indirect_ref (tree, const char *,
tsubst_flags_t);
extern tree cp_build_indirect_ref (tree, const char *,
tsubst_flags_t);
-extern tree build_array_ref (tree, tree);
+extern tree build_array_ref (tree, tree, location_t);
extern tree get_member_function_from_ptrfunc (tree *, tree);
extern tree cp_build_function_call (tree, tree, tsubst_flags_t);
extern tree build_x_binary_op (enum tree_code, tree,
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 677597e..0e56c07 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -354,7 +354,7 @@ grok_array_decl (tree array_expr, tree index_exp)
if (array_expr == error_mark_node || index_exp == error_mark_node)
error ("ambiguous conversion for array subscript");
- expr = build_array_ref (array_expr, index_exp);
+ expr = build_array_ref (array_expr, index_exp, input_location);
}
if (processing_template_decl && expr != error_mark_node)
return build_min_non_dep (ARRAY_REF, expr, orig_array_expr, orig_index_exp,
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index d60ddbd..9de51c5 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -2506,14 +2506,18 @@ cp_build_indirect_ref (tree ptr, const char *errorstring,
If INDEX is of some user-defined type, it must be converted to
integer type. Otherwise, to make a compatible PLUS_EXPR, it
- will inherit the type of the array, which will be some pointer type. */
+ will inherit the type of the array, which will be some pointer type.
+
+ LOC is the location to use in building the array reference. */
tree
-build_array_ref (tree array, tree idx)
+build_array_ref (tree array, tree idx, location_t loc)
{
+ tree ret;
+
if (idx == 0)
{
- error ("subscript missing in array reference");
+ error_at (loc, "subscript missing in array reference");
return error_mark_node;
}
@@ -2527,17 +2531,21 @@ build_array_ref (tree array, tree idx)
{
case COMPOUND_EXPR:
{
- tree value = build_array_ref (TREE_OPERAND (array, 1), idx);
- return build2 (COMPOUND_EXPR, TREE_TYPE (value),
- TREE_OPERAND (array, 0), value);
+ tree value = build_array_ref (TREE_OPERAND (array, 1), idx, loc);
+ ret = build2 (COMPOUND_EXPR, TREE_TYPE (value),
+ TREE_OPERAND (array, 0), value);
+ SET_EXPR_LOCATION (ret, loc);
+ return ret;
}
case COND_EXPR:
- return build_conditional_expr
- (TREE_OPERAND (array, 0),
- build_array_ref (TREE_OPERAND (array, 1), idx),
- build_array_ref (TREE_OPERAND (array, 2), idx),
- tf_warning_or_error);
+ ret = build_conditional_expr
+ (TREE_OPERAND (array, 0),
+ build_array_ref (TREE_OPERAND (array, 1), idx, loc),
+ build_array_ref (TREE_OPERAND (array, 2), idx, loc),
+ tf_warning_or_error);
+ SET_EXPR_LOCATION (ret, loc);
+ return ret;
default:
break;
@@ -2551,7 +2559,7 @@ build_array_ref (tree array, tree idx)
if (!INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (idx)))
{
- error ("array subscript is not an integer");
+ error_at (loc, "array subscript is not an integer");
return error_mark_node;
}
@@ -2588,7 +2596,8 @@ build_array_ref (tree array, tree idx)
}
if (!lvalue_p (array))
- pedwarn (input_location, OPT_pedantic, "ISO C++ forbids subscripting non-lvalue array");
+ pedwarn (loc, OPT_pedantic,
+ "ISO C++ forbids subscripting non-lvalue array");
/* Note in C++ it is valid to subscript a `register' array, since
it is valid to take the address of something with that
@@ -2599,7 +2608,8 @@ build_array_ref (tree array, tree idx)
while (TREE_CODE (foo) == COMPONENT_REF)
foo = TREE_OPERAND (foo, 0);
if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
- warning (OPT_Wextra, "subscripting array declared %<register%>");
+ warning_at (loc, OPT_Wextra,
+ "subscripting array declared %<register%>");
}
type = TREE_TYPE (TREE_TYPE (array));
@@ -2612,7 +2622,9 @@ build_array_ref (tree array, tree idx)
|= (CP_TYPE_VOLATILE_P (type) | TREE_SIDE_EFFECTS (array));
TREE_THIS_VOLATILE (rval)
|= (CP_TYPE_VOLATILE_P (type) | TREE_THIS_VOLATILE (array));
- return require_complete_type (fold_if_not_in_template (rval));
+ ret = require_complete_type (fold_if_not_in_template (rval));
+ SET_EXPR_LOCATION (ret, loc);
+ return ret;
}
{
@@ -2632,21 +2644,23 @@ build_array_ref (tree array, tree idx)
if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
{
- error ("subscripted value is neither array nor pointer");
+ error_at (loc, "subscripted value is neither array nor pointer");
return error_mark_node;
}
if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
{
- error ("array subscript is not an integer");
+ error_at (loc, "array subscript is not an integer");
return error_mark_node;
}
warn_array_subscript_with_type_char (idx);
- return cp_build_indirect_ref (cp_build_binary_op (PLUS_EXPR, ar, ind,
- tf_warning_or_error),
- "array indexing",
- tf_warning_or_error);
+ ret = cp_build_indirect_ref (cp_build_binary_op (PLUS_EXPR, ar, ind,
+ tf_warning_or_error),
+ "array indexing",
+ tf_warning_or_error);
+ protected_set_expr_location (ret, loc);
+ return ret;
}
}
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 02423fa..f323f36 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -598,6 +598,19 @@ error (const char *gmsgid, ...)
va_end (ap);
}
+/* Same as ebove, but use location LOC instead of input_location. */
+void
+error_at (location_t loc, const char *gmsgid, ...)
+{
+ diagnostic_info diagnostic;
+ va_list ap;
+
+ va_start (ap, gmsgid);
+ diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_ERROR);
+ report_diagnostic (&diagnostic);
+ va_end (ap);
+}
+
/* "Sorry, not implemented." Use for a language feature which is
required by the relevant specification but not implemented by GCC.
An object file will not be produced. */
diff --git a/gcc/toplev.h b/gcc/toplev.h
index 5555bf1..552ed33 100644
--- a/gcc/toplev.h
+++ b/gcc/toplev.h
@@ -61,6 +61,7 @@ extern bool warning (int, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
extern bool warning_at (location_t, int, const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
extern void error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
+extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
extern void fatal_error (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2)
ATTRIBUTE_NORETURN;
/* Pass one of the OPT_W* from options.h as the second parameter. */