Bug 84339 - [8 Regression] Wrong-code with optimizing strlen
Summary: [8 Regression] Wrong-code with optimizing strlen
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 8.0
: P1 normal
Target Milestone: 8.0
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2018-02-12 14:31 UTC by Marek Polacek
Modified: 2018-02-13 08:37 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-02-12 00:00:00


Attachments
gcc8-pr84339.patch (962 bytes, patch)
2018-02-12 14:50 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2018-02-12 14:31:40 UTC
Hunspell's test alias3 fails.  Distilled testcase:

typedef __SIZE_TYPE__ size_t;
struct S { int a; char b[1]; };

__attribute__((noipa)) size_t
foo (struct S *p)
{
  return __builtin_strlen (&p->b[0]);
}

__attribute__((noipa)) size_t
bar (struct S *p)
{
  return __builtin_strlen (p->b);
}

int
main ()
{
  struct S *p = __builtin_malloc (sizeof (struct S) + 16);
  if (p)
    {
      p->a = 1;
      __builtin_strcpy (p->b, "abcdefg");
      if (foo (p) != 7 || bar (p) != 7)
	__builtin_abort ();
      __builtin_free (p);
    }
  return 0;
}

Started with r256457.
Comment 1 Marek Polacek 2018-02-12 14:32:04 UTC
Jakub has a fix.
Comment 2 Jakub Jelinek 2018-02-12 14:50:00 UTC
Created attachment 43396 [details]
gcc8-pr84339.patch

Untested fix.
Comment 3 Jakub Jelinek 2018-02-13 08:36:25 UTC
Author: jakub
Date: Tue Feb 13 08:35:53 2018
New Revision: 257618

URL: https://gcc.gnu.org/viewcvs?rev=257618&root=gcc&view=rev
Log:
	PR tree-optimization/84339
	* gimple-fold.c (get_range_strlen): Set *FLEXP to true when handling
	ARRAY_REF where first operand is array_at_struct_end_p COMPONENT_REF.
	Formatting fixes.

	* gcc.c-torture/execute/pr84339.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr84339.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-fold.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Jakub Jelinek 2018-02-13 08:37:24 UTC
Fixed.