diff mbox

Fix PR c/46547

Message ID Pine.LNX.4.64.1011191833190.23107@digraph.polyomino.org.uk
State New
Headers show

Commit Message

Joseph Myers Nov. 19, 2010, 6:33 p.m. UTC
This patch fixes PR c/46547, a regression from the constant expression
changes in 4.5, by adding a check of in_late_binary_op as discussed in
that PR.

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  Applied
to mainline.  I'm also testing a backport to 4.5 branch and will
commit there subject to testing.

2010-11-19  Joseph Myers  <joseph@codesourcery.com>

	PR c/46547
	* c-tree.h (in_late_binary_op): Move to c-family/c-common.h.
	* c-typeck.c (in_late_binary_op): Move to c-family/c-common.c.

c-family:
2010-11-19  Joseph Myers  <joseph@codesourcery.com>

	PR c/46547
	* c-common.c (in_late_binary_op): Define.
	(c_common_truthvalue_conversion): Check in_late_binary_op before
	calling c_save_expr.
	* c-common.h (in_late_binary_op): Declare.

testsuite:
2010-11-19  Joseph Myers  <joseph@codesourcery.com>

	PR c/46547
	* gcc.c-torture/compile/pr46547-1.c: New test.

Comments

Eric Botcazou Nov. 19, 2010, 9:02 p.m. UTC | #1
> Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  Applied
> to mainline.  I'm also testing a backport to 4.5 branch and will
> commit there subject to testing.
>
> 2010-11-19  Joseph Myers  <joseph@codesourcery.com>
>
> 	PR c/46547
> 	* c-tree.h (in_late_binary_op): Move to c-family/c-common.h.
> 	* c-typeck.c (in_late_binary_op): Move to c-family/c-common.c.
>
> c-family:
> 2010-11-19  Joseph Myers  <joseph@codesourcery.com>
>
> 	PR c/46547
> 	* c-common.c (in_late_binary_op): Define.
> 	(c_common_truthvalue_conversion): Check in_late_binary_op before
> 	calling c_save_expr.
> 	* c-common.h (in_late_binary_op): Declare.

I cannot bootstrap anymore with Objective-C++ enabled.
diff mbox

Patch

Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 166944)
+++ gcc/c-family/c-common.c	(working copy)
@@ -271,6 +271,14 @@  tree (*make_fname_decl) (location_t, tre
    executed.  */
 int c_inhibit_evaluation_warnings;
 
+/* Whether we are building a boolean conversion inside
+   convert_for_assignment, or some other late binary operation.  If
+   build_binary_op is called for C (from code shared by C and C++) in
+   this case, then the operands have already been folded and the
+   result will not be folded again, so C_MAYBE_CONST_EXPR should not
+   be generated.  */
+bool in_late_binary_op;
+
 /* Whether lexing has been completed, so subsequent preprocessor
    errors should use the compiler's input_location.  */
 bool done_lexing = false;
@@ -3939,7 +3947,7 @@  c_common_truthvalue_conversion (location
 
   if (TREE_CODE (TREE_TYPE (expr)) == COMPLEX_TYPE)
     {
-      tree t = c_save_expr (expr);
+      tree t = (in_late_binary_op ? save_expr (expr) : c_save_expr (expr));
       expr = (build_binary_op
 	      (EXPR_LOCATION (expr),
 	       (TREE_SIDE_EFFECTS (expr)
Index: gcc/c-family/c-common.h
===================================================================
--- gcc/c-family/c-common.h	(revision 166944)
+++ gcc/c-family/c-common.h	(working copy)
@@ -675,6 +675,7 @@  extern tree (*make_fname_decl) (location
 extern void c_register_addr_space (const char *str, addr_space_t as);
 
 /* In c-common.c.  */
+extern bool in_late_binary_op;
 extern const char *c_addr_space_name (addr_space_t as);
 extern tree identifier_global_value (tree);
 extern void record_builtin_type (enum rid, const char *, tree);
Index: gcc/testsuite/gcc.c-torture/compile/pr46547-1.c
===================================================================
--- gcc/testsuite/gcc.c-torture/compile/pr46547-1.c	(revision 0)
+++ gcc/testsuite/gcc.c-torture/compile/pr46547-1.c	(revision 0)
@@ -0,0 +1,6 @@ 
+void foo (void) {
+  _Bool d;
+  long double _Complex *s;
+
+  d = *s++;
+}
Index: gcc/c-tree.h
===================================================================
--- gcc/c-tree.h	(revision 166944)
+++ gcc/c-tree.h	(working copy)
@@ -501,7 +501,6 @@  extern void c_initialize_diagnostics (di
 extern bool c_vla_unspec_p (tree x, tree fn);
 
 /* in c-typeck.c */
-extern bool in_late_binary_op;
 extern int in_alignof;
 extern int in_sizeof;
 extern int in_typeof;
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c	(revision 166944)
+++ gcc/c-typeck.c	(working copy)
@@ -51,13 +51,6 @@  enum impl_conv {
   ic_return
 };
 
-/* Whether we are building a boolean conversion inside
-   convert_for_assignment, or some other late binary operation.  If
-   build_binary_op is called (from code shared with C++) in this case,
-   then the operands have already been folded and the result will not
-   be folded again, so C_MAYBE_CONST_EXPR should not be generated.  */
-bool in_late_binary_op;
-
 /* The level of nesting inside "__alignof__".  */
 int in_alignof;