re PR c/32295 (An invalid c code causes an ICE in create_tmp_var, at gimplify.c:489)

PR c/32295
	* c-typeck.c (default_conversion): Call require_complete_type
	before perform_integral_promotions.
	(build_unary_op): Call require_complete_type except for ADDR_EXPR.
	(build_c_cast): Call require_complete_type except for casts to
	void types.
	(convert_for_assignment): Call require_complete_type.

testsuite:
	* gcc.dg/enum-incomplete-1.c: New test.

From-SVN: r128765
This commit is contained in:
Joseph Myers 2007-09-25 16:04:58 +01:00 committed by Joseph Myers
parent ea6e01682b
commit 808d6eaa01
4 changed files with 124 additions and 4 deletions

View File

@ -1,3 +1,13 @@
2007-09-25 Joseph Myers <joseph@codesourcery.com>
PR c/32295
* c-typeck.c (default_conversion): Call require_complete_type
before perform_integral_promotions.
(build_unary_op): Call require_complete_type except for ADDR_EXPR.
(build_c_cast): Call require_complete_type except for casts to
void types.
(convert_for_assignment): Call require_complete_type.
2007-09-25 Revital Eres <eres@il.ibm.com>
* config/spu/spu.md: Fix doloop pattern.

View File

@ -1770,14 +1770,19 @@ default_conversion (tree exp)
if (TREE_NO_WARNING (orig_exp))
TREE_NO_WARNING (exp) = 1;
if (INTEGRAL_TYPE_P (type))
return perform_integral_promotions (exp);
if (code == VOID_TYPE)
{
error ("void value not ignored as it ought to be");
return error_mark_node;
}
exp = require_complete_type (exp);
if (exp == error_mark_node)
return error_mark_node;
if (INTEGRAL_TYPE_P (type))
return perform_integral_promotions (exp);
return exp;
}
@ -2871,11 +2876,15 @@ build_unary_op (enum tree_code code, tree xarg, int flag)
/* No default_conversion here. It causes trouble for ADDR_EXPR. */
tree arg = xarg;
tree argtype = 0;
enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
enum tree_code typecode;
tree val;
int noconvert = flag;
const char *invalid_op_diag;
if (code != ADDR_EXPR)
arg = require_complete_type (arg);
typecode = TREE_CODE (TREE_TYPE (arg));
if (typecode == ERROR_MARK)
return error_mark_node;
if (typecode == ENUMERAL_TYPE || typecode == BOOLEAN_TYPE)
@ -3589,6 +3598,13 @@ build_c_cast (tree type, tree expr)
return error_mark_node;
}
if (!VOID_TYPE_P (type))
{
value = require_complete_type (value);
if (value == error_mark_node)
return error_mark_node;
}
if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value)))
{
if (pedantic)
@ -3998,6 +4014,9 @@ convert_for_assignment (tree type, tree rhs, enum impl_conv errtype,
error ("void value not ignored as it ought to be");
return error_mark_node;
}
rhs = require_complete_type (rhs);
if (rhs == error_mark_node)
return error_mark_node;
/* A type converts to a reference to it.
This code doesn't fully support references, it's just for the
special case of va_start and va_copy. */

View File

@ -1,3 +1,8 @@
2007-09-25 Joseph Myers <joseph@codesourcery.com>
PR c/32295
* gcc.dg/enum-incomplete-1.c: New test.
2007-09-25 Bernd Schmidt <bernd.schmidt@analog.com>
* gcc.c-torture/compile/20070919-1.c: New test.

View File

@ -0,0 +1,86 @@
/* Test for uses of incomplete enum variables: should be allowed just
when incomplete structs are allowed. PR 32295. */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-options "" } */
extern enum e ve;
extern struct s vs;
void *p;
int
f0 (int i)
{
ve; /* { dg-error "incomplete" } */
vs; /* { dg-error "incomplete" } */
(void) ve;
(void) vs;
(void) (i ? ve : ve); /* { dg-error "incomplete" } */
(void) (i ? vs : vs); /* { dg-error "incomplete" } */
(void) (ve = ve); /* { dg-error "incomplete" } */
(void) (vs = vs); /* { dg-error "incomplete" } */
(void) ve, (void) ve;
(void) vs, (void) vs;
p = &ve;
p = &vs;
(void) sizeof (ve); /* { dg-error "incomplete" } */
(void) sizeof (vs); /* { dg-error "incomplete" } */
typeof (ve) *pe;
typeof (vs) *ps;
/* ??? alignof should probably not be accepted here. */
(void) __alignof (ve);
(void) __alignof (vs);
(void) (ve + i); /* { dg-error "incomplete" } */
(void) (i * ve); /* { dg-error "incomplete" } */
(void) (i / ve); /* { dg-error "incomplete" } */
(void) (ve - i); /* { dg-error "incomplete" } */
(void) (ve << i); /* { dg-error "incomplete" } */
(void) (i >> ve); /* { dg-error "incomplete" } */
(void) (ve < i); /* { dg-error "incomplete" } */
(void) (ve <= i); /* { dg-error "incomplete" } */
(void) (i > ve); /* { dg-error "incomplete" } */
(void) (i >= ve); /* { dg-error "incomplete" } */
(void) (ve == i); /* { dg-error "incomplete" } */
(void) (i != ve); /* { dg-error "incomplete" } */
(void) (ve & i); /* { dg-error "incomplete" } */
(void) (ve ^ i); /* { dg-error "incomplete" } */
(void) (i | ve); /* { dg-error "incomplete" } */
(void) (i && ve); /* { dg-error "incomplete" } */
(void) (ve || i); /* { dg-error "incomplete" } */
(void) -ve; /* { dg-error "incomplete" } */
(void) +ve; /* { dg-error "incomplete" } */
(void) ~ve; /* { dg-error "incomplete" } */
(void) !ve; /* { dg-error "incomplete" } */
(void) --ve; /* { dg-error "incomplete" } */
(void) ++ve; /* { dg-error "incomplete" } */
(void) ve--; /* { dg-error "incomplete" } */
(void) ve++; /* { dg-error "incomplete" } */
i = ve; /* { dg-error "incomplete" } */
i *= ve; /* { dg-error "incomplete" } */
i /= ve; /* { dg-error "incomplete" } */
i %= ve; /* { dg-error "incomplete" } */
i += ve; /* { dg-error "incomplete" } */
i -= ve; /* { dg-error "incomplete" } */
i <<= ve; /* { dg-error "incomplete" } */
i >>= ve; /* { dg-error "incomplete" } */
i &= ve; /* { dg-error "incomplete" } */
i ^= ve; /* { dg-error "incomplete" } */
i |= ve; /* { dg-error "incomplete" } */
(void) (ve ? 1 : 1); /* { dg-error "incomplete" } */
(void) (int) ve; /* { dg-error "incomplete" } */
f0 (ve); /* { dg-error "incomplete" } */
if (ve) /* { dg-error "incomplete" } */
;
do
;
while (ve); /* { dg-error "incomplete" } */
while (ve) /* { dg-error "incomplete" } */
;
_Bool b = ve; /* { dg-error "incomplete" } */
float f = ve; /* { dg-error "incomplete" } */
switch (ve) /* { dg-error "incomplete" } */
;
for (; ve;) /* { dg-error "incomplete" } */
;
return ve; /* { dg-error "incomplete" } */
}