This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix PR c/27721: ICE using += with a function
- From: Volker Reichelt <reichelt at igpm dot rwth-aachen dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 20 Jul 2006 16:51:40 +0200 (CEST)
- Subject: [patch] Fix PR c/27721: ICE using += with a function
The following invalid testcase triggers an ICE in the C frontend:
void foo()
{
int i();
i += 0;
}
bug.c: In function 'foo':
bug.c:4: internal compiler error: in default_conversion, at c-typeck.c:1642
Please submit a full bug report, [etc.]
The problem is in build_modify_expr: We already have a sanity check
for the lhs of the assignment (by calling lvalue_or_else) in place.
However, we call build_binary_op with the invalid lhs before the check
is performed. This finally leads to the crash.
The patch below fixes the ICE by just moving the sanity check a couple
of lines before the call to build_binary_op.
Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline and 4.1 branch?
Regards,
Volker
:ADDPATCH C:
2006-07-20 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c/27721
* c-typeck.c (build_modify_expr): Test earlier for non-lvalues.
===================================================================
--- gcc/gcc/c-typeck.c 2006-07-20 03:13:31 +0200
+++ gcc/gcc/c-typeck.c 2006-07-20 03:11:48 +0200
@@ -3667,6 +3667,9 @@ build_modify_expr (tree lhs, enum tree_c
if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
return error_mark_node;
+ if (!lvalue_or_else (lhs, lv_assign))
+ return error_mark_node;
+
STRIP_TYPE_NOPS (rhs);
newrhs = rhs;
@@ -3680,9 +3683,6 @@ build_modify_expr (tree lhs, enum tree_c
newrhs = build_binary_op (modifycode, lhs, rhs, 1);
}
- if (!lvalue_or_else (lhs, lv_assign))
- return error_mark_node;
-
/* Give an error for storing in something that is 'const'. */
if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
===================================================================
2006-07-20 Volker Reichelt <reichelt@igpm.rwth-aachen.de>
PR c/27721
* gcc.dg/lvalue-4.c: New test.
===================================================================
--- gcc/gcc/testsuite/gcc.dg/lvalue-4.c 2003-09-23 19:59:22 +0200
+++ gcc/gcc/testsuite/gcc.dg/lvalue-4.c 2006-07-20 03:18:38 +0200
@@ -0,0 +1,8 @@
+/* PR c/27721 */
+/* { dg-do compile } */
+
+void foo()
+{
+ int i();
+ i += 0; /* { dg-error "lvalue required" } */
+}
===================================================================