Commit d7705934 by Daniel Berlin Committed by Daniel Berlin

c-typeck.c (readonly_error): Improve error for assignment.

2007-08-09  Daniel Berlin  <dberlin@dberlin.org>

	* c-typeck.c (readonly_error): Improve error for assignment.
	
	* c-pretty-print.c (pp_c_additive_expression): Handle pointer-plus
	expression. 
	(pp_c_expression): Ditto.
2007-08-09  Daniel Berlin  <dberlin@dberlin.org>

	* typeck2.c (readonly_error): Handle general expressions.
	* error.c (dump_expr): Handle POINTER_PLUS_EXPR

From-SVN: r127320
parent d6bc05d4
2007-08-09 Daniel Berlin <dberlin@dberlin.org>
* c-typeck.c (readonly_error): Improve error for assignment.
* c-pretty-print.c (pp_c_additive_expression): Handle pointer-plus
expression.
(pp_c_expression): Ditto.
2007-08-09 Simon Baldwin <simonb@google.com> 2007-08-09 Simon Baldwin <simonb@google.com>
* simplify-rtx.c (simplify_binary_operation_1): Removed erroneous * simplify-rtx.c (simplify_binary_operation_1): Removed erroneous
......
...@@ -1597,11 +1597,12 @@ pp_c_additive_expression (c_pretty_printer *pp, tree e) ...@@ -1597,11 +1597,12 @@ pp_c_additive_expression (c_pretty_printer *pp, tree e)
enum tree_code code = TREE_CODE (e); enum tree_code code = TREE_CODE (e);
switch (code) switch (code)
{ {
case POINTER_PLUS_EXPR:
case PLUS_EXPR: case PLUS_EXPR:
case MINUS_EXPR: case MINUS_EXPR:
pp_c_additive_expression (pp, TREE_OPERAND (e, 0)); pp_c_additive_expression (pp, TREE_OPERAND (e, 0));
pp_c_whitespace (pp); pp_c_whitespace (pp);
if (code == PLUS_EXPR) if (code == PLUS_EXPR || code == POINTER_PLUS_EXPR)
pp_plus (pp); pp_plus (pp);
else else
pp_minus (pp); pp_minus (pp);
...@@ -1979,6 +1980,7 @@ pp_c_expression (c_pretty_printer *pp, tree e) ...@@ -1979,6 +1980,7 @@ pp_c_expression (c_pretty_printer *pp, tree e)
pp_conditional_expression (pp, e); pp_conditional_expression (pp, e);
break; break;
case POINTER_PLUS_EXPR:
case PLUS_EXPR: case PLUS_EXPR:
case MINUS_EXPR: case MINUS_EXPR:
pp_c_additive_expression (pp, e); pp_c_additive_expression (pp, e);
......
...@@ -3152,10 +3152,11 @@ readonly_error (tree arg, enum lvalue_use use) ...@@ -3152,10 +3152,11 @@ readonly_error (tree arg, enum lvalue_use use)
G_("read-only variable %qD used as %<asm%> output")), G_("read-only variable %qD used as %<asm%> output")),
arg); arg);
else else
error (READONLY_MSG (G_("assignment of read-only location"), error (READONLY_MSG (G_("assignment of read-only location %qE"),
G_("increment of read-only location"), G_("increment of read-only location %qE"),
G_("decrement of read-only location"), G_("decrement of read-only location %qE"),
G_("read-only location used as %<asm%> output"))); G_("read-only location %qE used as %<asm%> output")),
arg);
} }
......
2007-08-09 Daniel Berlin <dberlin@dberlin.org>
* typeck2.c (readonly_error): Handle general expressions.
* error.c (dump_expr): Handle POINTER_PLUS_EXPR
2007-08-06 Dan Hipschman <dsh@google.com> 2007-08-06 Dan Hipschman <dsh@google.com>
* method.c (use_thunk): Use DECL_NAME instead of DECL_RTL to * method.c (use_thunk): Use DECL_NAME instead of DECL_RTL to
......
...@@ -1612,6 +1612,10 @@ dump_expr (tree t, int flags) ...@@ -1612,6 +1612,10 @@ dump_expr (tree t, int flags)
dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS); dump_expr (TREE_OPERAND (t, 1), flags | TFF_EXPR_IN_PARENS);
break; break;
case POINTER_PLUS_EXPR:
dump_binary_op ("+", t, flags);
break;
case INIT_EXPR: case INIT_EXPR:
case MODIFY_EXPR: case MODIFY_EXPR:
case PLUS_EXPR: case PLUS_EXPR:
......
...@@ -104,7 +104,7 @@ readonly_error (tree arg, const char* string) ...@@ -104,7 +104,7 @@ readonly_error (tree arg, const char* string)
else if (TREE_CODE (arg) == FUNCTION_DECL) else if (TREE_CODE (arg) == FUNCTION_DECL)
error ("%s of function %qD", string, arg); error ("%s of function %qD", string, arg);
else else
error ("%s of read-only location", string); error ("%s of read-only location %qE", string, arg);
} }
......
/* { dg-do compile } */
/* { dg-options "-O" } */
int func()
{
const int *arr;
const int arr2[5];
arr[0] = 1; /* { dg-error "assignment of read-only location" "*(arr)" } */
arr[1] = 1; /* { dg-error "assignment of read-only location" "*(arr + 4u)" } */
arr2[0] = 1; /* { dg-error "assignment of read-only location" "arr2\[0\]" } */
arr2[1] = 1; /* { dg-error "assignment of read-only location" "arr2\[1\]" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment