[gcc/devel/omp/gcc-9] Backport r272993
Tobias Burnus
burnus@gcc.gnu.org
Thu Mar 5 14:06:00 GMT 2020
https://gcc.gnu.org/g:b098c7983c12e17ba872d2241173c186a3c6f4e9
commit b098c7983c12e17ba872d2241173c186a3c6f4e9
Author: Martin Liska <mliska@suse.cz>
Date: Thu Jul 4 11:03:56 2019 +0200
Backport r272993
2019-07-04 Martin Liska <mliska@suse.cz>
Backport from mainline
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-04 Martin Liska <mliska@suse.cz>
Backport from mainline
2019-07-03 Martin Liska <mliska@suse.cz>
PR tree-optimization/90892
* gcc.dg/pr90892.c: New test.
From-SVN: r273074
Diff:
---
gcc/ChangeLog | 9 +++++++++
gcc/builtins.c | 17 ++++++++++++++---
gcc/testsuite/ChangeLog | 8 ++++++++
gcc/testsuite/gcc.dg/pr90892.c | 14 ++++++++++++++
4 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index ae63315..8201081 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -3,6 +3,15 @@
Backport from mainline
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-04 Martin Liska <mliska@suse.cz>
+
+ Backport from mainline
+ 2019-07-03 Martin Liska <mliska@suse.cz>
+
PR middle-end/90899
* multiple_target.c (create_dispatcher_calls): Add to comdat
group only if set for ifunc.
diff --git a/gcc/builtins.c b/gcc/builtins.c
index d37d73f..9bcb310 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -7124,8 +7124,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)
@@ -7140,7 +7151,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,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2a42f3c..07b2fa7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -3,6 +3,14 @@
Backport from mainline
2019-07-03 Martin Liska <mliska@suse.cz>
+ PR tree-optimization/90892
+ * gcc.dg/pr90892.c: New test.
+
+2019-07-04 Martin Liska <mliska@suse.cz>
+
+ Backport from mainline
+ 2019-07-03 Martin Liska <mliska@suse.cz>
+
PR middle-end/90899
* gcc.target/i386/pr90899.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr90892.c b/gcc/testsuite/gcc.dg/pr90892.c
new file mode 100644
index 0000000..e4b5310
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr90892.c
@@ -0,0 +1,14 @@
+/* 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;
+}
More information about the Gcc-cvs
mailing list