Commit 12a149a0 by Eric Botcazou Committed by Eric Botcazou

re PR middle-end/44100 (ICE compiling g++.dg/init/struct2.C on Tru64 UNIX V5.1B)

	PR middle-end/44100
	* typeck.c (cp_build_unary_op): Fold offsetof-like computations.

From-SVN: r159800
parent feb4c293
2010-05-24 Eric Botcazou <ebotcazou@adacore.com>
PR middle-end/44100
* typeck.c (cp_build_unary_op): Fold offsetof-like computations.
2010-05-24 Joseph Myers <joseph@codesourcery.com> 2010-05-24 Joseph Myers <joseph@codesourcery.com>
* error.c (cp_diagnostic_starter): Update call to * error.c (cp_diagnostic_starter): Update call to
......
...@@ -5024,6 +5024,20 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert, ...@@ -5024,6 +5024,20 @@ cp_build_unary_op (enum tree_code code, tree xarg, int noconvert,
return arg; return arg;
} }
/* ??? Cope with user tricks that amount to offsetof. */
if (TREE_CODE (argtype) != FUNCTION_TYPE
&& TREE_CODE (argtype) != METHOD_TYPE
&& argtype != unknown_type_node
&& (val = get_base_address (arg))
&& TREE_CODE (val) == INDIRECT_REF
&& TREE_CONSTANT (TREE_OPERAND (val, 0)))
{
tree type = build_pointer_type (argtype);
tree op0 = fold_convert (type, TREE_OPERAND (val, 0));
tree op1 = fold_convert (sizetype, fold_offsetof (arg, val));
return fold_build2 (POINTER_PLUS_EXPR, type, op0, op1);
}
/* Uninstantiated types are all functions. Taking the /* Uninstantiated types are all functions. Taking the
address of a function is a no-op, so just return the address of a function is a no-op, so just return the
argument. */ argument. */
......
2010-05-24 Eric Botcazou <ebotcazou@adacore.com> 2010-05-24 Eric Botcazou <ebotcazou@adacore.com>
* g++.dg/parse/array-size2.C: Remove dg-error directives.
2010-05-24 Eric Botcazou <ebotcazou@adacore.com>
PR ada/38394 PR ada/38394
* gnat.dg/array13.ad[sb]: New test. * gnat.dg/array13.ad[sb]: New test.
......
// PR c/25682 // PR c/25682
// { dg-do compile } // { dg-do compile }
// Test whether we don't ICE on invalid array sizes. // Test whether we don't ICE on questionable constructs where offsetof
// should have been used instead.
struct S struct S
{ {
...@@ -13,7 +14,7 @@ extern void bar (char *, char *); ...@@ -13,7 +14,7 @@ extern void bar (char *, char *);
void void
foo (void) foo (void)
{ {
char g[(char *) &((struct S *) 0)->b - (char *) 0]; // { dg-error "not an integral constant-expression" } char g[(char *) &((struct S *) 0)->b - (char *) 0];
char h[(__SIZE_TYPE__) &((struct S *) 8)->b]; // { dg-error "not an integral constant-expression" } char h[(__SIZE_TYPE__) &((struct S *) 8)->b];
bar (g, h); 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