+2019-07-03 Martin Liska <mliska@suse.cz>
+
+ PR tree-optimization/90892
+ * builtins.c (inline_expand_builtin_string_cmp): Handle '\0'
+ in string constants.
+
2019-07-03 Martin Liska <mliska@suse.cz>
PR middle-end/90899
return NULL_RTX;
/* For strncmp, if the length is not a const, not qualify. */
- if (is_ncmp && !tree_fits_uhwi_p (len3_tree))
- return NULL_RTX;
+ if (is_ncmp)
+ {
+ if (!tree_fits_uhwi_p (len3_tree))
+ return NULL_RTX;
+ else
+ len3 = tree_to_uhwi (len3_tree);
+ }
+
+ if (src_str1 != NULL)
+ len1 = strnlen (src_str1, len1) + 1;
+
+ if (src_str2 != NULL)
+ len2 = strnlen (src_str2, len2) + 1;
int const_str_n = 0;
if (!len1)
gcc_checking_assert (const_str_n > 0);
length = (const_str_n == 1) ? len1 : len2;
- if (is_ncmp && (len3 = tree_to_uhwi (len3_tree)) < length)
+ if (is_ncmp && len3 < length)
length = len3;
/* If the length of the comparision is larger than the threshold,
+2019-07-03 Martin Liska <mliska@suse.cz>
+
+ PR tree-optimization/90892
+ * gcc.dg/pr90892.c: New test.
+
2019-07-03 Martin Liska <mliska@suse.cz>
PR middle-end/90899
--- /dev/null
+/* PR tree-optimization/90892 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+const char *a = "A\0b";
+
+int
+main()
+{
+ if (__builtin_strncmp(a, "A\0", 2) != 0)
+ __builtin_abort ();
+
+ return 0;
+}