Commit b70cef5d by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/37561 (Revision 140405 caused g++.old-deja/g++.mike/warn1.C)

	PR c++/37561
	* c-typeck.c (build_unary_op): Don't call get_unwidened.  Use
	argtype instead of result_type.

	* typeck.c (cp_build_unary_op): Don't call get_unwidened.  Use
	argtype instead of result_type.

	* gcc.dg/pr37561.c: New test.
	* g++.dg/other/increment1.C: New test.

From-SVN: r141881
parent 91ddf5a1
2008-11-15 Jakub Jelinek <jakub@redhat.com>
PR c++/37561
* c-typeck.c (build_unary_op): Don't call get_unwidened. Use
argtype instead of result_type.
2008-11-14 Adam Nemet <anemet@caviumnetworks.com> 2008-11-14 Adam Nemet <anemet@caviumnetworks.com>
* ira-int.h (struct ira_loop_tree_node): Improve comments for * ira-int.h (struct ira_loop_tree_node): Improve comments for
......
...@@ -3080,9 +3080,7 @@ build_unary_op (location_t location, ...@@ -3080,9 +3080,7 @@ build_unary_op (location_t location,
{ {
tree inc; tree inc;
tree result_type = TREE_TYPE (arg);
arg = get_unwidened (arg, 0);
argtype = TREE_TYPE (arg); argtype = TREE_TYPE (arg);
/* Compute the increment. */ /* Compute the increment. */
...@@ -3091,7 +3089,7 @@ build_unary_op (location_t location, ...@@ -3091,7 +3089,7 @@ build_unary_op (location_t location,
{ {
/* If pointer target is an undefined struct, /* If pointer target is an undefined struct,
we just cannot know how to do the arithmetic. */ we just cannot know how to do the arithmetic. */
if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (result_type))) if (!COMPLETE_OR_VOID_TYPE_P (TREE_TYPE (argtype)))
{ {
if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
error_at (location, error_at (location,
...@@ -3100,8 +3098,8 @@ build_unary_op (location_t location, ...@@ -3100,8 +3098,8 @@ build_unary_op (location_t location,
error_at (location, error_at (location,
"decrement of pointer to unknown structure"); "decrement of pointer to unknown structure");
} }
else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
|| TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE) || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE)
{ {
if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR) if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
...@@ -3111,10 +3109,10 @@ build_unary_op (location_t location, ...@@ -3111,10 +3109,10 @@ build_unary_op (location_t location,
"wrong type argument to decrement"); "wrong type argument to decrement");
} }
inc = c_size_in_bytes (TREE_TYPE (result_type)); inc = c_size_in_bytes (TREE_TYPE (argtype));
inc = fold_convert (sizetype, inc); inc = fold_convert (sizetype, inc);
} }
else if (FRACT_MODE_P (TYPE_MODE (result_type))) else if (FRACT_MODE_P (TYPE_MODE (argtype)))
{ {
/* For signed fract types, we invert ++ to -- or /* For signed fract types, we invert ++ to -- or
-- to ++, and change inc from 1 to -1, because -- to ++, and change inc from 1 to -1, because
...@@ -3161,7 +3159,6 @@ build_unary_op (location_t location, ...@@ -3161,7 +3159,6 @@ build_unary_op (location_t location,
else else
val = build2 (code, TREE_TYPE (arg), arg, inc); val = build2 (code, TREE_TYPE (arg), arg, inc);
TREE_SIDE_EFFECTS (val) = 1; TREE_SIDE_EFFECTS (val) = 1;
val = convert (result_type, val);
if (TREE_CODE (val) != code) if (TREE_CODE (val) != code)
TREE_NO_WARNING (val) = 1; TREE_NO_WARNING (val) = 1;
ret = val; ret = val;
......
2008-11-15 Jakub Jelinek <jakub@redhat.com>
PR c++/37561
* typeck.c (cp_build_unary_op): Don't call get_unwidened. Use
argtype instead of result_type.
2008-11-14 Jason Merrill <jason@redhat.com> 2008-11-14 Jason Merrill <jason@redhat.com>
PR c++/38030 PR c++/38030
......
...@@ -4348,12 +4348,8 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, ...@@ -4348,12 +4348,8 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
{ {
tree inc; tree inc;
tree declared_type; tree declared_type = unlowered_expr_type (arg);
tree result_type = TREE_TYPE (arg);
declared_type = unlowered_expr_type (arg);
arg = get_unwidened (arg, 0);
argtype = TREE_TYPE (arg); argtype = TREE_TYPE (arg);
/* ARM $5.2.5 last annotation says this should be forbidden. */ /* ARM $5.2.5 last annotation says this should be forbidden. */
...@@ -4427,7 +4423,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, ...@@ -4427,7 +4423,7 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
val = build2 (code, TREE_TYPE (arg), arg, inc); val = build2 (code, TREE_TYPE (arg), arg, inc);
TREE_SIDE_EFFECTS (val) = 1; TREE_SIDE_EFFECTS (val) = 1;
return cp_convert (result_type, val); return val;
} }
case ADDR_EXPR: case ADDR_EXPR:
......
2008-11-15 Jakub Jelinek <jakub@redhat.com>
PR c++/37561
* gcc.dg/pr37561.c: New test.
* g++.dg/other/increment1.C: New test.
2008-11-14 Jerry DeLisle <jvdelisle@gcc.gnu.org> 2008-11-14 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR fortran/37988 PR fortran/37988
......
// PR c++/37561
// { dg-do compile }
__PTRDIFF_TYPE__ p;
char q;
void
foo ()
{
((char *) p)++; // { dg-error "lvalue" }
((char *) q)++; // { dg-error "lvalue" }
((char *) p)--; // { dg-error "lvalue" }
((char *) q)--; // { dg-error "lvalue" }
++(char *) p; // { dg-error "lvalue" }
++(char *) q; // { dg-error "lvalue" }
--(char *) p; // { dg-error "lvalue" }
--(char *) q; // { dg-error "lvalue" }
}
/* PR c++/37561 */
/* { dg-do compile } */
__PTRDIFF_TYPE__ p;
char q;
void
foo ()
{
((char *) p)++; /* { dg-error "lvalue" } */
((char *) q)++; /* { dg-error "lvalue" } */
((char *) p)--; /* { dg-error "lvalue" } */
((char *) q)--; /* { dg-error "lvalue" } */
++(char *) p; /* { dg-error "lvalue" } */
++(char *) q; /* { dg-error "lvalue" } */
--(char *) p; /* { dg-error "lvalue" } */
--(char *) q; /* { dg-error "lvalue" } */
}
/* { dg-warning "cast to pointer from integer of different size" "" { target *-*-* } 11 } */
/* { dg-warning "cast to pointer from integer of different size" "" { target *-*-* } 13 } */
/* { dg-warning "cast to pointer from integer of different size" "" { target *-*-* } 15 } */
/* { dg-warning "cast to pointer from integer of different size" "" { target *-*-* } 17 } */
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