summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2001-04-23 22:55:32 +0000
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>2001-04-23 22:55:32 +0000
commit780b5c1b45463717d90f1958a6dc73fb523498f6 (patch)
treee56281c646b5d3025e6590d3b59fc38691173903 /gcc
parente46566dab0db7d1e3a5a0feb0d6fe2ac146181fe (diff)
downloadgcc-780b5c1b45463717d90f1958a6dc73fb523498f6.tar.gz
* c-convert.c (convert): When converting to a BOOLEAN_TYPE, avoid
passing nested NOP_EXPRs to fold. testsuite: * gcc.c-torture/compile/20010423-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@41508 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-convert.c10
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/20010423-1.c16
4 files changed, 34 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e3d7ad0d9bb..fca2bcffc1a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2001-04-23 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * c-convert.c (convert): When converting to a BOOLEAN_TYPE, avoid
+ passing nested NOP_EXPRs to fold.
+
Mon Apr 23 14:32:12 CEST 2001 Jan Hubicka <jh@suse.cz>
* reg-stack.c (emit_swap_insn): Do not get pass CALL_INSNs.
diff --git a/gcc/c-convert.c b/gcc/c-convert.c
index 7f57725b7c1..6585f3cb4f6 100644
--- a/gcc/c-convert.c
+++ b/gcc/c-convert.c
@@ -89,7 +89,15 @@ convert (type, expr)
if (code == INTEGER_TYPE || code == ENUMERAL_TYPE)
return fold (convert_to_integer (type, e));
if (code == BOOLEAN_TYPE)
- return fold (build1 (NOP_EXPR, type, truthvalue_conversion (expr)));
+ {
+ tree t = truthvalue_conversion (expr);
+ /* If truthvalue_conversion returns a NOP_EXPR, we must fold it here
+ to avoid infinite recursion between fold () and convert (). */
+ if (TREE_CODE (t) == NOP_EXPR)
+ return fold (build1 (NOP_EXPR, type, TREE_OPERAND (t, 0)));
+ else
+ return fold (build1 (NOP_EXPR, type, t));
+ }
if (code == POINTER_TYPE || code == REFERENCE_TYPE)
return fold (convert_to_pointer (type, e));
if (code == REAL_TYPE)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f2c3d70e037..aa168b69cb7 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2001-04-23 Joseph S. Myers <jsm28@cam.ac.uk>
+
+ * gcc.c-torture/compile/20010423-1.c: New test.
+
2001-04-20 Nathan Sidwell <nathan@codesourcery.com>
* g++.old-deja/g++.pt/typename28.C: New test.
diff --git a/gcc/testsuite/gcc.c-torture/compile/20010423-1.c b/gcc/testsuite/gcc.c-torture/compile/20010423-1.c
new file mode 100644
index 00000000000..ef7771f8e6b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/20010423-1.c
@@ -0,0 +1,16 @@
+/* Origin: PR c/2618 from Cesar Eduardo Barros <cesarb@nitnet.com.br>,
+ adapted to a testcase by Joseph Myers <jsm28@cam.ac.uk>.
+
+ Boolean conversions were causing infinite recursion between convert
+ and fold in certain cases. */
+
+#include <stdbool.h>
+
+bool x;
+unsigned char y;
+
+void
+fn (void)
+{
+ x = y & 0x1 ? 1 : 0;
+}