[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.
Revision 116656: http://gcc.gnu.org/ml/gcc-patches/2006-09/msg00026.html causes this regression.
It also fails on Linux/ia32 and Linux/x86-64.
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; } } ---
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; } } ---
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);
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.
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
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
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
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
Change target milestone to 4.2.3, as 4.2.2 has been released.
4.2.3 is being released now, changing milestones of open bugs to 4.2.4.
4.2.4 is being released, changing milestones to 4.2.5.
Closing 4.2 branch, fixed in 4.3.