[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 --- Comment #8 from Martin Sebor --- Author: msebor Date: Wed Jul 25 02:11:31 2018 New Revision: 262958 URL: https://gcc.gnu.org/viewcvs?rev=262958&root=gcc&view=rev Log: PR tree-optimization/86622 - incorrect strlen of array of array plus variable offset PR tree-optimization/86532 - Wrong code due to a wrong strlen folding starting with r262522 gcc/ChangeLog: PR tree-optimization/86622 PR tree-optimization/86532 * builtins.h (string_length): Declare. * builtins.c (c_strlen): Correct handling of non-constant offsets. (check_access): Be prepared for non-constant length ranges. (string_length): Make extern. * expr.c (string_constant): Only handle the minor non-constant array index. Use string_constant to compute the length of a generic string constant. gcc/testsuite/ChangeLog: PR tree-optimization/86622 PR tree-optimization/86532 * gcc.c-torture/execute/strlen-2.c: New test. * gcc.c-torture/execute/strlen-3.c: New test. * gcc.c-torture/execute/strlen-4.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/strlen-2.c trunk/gcc/testsuite/gcc.c-torture/execute/strlen-3.c trunk/gcc/testsuite/gcc.c-torture/execute/strlen-4.c Modified: trunk/gcc/ChangeLog trunk/gcc/builtins.c trunk/gcc/builtins.h trunk/gcc/expr.c trunk/gcc/testsuite/ChangeLog
[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 Martin Sebor changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED --- Comment #9 from Martin Sebor --- Fixed in r262958.
[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 Richard Biener changed: What|Removed |Added Target Milestone|--- |9.0
[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 Bernd Edlinger changed: What|Removed |Added CC||bernd.edlinger at hotmail dot de --- Comment #7 from Bernd Edlinger --- The test case can be modified to fail on current trunk as well: $ cat p.c static const char a[3][8] = { "1234", "1234567", "123456" }; int main () { volatile int i = 1; int n = __builtin_strlen (*(&a[1]+i)); if (n != 6) __builtin_abort (); }
[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 --- Comment #6 from Martin Sebor --- Sorry, I didn't give enough details in the report. As discussed in the gcc-patches thread referenced in comment #0, the bug is latent on current trunk. It only manifests itself when the fix for bug 86532 is applied.
[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 --- Comment #5 from U.Mutlu --- I have to correct myself in #2 and #3. The code is correct, and should return n=6.
[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 --- Comment #4 from U.Mutlu --- gcc version 4.9.2 (Debian 4.9.2-10+deb8u1) gives the same result as v9: p=123456 n=6
[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 --- Comment #3 from U.Mutlu --- I just tested it with v9: #include static const char a[3][8] = { "1234", "12345", "123456" }; int main () { volatile int i = 1; const char* p = *(&a[1] + i); int n = __builtin_strlen (p); printf("p=%s n=%d\n", p, n);// p=123456 n=6 if (n != 6) __builtin_abort (); } Hmm. I would have expected something different, along the lines of p=&a[1][1]... The question is, which result is correct?
[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 U.Mutlu changed: What|Removed |Added CC||um at mutluit dot com --- Comment #2 from U.Mutlu --- I think there's no error. IMO the call is wrong as it tests the strlen of a single char (a[1][1], ie. '2'), which of course is bogus.
[Bug tree-optimization/86622] [9 Regression] incorrect strlen of array of array plus variable offset
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86622 Martin Sebor changed: What|Removed |Added Status|UNCONFIRMED |ASSIGNED Keywords||wrong-code Last reconfirmed||2018-07-21 Assignee|unassigned at gcc dot gnu.org |msebor at gcc dot gnu.org Blocks||83819 See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=86532 Ever confirmed|0 |1 Summary|incorrect strlen of array |[9 Regression] incorrect |of array plus variable |strlen of array of array |offset |plus variable offset --- Comment #1 from Martin Sebor --- See also bug 86532 for another problem introduced into this area by r262522. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83819 [Bug 83819] [meta-bug] missing strlen optimizations