Commit 3aa2ddb8 by Jakub Jelinek Committed by Jakub Jelinek

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
parent 474eccc6
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.
......
......@@ -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);
......
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".
......
......@@ -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)
{
......
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.
// 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);
}
/* 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);
}
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