diff options
author | Martin Liska <mliska@suse.cz> | 2019-07-03 10:32:25 +0200 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2019-07-03 08:32:25 +0000 |
commit | 6aa2e42cb4be16ee0937ba872b297b11d8f0a18b (patch) | |
tree | f210a49163af5fc3a3d03f5a1cff2bf92bf3d423 /gcc/builtins.c | |
parent | d04295d24364b0138c354e249a4bb14e0a6ffb96 (diff) | |
download | gcc-6aa2e42cb4be16ee0937ba872b297b11d8f0a18b.zip gcc-6aa2e42cb4be16ee0937ba872b297b11d8f0a18b.tar.gz gcc-6aa2e42cb4be16ee0937ba872b297b11d8f0a18b.tar.bz2 |
Handle '\0' in strcmp in RTL expansion (PR tree-optimization/90892).
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 tree-optimization/90892
* gcc.dg/pr90892.c: New test.
From-SVN: r272993
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 2b8914f..e2ba356 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -7118,8 +7118,19 @@ inline_expand_builtin_string_cmp (tree exp, rtx target) 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) @@ -7134,7 +7145,7 @@ inline_expand_builtin_string_cmp (tree exp, rtx target) 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, |