aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2006-01-17 10:57:56 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2006-01-17 10:57:56 +0100
commit3aa2ddb8859364abdbe391467e91c0741a7fba3e (patch)
tree199ee3e668600a1058b2f24948647c8931113c50 /gcc
parent474eccc60315960b14fb0af4b7da9c6795ac4f0e (diff)
downloadgcc-3aa2ddb8859364abdbe391467e91c0741a7fba3e.zip
gcc-3aa2ddb8859364abdbe391467e91c0741a7fba3e.tar.gz
gcc-3aa2ddb8859364abdbe391467e91c0741a7fba3e.tar.bz2
re PR c/25682 (ICE when using old sytle offsetof (with non zero start) as array size)
PR c/25682 * c-typeck.c (build_unary_op): Fold offsetof-like expressions even when the pointer is not NULL. cp/ * decl.c (compute_array_index_type): After issuing not an integral constant-expression error, set size to 1 to avoid ICEs later on. testsuite/ * gcc.dg/pr25682.c: New test. * g++.dg/parse/array-size2.C: New test. From-SVN: r109812
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-typeck.c9
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/decl.c1
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/parse/array-size2.C19
-rw-r--r--gcc/testsuite/gcc.dg/pr25682.c27
7 files changed, 72 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 030333b..ca2c555 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-17 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/25682
+ * c-typeck.c (build_unary_op): Fold offsetof-like expressions
+ even when the pointer is not NULL.
+
2006-01-16 Ian Lance Taylor <ian@airs.com>
* common.opt (ftoplevel-reorder): New option.
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index bda8789..e442848 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -3003,8 +3003,13 @@ build_unary_op (enum tree_code code, tree xarg, int flag)
when we have proper support for integer constant expressions. */
val = get_base_address (arg);
if (val && TREE_CODE (val) == INDIRECT_REF
- && integer_zerop (TREE_OPERAND (val, 0)))
- return fold_convert (argtype, fold_offsetof (arg));
+ && TREE_CONSTANT (TREE_OPERAND (val, 0)))
+ {
+ tree op0 = fold_convert (argtype, fold_offsetof (arg)), op1;
+
+ op1 = fold_convert (argtype, TREE_OPERAND (val, 0));
+ return fold_build2 (PLUS_EXPR, argtype, op0, op1);
+ }
val = build1 (ADDR_EXPR, argtype, arg);
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3453893..77bb00b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-17 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/25682
+ * decl.c (compute_array_index_type): After issuing not an integral
+ constant-expression error, set size to 1 to avoid ICEs later on.
+
2006-01-16 Ian Lance Taylor <ian@airs.com>
* parser.c: Include "cgraph.h".
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index d28481b..48e985c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6343,6 +6343,7 @@ compute_array_index_type (tree name, tree size)
name);
else
error ("size of array is not an integral constant-expression");
+ size = integer_one_node;
}
else if (pedantic)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a69bdc3..89b1693 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-17 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/25682
+ * gcc.dg/pr25682.c: New test.
+ * g++.dg/parse/array-size2.C: New test.
+
2006-01-16 Ian Lance Taylor <ian@airs.com>
* consistency.vlad: Remove entire directory, 1652 files.
diff --git a/gcc/testsuite/g++.dg/parse/array-size2.C b/gcc/testsuite/g++.dg/parse/array-size2.C
new file mode 100644
index 0000000..22a57b2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/parse/array-size2.C
@@ -0,0 +1,19 @@
+// PR c/25682
+// { dg-do compile }
+// Test whether we don't ICE on invalid array sizes.
+
+struct S
+{
+ char a[4];
+ int b;
+};
+
+extern void bar (char *, char *);
+
+void
+foo (void)
+{
+ char g[(char *) &((struct S *) 0)->b - (char *) 0]; // { dg-error "not an integral constant-expression" }
+ char h[(__SIZE_TYPE__) &((struct S *) 8)->b]; // { dg-error "not an integral constant-expression" }
+ bar (g, h);
+}
diff --git a/gcc/testsuite/gcc.dg/pr25682.c b/gcc/testsuite/gcc.dg/pr25682.c
new file mode 100644
index 0000000..3a1d7c2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr25682.c
@@ -0,0 +1,27 @@
+/* PR c/25682 */
+/* { dg-do compile } */
+/* Test whether we don't ICE on questionable constructs where offsetof
+ should have been used instead. */
+
+struct S
+{
+ char a[4];
+ int b;
+};
+
+char c[(char *) &((struct S *) 0)->b - (char *) 0];
+char d[(__SIZE_TYPE__) &((struct S *) 8)->b];
+char e[sizeof (c) == __builtin_offsetof (struct S, b) ? 1 : -1];
+char f[sizeof (d) == __builtin_offsetof (struct S, b) + 8 ? 1 : -1];
+
+extern void bar (char *, char *);
+
+void
+foo (void)
+{
+ char g[(char *) &((struct S *) 0)->b - (char *) 0];
+ char h[(__SIZE_TYPE__) &((struct S *) 8)->b];
+ char i[sizeof (g) == __builtin_offsetof (struct S, b) ? 1 : -1];
+ char j[sizeof (h) == __builtin_offsetof (struct S, b) + 8 ? 1 : -1];
+ bar (g, h);
+}