[PATCH] Fix ICU miscompilation due to tree-ssa-strlen.c bug (PR tree-optimization/88693)
Bernd Edlinger
bernd.edlinger@hotmail.de
Sat Jan 5 12:20:00 GMT 2019
Hi,
co-incidentally my "Make strlen range computations more conservative" patch
contained a fix on the same spot, I just did not have a test case for it:
@@ -3184,7 +3146,10 @@ get_min_string_length (tree rhs, bool *f
&& TREE_READONLY (rhs))
rhs = DECL_INITIAL (rhs);
- if (rhs && TREE_CODE (rhs) == STRING_CST)
+ if (rhs && TREE_CODE (rhs) == STRING_CST
+ && tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (rhs)))) == 1
+ && TREE_STRING_LENGTH (rhs) > 0
+ && TREE_STRING_POINTER (rhs) [TREE_STRING_LENGTH (rhs) - 1] == '\0')
{
*full_string_p = true;
return strlen (TREE_STRING_POINTER (rhs));
additionally to your patch this tests the string is in fact a single-byte string.
since strlen returns garbage otherwise.
Bernd.
More information about the Gcc-patches
mailing list