]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c/46547 (internal compiler error when converting a complex to a bool)
authorJoseph Myers <joseph@codesourcery.com>
Fri, 19 Nov 2010 20:45:00 +0000 (20:45 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 19 Nov 2010 20:45:00 +0000 (20:45 +0000)
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.
* c-tree.h (in_late_binary_op): Move to c-common.h.
* c-typeck.c (in_late_binary_op): Move to c-common.c.

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

From-SVN: r166957

gcc/ChangeLog
gcc/c-common.c
gcc/c-common.h
gcc/c-tree.h
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr46547-1.c [new file with mode: 0644]

index 5f65851e43f822f038bc10ddc09607c8260b5650..31e3d5c460ca00db9238917437f031b5fecf938f 100644 (file)
@@ -1,3 +1,13 @@
+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.
+       * c-tree.h (in_late_binary_op): Move to c-common.h.
+       * c-typeck.c (in_late_binary_op): Move to c-common.c.
+
 2010-11-17  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/46498
index 11a8b119500931295fcba2269f9e8d7e62b58662..db329cef546bc71a9c9ca7776f081bac2a1e3d29 100644 (file)
@@ -446,6 +446,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;
@@ -4057,7 +4065,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)
index 6f8d832d455ab1849144ce73344a25fc6586ef44..acf6aa7cfc97349e3cfddf3576ba874a7203b0e3 100644 (file)
@@ -802,6 +802,7 @@ extern const struct attribute_spec c_common_format_attribute_table[];
 
 extern tree (*make_fname_decl) (location_t, tree, int);
 
+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 2309d51d58914c5726881ff92db7a0310cdcbadf..f5a02a612b02db5dc48121e326097eba5d175b9b 100644 (file)
@@ -495,7 +495,6 @@ extern bool c_vla_unspec_p (tree x, tree fn);
                          ((VOLATILE_P) ? TYPE_QUAL_VOLATILE : 0))
 
 /* in c-typeck.c */
-extern bool in_late_binary_op;
 extern int in_alignof;
 extern int in_sizeof;
 extern int in_typeof;
index c17cef7ba36864da20aa95ac352d0f22e27c3514..56bad2c88ae5a1c1751a2091db5eb72c815b7398 100644 (file)
@@ -55,13 +55,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;
 
index 7b3b73abad7dc1d3bd929ff94ba49e800d1e5bfc..ff9d6bcfc268c348c5e1fc0b07bbbbb42fad9408 100644 (file)
@@ -1,3 +1,8 @@
+2010-11-19  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/46547
+       * gcc.c-torture/compile/pr46547-1.c: New test.
+
 2010-11-16  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc.target/rx/pack.c: New test.
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 (file)
index 0000000..67d8e1e
--- /dev/null
@@ -0,0 +1,6 @@
+void foo (void) {
+  _Bool d;
+  long double _Complex *s;
+
+  d = *s++;
+}