[Bug c/53424] dynamic array expressions get wrong sizeof() if pointers to const are involved and the pointers are changed (const is misapplied to the whole expression)

2013-12-03 Thread jsm28 at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53424

--- Comment #4 from Joseph S. Myers  ---
Created attachment 31371
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31371&action=edit
Patch to tree_invariant_p_1

I tried restricting tree_invariant_p_1 as in the attached patch, but while this
fixes the bug it causes regressions

FAIL: gnat.dg/vect1.adb scan-tree-dump-times vect "vectorized 1 loops" 15

and similar for vect2.adb through vect6.adb.  It seems Ada vectorization is
somehow relying on certain trees being treated as invariant when similar C
trees aren't invariant; I'd hoped that it wouldn't matter much because the
GIMPLE optimizers should eliminate any unnecessary temporaries.


[Bug c/53424] dynamic array expressions get wrong sizeof() if pointers to const are involved and the pointers are changed (const is misapplied to the whole expression)

2012-05-26 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53424

--- Comment #3 from Andrew Pinski  2012-05-26 
23:47:56 UTC ---
(gdb) p debug_tree(t)
 
unit size 
align 32 symtab 0 alias set -1 canonical type 0x76e6e000 precision
32 min  max 
pointer_to_this >
readonly
arg 0 
unsigned DI
size 
unit size 
align 64 symtab 0 alias set -1 canonical type 0x76e6e0a8>
used unsigned DI file t1.c line 6 col 13 size  unit size 
align 64 context  initial
>
t1.c:7:11>

The indirect reference is marked as readonly.
2663static bool
2664tree_invariant_p_1 (tree t)
2665{
2666  tree op;
2667
2668  if (TREE_CONSTANT (t)
2669  || (TREE_READONLY (t) && !TREE_SIDE_EFFECTS (t)))
2670return true;

Is where the issue is.


[Bug c/53424] dynamic array expressions get wrong sizeof() if pointers to const are involved and the pointers are changed (const is misapplied to the whole expression)

2012-05-20 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53424

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||wrong-code
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2012-05-20
 Ever Confirmed|0   |1
   Severity|major   |normal

--- Comment #2 from Andrew Pinski  2012-05-20 
08:17:57 UTC ---
There is no SAVE_EXPR wrapped around the *x for some reason which is causing
the issue.

Add the following to make a runtime test:
void usebuf(char *) __attribute__((noinline,noclone));
void usebuf(char *a)
{
  asm ("");
}


int main(void)
{
  if (works () != broken ())
__builtin_abort ();
  nocrash ();
  crashes ();
  if (negativesizeof() != works ())
__builtin_abort ();
}


[Bug c/53424] dynamic array expressions get wrong sizeof() if pointers to const are involved and the pointers are changed (const is misapplied to the whole expression)

2012-05-19 Thread gccbug at shaggy dot cc
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53424

--- Comment #1 from Frank Barrus  2012-05-20 05:31:02 
UTC ---
Of particular attention, look at the example function "negativesizeof2".
It's not just the sizeof() function returning the incorrect size.  In this
case, the pointer change retroactively changed the size of a struct already
declared, and which a variable was instantiated from.  And it didn't just
change it for sizeof().  Pointer arithmetic is actually wrong, and the size is
negative.  So a step forward actually goes backwards!