* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@109812
138bc75d-0d04-0410-961f-
82ee72b054a4
+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.
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);
+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".
name);
else
error ("size of array is not an integral constant-expression");
+ size = integer_one_node;
}
else if (pedantic)
{
+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.
--- /dev/null
+// 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);
+}
--- /dev/null
+/* 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);
+}