On Wed, 2020-01-15 at 13:18 +0000, Martin Sebor wrote:
> The strcmp optimization newly introduced in GCC 10 relies on
> the size of the smallest referenced array object to determine
> whether the function can return zero.  When the size of
> the object is smaller than the length of the other string
> argument the optimization folds the equality to false.
> 
> The bug report has identified a couple of problems here:
> 1) when the access to the array object is via a pointer to
> a (possibly indirect) member of a union, in GIMPLE the pointer
> may actually point to a different member than the one in
> the original source code.  Thus the size of the array may
> appear to be smaller than in the source code which can then
> result in the optimization being invalid.
> 2) when the pointer in the access may point to two or more
> arrays of different size (i.e., it's the result of a PHI),
> assuming it points to the smallest of them can also lead
> to an incorrect result when the optimization is applied.
> 
> The attached patch adjusts the optimization to 1) avoid making
> any assumptions about the sizes of objects accessed via union
> types, and b) use the size of the largest object in PHI nodes.
> 
> Tested on x86_64-linux.
> 
> Martin
> PR tree-optimization/92765 - wrong code for strcmp of a union member
> 
> gcc/testsuite/ChangeLog:
> 
>       PR tree-optimization/92765
>       * gcc.dg/strlenopt-92.c: New test.
> 
> gcc/ChangeLog:
> 
>       PR tree-optimization/92765
>       * tree-ssa-strlen.c (component_ref_via_union_p): New function.
>       (determine_min_objsize): Call it.  Use the maximum object size
>       for PHI arguments.
OK
jeff

Reply via email to