This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR 23402, ICE with zero sized structs
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: patch Patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 25 Aug 2005 14:29:38 +0930
- Subject: Re: [PATCH] Fix PR 23402, ICE with zero sized structs
- References: <78be4720ee0f2e300bb4de41dca18c53@physics.uc.edu>
On Tue, Aug 16, 2005 at 01:14:19PM -0400, Andrew Pinski wrote:
> * gimplify.c (zero_sized_type): New function.
> (gimplify_modify_expr_rhs): If we have a zero sized type,
> replace the statement with an empty statement.
This breaks gcc.c-torture/execute/va-arg-22.c on powerpc-linux.
typedef struct { char x[0]; } A0;
..
A0 a0;
..
a0 = __builtin_va_arg (ap, typeof (a0));
On powerpc-linux, structs are passed by reference, so even a zero-size
struct uses an arg register. Andrew's patch effectively deletes the
__builtin_va_arg invocation, thus ap doesn't increment over the zero
struct pointer.
At the gimplify_modify_expr_rhs call, we have
(gdb) p debug_tree (*from_p)
<va_arg_expr 0x4002dfe0
type <record_type 0x400d2d68 A0 sizes-gimplified type_0 BLK
size <integer_cst 0x4002d960 constant invariant 0>
unit size <integer_cst 0x4002d180 constant invariant 0>
align 8 symtab 0 alias set -1
fields <field_decl 0x40044930 x type <array_type 0x400d2d00>
BLK file /src/tmp/va-arg-22.i line 1 size <integer_cst 0x4002d960 0> unit size <integer_cst 0x4002d180 0>
align 8 offset_align 128 offset <integer_cst 0x4002d180 0> bit offset <integer_cst 0x4002d960 0> context <record_type 0x400d2c30>>>
side-effects
arg 0 <var_decl 0x40044a10 ap
type <array_type 0x400432d8 __builtin_va_list type <record_type 0x40043138 __va_list_tag>
sizes-gimplified BLK
size <integer_cst 0x4002db40 constant invariant 96>
unit size <integer_cst 0x4002db80 constant invariant 12>
align 32 symtab 0 alias set -1 domain <integer_type 0x400431a0>>
addressable used BLK file /src/tmp/va-arg-22.i line 6 size <integer_cst 0x4002db40 96> unit size <integer_cst 0x4002db80 12>
align 32 context <function_decl 0x400d4900 foo>
chain <var_decl 0x40044a80 i type <integer_type 0x40034410 int>
SI file /src/tmp/va-arg-22.i line 7
size <integer_cst 0x4002d4a0 constant invariant 32>
unit size <integer_cst 0x4002d160 constant invariant 4>
align 32 context <function_decl 0x400d4900 foo>>>>
The following cures the va-arg-22 breakage, but I suspect isn't right
because it leaves the PR23402 problem Andrew was trying to fix.
Index: gcc/gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimplify.c,v
retrieving revision 2.148
diff -u -p -r2.148 gimplify.c
--- gcc/gimplify.c 23 Aug 2005 07:28:11 -0000 2.148
+++ gcc/gimplify.c 25 Aug 2005 04:54:20 -0000
@@ -2966,7 +2966,7 @@ gimplify_modify_expr_rhs (tree *expr_p,
{
enum gimplify_status ret = GS_OK;
tree type = TREE_TYPE (*from_p);
- if (zero_sized_type (type))
+ if (!TREE_SIDE_EFFECTS (*from_p) && zero_sized_type (type))
{
*expr_p = NULL_TREE;
return GS_ALL_DONE;
--
Alan Modra
IBM OzLabs - Linux Technology Centre