aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2008-11-15 10:53:02 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2008-11-15 10:53:02 +0100
commitb70cef5d743a294b00b863f8caf80342f33f8100 (patch)
tree1e5e94a256aac8b6bf173d2f80f06cb0c584e226 /gcc
parent91ddf5a1e710ef71f8f4e0f4d84dc852d15eea89 (diff)
downloadgcc-b70cef5d743a294b00b863f8caf80342f33f8100.zip
gcc-b70cef5d743a294b00b863f8caf80342f33f8100.tar.gz
gcc-b70cef5d743a294b00b863f8caf80342f33f8100.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-typeck.c13
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c8
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/other/increment1.C18
-rw-r--r--gcc/testsuite/gcc.dg/pr37561.c23
7 files changed, 66 insertions, 14 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 34a5dc7..4c8b9a1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+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>
* ira-int.h (struct ira_loop_tree_node): Improve comments for
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index b322db4..c751b4f 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -3080,9 +3080,7 @@ build_unary_op (location_t location,
{
tree inc;
- tree result_type = TREE_TYPE (arg);
- arg = get_unwidened (arg, 0);
argtype = TREE_TYPE (arg);
/* Compute the increment. */
@@ -3091,7 +3089,7 @@ build_unary_op (location_t location,
{
/* If pointer target is an undefined struct,
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)
error_at (location,
@@ -3100,8 +3098,8 @@ build_unary_op (location_t location,
error_at (location,
"decrement of pointer to unknown structure");
}
- else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
- || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
+ else if (TREE_CODE (TREE_TYPE (argtype)) == FUNCTION_TYPE
+ || TREE_CODE (TREE_TYPE (argtype)) == VOID_TYPE)
{
if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith,
@@ -3111,10 +3109,10 @@ build_unary_op (location_t location,
"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);
}
- 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
-- to ++, and change inc from 1 to -1, because
@@ -3161,7 +3159,6 @@ build_unary_op (location_t location,
else
val = build2 (code, TREE_TYPE (arg), arg, inc);
TREE_SIDE_EFFECTS (val) = 1;
- val = convert (result_type, val);
if (TREE_CODE (val) != code)
TREE_NO_WARNING (val) = 1;
ret = val;
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a4dbc86..e6fbdfb 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+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>
PR c++/38030
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 321f76b..7595b58 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -4348,12 +4348,8 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
{
tree inc;
- tree declared_type;
- tree result_type = TREE_TYPE (arg);
+ tree declared_type = unlowered_expr_type (arg);
- declared_type = unlowered_expr_type (arg);
-
- arg = get_unwidened (arg, 0);
argtype = TREE_TYPE (arg);
/* 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,
val = build2 (code, TREE_TYPE (arg), arg, inc);
TREE_SIDE_EFFECTS (val) = 1;
- return cp_convert (result_type, val);
+ return val;
}
case ADDR_EXPR:
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 51bb931..b64bf63 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+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>
PR fortran/37988
diff --git a/gcc/testsuite/g++.dg/other/increment1.C b/gcc/testsuite/g++.dg/other/increment1.C
new file mode 100644
index 0000000..c36e573
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/increment1.C
@@ -0,0 +1,18 @@
+// 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" }
+}
diff --git a/gcc/testsuite/gcc.dg/pr37561.c b/gcc/testsuite/gcc.dg/pr37561.c
new file mode 100644
index 0000000..82eca96
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr37561.c
@@ -0,0 +1,23 @@
+/* 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 } */