From 93be21c016d4d35bbc03ac44c8be7077868afff1 Mon Sep 17 00:00:00 2001 From: jsm28 Date: Fri, 19 Nov 2010 18:32:57 +0000 Subject: [PATCH] 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: * 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: * gcc.c-torture/compile/pr46547-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@166951 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/c-family/ChangeLog | 8 ++++++++ gcc/c-family/c-common.c | 10 +++++++++- gcc/c-family/c-common.h | 1 + gcc/c-tree.h | 1 - gcc/c-typeck.c | 7 ------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/compile/pr46547-1.c | 6 ++++++ 8 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr46547-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 292fa371c94..4d467a2341e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-11-19 Joseph Myers + + 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. + 2010-11-19 Michael Meissner * doc/extend.texi (Function attributes): Document PowerPC target diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 93690687ef6..1c4b3f5506e 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,5 +1,13 @@ 2010-11-19 Joseph Myers + 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. + +2010-11-19 Joseph Myers + * c-opts.c (c_common_handle_option): Update calls to set_struct_debug_option. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index afe9b9d6e19..cd9175adb7c 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -271,6 +271,14 @@ tree (*make_fname_decl) (location_t, tree, int); 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_t location, tree expr) 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) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 6c6da9d1b1d..c01b183203a 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -675,6 +675,7 @@ extern tree (*make_fname_decl) (location_t, tree, int); 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); diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 0581b38da1f..64e784407f1 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -501,7 +501,6 @@ extern void c_initialize_diagnostics (diagnostic_context *); 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; diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 9aca720fd71..09e9ca73039 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 03e9df1be0a..c80e04246f6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-11-19 Joseph Myers + + PR c/46547 + * gcc.c-torture/compile/pr46547-1.c: New test. + 2010-11-19 Rainer Orth * lib/gcc-defs.exp (gcc-set-multilib-library-path): Use eval to diff --git a/gcc/testsuite/gcc.c-torture/compile/pr46547-1.c b/gcc/testsuite/gcc.c-torture/compile/pr46547-1.c new file mode 100644 index 00000000000..67d8e1e7e9a --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr46547-1.c @@ -0,0 +1,6 @@ +void foo (void) { + _Bool d; + long double _Complex *s; + + d = *s++; +} -- 2.11.0