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]

[PATCH] Fix PR 29715, fold produces &a - 4


Hi,
  The problem here is that fold assumes that for ptr-- > a, fold assumes 
that the pointers will not overflow which is true but that is wrong as you 
can produce an extra overflow by doing this optimization if a was 
((ptr_type)-1).  This can also cause us to produce &a[-1] which is 
actually undefined in our IR.

This patch removes the check that the type is a pointer and for the 
testcase in the bug report (which was found in the testsuite already), we 
produce better code now on the tree level in that we just generate a 
return 0 if we change the second return to f();.  Also this fixes a 
regression on the ptr_plus_expr branch as we would try to generate a 
MINUS_EXPR with a Pointer type which is invalid on that branch.

OK? Bootstrapped and tested on i686-linux-gnu on the trunk with no 
regressions.


Thanks,
Andrew Pinski

ChangeLog:

        * fold-const.c (fold_comparison): For the
        POSTDECREMENT_EXPR/POSTINCREMENT_EXPR optimization, don't
        do it for Pointer types.

Attachment: fixpr29715.diff.txt
Description: Text document


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