This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Patch to clean up uses of default_function_array_conversion


On Thu, 16 Jun 2005, Richard Guenther wrote:

> > Ok for mainline?
> 
> Andrew kindly pointed out I posted an empty pach file.  Fixed (hopefully).

There are problems with the change to how build_unary_op sets 
"TREE_INVARIANT (val) = TREE_CONSTANT (val) = 1;".  For a compound 
literal, this may be correct (but see second test below).  For an 
ARRAY_REF of one, it is only correct if the array index is constant, but 
in such a case it is also correct for any number of nested ARRAY_REFs, not 
just one.

My recommendation for this issue: add a langhook which 
recompute_tree_invarant_for_addr_expr calls after going down through 
components; for C this will go from the COMPOUND_LITERAL_EXPR to the decl 
within and should be accompanied by removing this special case code in 
build_unary_op.  This may stop the address being TREE_CONSTANT inside a 
function, but this is good.  Here are two testcases.  The first ICEs with 
your patch but not without it.  The second ICEs with and without; I've 
filed bug 22098 for it as it's a regression in 4.0 as well and may provide 
the case for backporting the langhook patch to 4.0.  Both should go in 
gcc.c-torture/execute, the first with the version of this patch which 
avoids the ICE and the second with whatever patch fixes that ICE 
(hopefully that adding a langhook).

First test:

extern void abort (void);
extern void exit (int);
typedef __SIZE_TYPE__ size_t;
int
main (void)
{
  int a = 0;
  int *p;
  size_t b;
  b = (size_t)(p = &(int []){0, 1, 2}[++a]);
  if (a != 1 || *p != 1 || *(int *)b != 1)
    abort ();
  exit (0);
}

Second test:

extern void abort (void);
extern void exit (int);
typedef __SIZE_TYPE__ size_t;
int
main (void)
{
  int a = 0;
  int *p;
  size_t b;
  b = (size_t)(p = &(int []){0, 1, 2}[1]);
  if (*p != 1 || *(int *)b != 1)
    abort ();
  exit (0);
}

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]