From: Jakub Jelinek Date: Fri, 11 Jan 2019 19:04:32 +0000 (+0100) Subject: re PR tree-optimization/88693 (Wrong code since r263018) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e17fa93eca7611415368af47d6e4dd2796c8fd7b;p=gcc.git re PR tree-optimization/88693 (Wrong code since r263018) 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. From-SVN: r267852 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cab2430e1f9..bca96c04ac8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-01-11 Jakub Jelinek + + 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. + 2019-01-11 Alan Modra PR 88777 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6baaa8e4afc..3b1de48f990 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-11 Jakub Jelinek + + PR tree-optimization/88693 + * gcc.c-torture/execute/pr88693.c: New test. + 2019-01-11 Tamar Christina * gcc.target/aarch64/advsimd-intrinsics/vector-complex_f16.c: Require neon diff --git a/gcc/testsuite/gcc.c-torture/execute/pr88693.c b/gcc/testsuite/gcc.c-torture/execute/pr88693.c new file mode 100644 index 00000000000..7e78aea50f5 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr88693.c @@ -0,0 +1,54 @@ +/* PR tree-optimization/88693 */ + +__attribute__((noipa)) void +foo (char *p) +{ + if (__builtin_strlen (p) != 9) + __builtin_abort (); +} + +__attribute__((noipa)) void +quux (char *p) +{ + int i; + for (i = 0; i < 100; i++) + if (p[i] != 'x') + __builtin_abort (); +} + +__attribute__((noipa)) void +qux (void) +{ + char b[100]; + __builtin_memset (b, 'x', sizeof (b)); + quux (b); +} + +__attribute__((noipa)) void +bar (void) +{ + static unsigned char u[9] = "abcdefghi"; + char b[100]; + __builtin_memcpy (b, u, sizeof (u)); + b[sizeof (u)] = 0; + foo (b); +} + +__attribute__((noipa)) void +baz (void) +{ + static unsigned char u[] = { 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r' }; + char b[100]; + __builtin_memcpy (b, u, sizeof (u)); + b[sizeof (u)] = 0; + foo (b); +} + +int +main () +{ + qux (); + bar (); + baz (); + return 0; +} diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 55fba88e0f4..02ed1b4c777 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -3232,8 +3232,9 @@ get_min_string_length (tree rhs, bool *full_string_p) if (rhs && TREE_CODE (rhs) == STRING_CST) { - *full_string_p = true; - return strlen (TREE_STRING_POINTER (rhs)); + HOST_WIDE_INT len = strlen (TREE_STRING_POINTER (rhs)); + *full_string_p = len < TREE_STRING_LENGTH (rhs); + return len; } return -1;