[PATCH] Fix ICU miscompilation due to tree-ssa-strlen.c bug (PR tree-optimization/88693)

Jeff Law law@redhat.com
Fri Jan 11 18:29:00 GMT 2019


On 1/4/19 3:54 PM, Jakub Jelinek wrote:
> Hi!
> 
> The following patch fixes ICU miscompilation, where an initial part of a
> buffer is initializer from non-zero terminated string literal (in ICU
> actually from an array of non-zero chars that the FE newly turns into
> non-zero terminated string literal), but the code recently added to
> tree-ssa-strlen.c doesn't consider the possibility of string literals that
> aren't zero terminated.
> 
> STRING_CSTs actually are always zero terminated, but if TREE_STRING_LENGTH
> doesn't include the terminating character, it is just bytes.
> 
> Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
> 
> I was considering using strnlen, but if all STRING_CSTs are actually zero
> terminated, it will mean it reads are most one further byte and on many
> targets strlen is more optimized than strnlen.
> 
> 2019-01-04  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/88693
> 	* tree-ssa-strlen.c (get_min_string_length): Don't set *full_string_p
> 	for STRING_CSTs that don't contain any NUL characters in the first
> 	TREE_STRING_LENGTH bytes.
> 
> 	* gcc.c-torture/execute/pr88693.c: New test.
OK
jeff



More information about the Gcc-patches mailing list