Bug 33423 - [4.2 regression]: internal compiler error: in expand_expr_real_1, at expr.c:8670
Summary: [4.2 regression]: internal compiler error: in expand_expr_real_1, at expr.c:8670
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.2
: P2 normal
Target Milestone: 4.3.0
Assignee: Jakub Jelinek
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-13 20:07 UTC by H.J. Lu
Modified: 2009-03-30 22:18 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.3 4.3.0
Known to fail: 4.2.2 4.2.5
Last reconfirmed: 2007-09-15 20:01:47


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2007-09-13 20:07:29 UTC
[hjl@gnu-11 rrs]$ cat foo.c
static union {
  char buf[((sizeof (long long)) + 15 + (sizeof (long long)))];
  long long align_int;
  long double align_fp;
} u2;

void
test6 (void)
{
  int len;
  char *p;

  for (len = 0; len < 15; len++)
    {
      p = __builtin___memset_chk (u2.buf, '\0', len,
                                  __builtin_object_size (u2.buf, 0));
      if (p != u2.buf) return;
    }
}
[hjl@gnu-11 rrs]$ ~/usr/gcc-4.3/bin/gcc -S -O3 foo.c
foo.c: In function ‘test6’:
foo.c:15: internal compiler error: in expand_expr_real_1, at expr.c:8670
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
Comment 1 H.J. Lu 2007-09-13 21:52:50 UTC
Revision 116656:

http://gcc.gnu.org/ml/gcc-patches/2006-09/msg00026.html

causes this regression.
Comment 2 H.J. Lu 2007-09-15 03:43:28 UTC
It also fails on Linux/ia32 and Linux/x86-64.
Comment 3 H.J. Lu 2007-09-15 14:23:28 UTC
It is a simpler testcase:

---
static struct {
  char buf[15];
} u2;

void
test6 (void)
{
  int len;
  char *p;

  for (len = 0; len < 2; len++)
    {
      p = __builtin___memset_chk (u2.buf, '\0', len, 15);
      if (p != u2.buf) return;
    }
}
---
Comment 4 H.J. Lu 2007-09-15 14:58:15 UTC
This one works:

---
static 
  char buf[15];

void
test6 (void)
{
  int len;
  char *p;

  for (len = 0; len < 15; len++)
    {
      p = __builtin___memset_chk (&buf[0], '\0', len, 15);
      if (p != &buf[0]) return;
    }
}
---
Comment 5 H.J. Lu 2007-09-15 15:00:20 UTC
We can fold

 __builtin___memset_chk (buf, 0, 1, 15);

into

__builtin_memset (&buf, 0, 1);

But we failed to fold

 __builtin___memset_chk (&u2.buf[0], 0, 1, 15);
Comment 6 H.J. Lu 2007-09-15 18:50:40 UTC
Another simple testcase:
---
static char buf;

void
test6 (void)
{
  int len;
  void *p;

  for (len = 0; len < 2; len++)
    {
      p = __builtin___memset_chk (&buf, '\0', len, 1);
      if (p != &buf) return;
    }
}
---

fold_builtin_memset was added to return COMPOUND_EXPR via
omit_one_operand. But there was nothing added to handle it.
Comment 7 H.J. Lu 2007-09-15 19:24:26 UTC
This patch works for the testcase.

--- gcc/expr.c.chk      2007-09-07 07:53:42.000000000 -0700
+++ gcc/expr.c  2007-09-15 12:21:57.000000000 -0700
@@ -9117,7 +9117,6 @@ expand_expr_real_1 (tree exp, rtx target
     case BIND_EXPR:
     case INIT_EXPR:
     case CONJ_EXPR:
-    case COMPOUND_EXPR:
     case PREINCREMENT_EXPR:
     case PREDECREMENT_EXPR:
     case POSTINCREMENT_EXPR:
@@ -9129,6 +9128,15 @@ expand_expr_real_1 (tree exp, rtx target
       /* Lowered by gimplify.c.  */
       gcc_unreachable ();
 
+    case COMPOUND_EXPR:
+      while (TREE_CODE (exp) == COMPOUND_EXPR)
+       {
+         expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode,
+                      EXPAND_NORMAL);
+         exp = TREE_OPERAND (exp, 1);
+       }
+      return expand_expr (exp, target, mode, EXPAND_NORMAL);
+
     case CHANGE_DYNAMIC_TYPE_EXPR:
       /* This is ignored at the RTL level.  The tree level set
         DECL_POINTER_ALIAS_SET of any variable to be 0, which is
Comment 8 Andrew Pinski 2007-09-15 19:30:25 UTC
Subject: Re:  [4.2/4.3 regression]: internal compiler error: in expand_expr_real_1, at expr.c:8670

On 15 Sep 2007 19:24:28 -0000, hjl at lucon dot org
<gcc-bugzilla@gcc.gnu.org> wrote:
>
>
> ------- Comment #7 from hjl at lucon dot org  2007-09-15 19:24 -------
> This patch works for the testcase.

And is wrong.

COMPOUND_EXPR support was removed on purpose.

-- Pinski
Comment 9 Jakub Jelinek 2007-09-17 22:05:52 UTC
Subject: Bug 33423

Author: jakub
Date: Mon Sep 17 22:05:40 2007
New Revision: 128554

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128554
Log:
	PR middle-end/33423
	* builtins.c (expand_builtin_memory_chk): Handle COMPOUND_EXPRs
	returned by build_call_expr.

	* gcc.c-torture/compile/20070915-1.c: New test.

Added:
    trunk/gcc/testsuite/gcc.c-torture/compile/20070915-1.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c
    trunk/gcc/testsuite/ChangeLog

Comment 10 Jakub Jelinek 2007-09-25 10:27:40 UTC
Subject: Bug 33423

Author: jakub
Date: Tue Sep 25 10:27:28 2007
New Revision: 128759

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128759
Log:
	PR middle-end/33423
	* builtins.c (expand_builtin_memory_chk): Handle COMPOUND_EXPRs
	returned by build_call_expr.

	* gcc.c-torture/compile/20070915-1.c: New test.

Added:
    branches/redhat/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/compile/20070915-1.c
Modified:
    branches/redhat/gcc-4_1-branch/gcc/ChangeLog
    branches/redhat/gcc-4_1-branch/gcc/builtins.c
    branches/redhat/gcc-4_1-branch/gcc/testsuite/ChangeLog

Comment 11 Mark Mitchell 2007-10-09 19:21:44 UTC
Change target milestone to 4.2.3, as 4.2.2 has been released.
Comment 12 Joseph S. Myers 2008-02-01 16:54:47 UTC
4.2.3 is being released now, changing milestones of open bugs to 4.2.4.
Comment 13 Joseph S. Myers 2008-05-19 20:23:25 UTC
4.2.4 is being released, changing milestones to 4.2.5.
Comment 14 Joseph S. Myers 2009-03-30 22:18:17 UTC
Closing 4.2 branch, fixed in 4.3.