c/2618: gcc crashes when doing _Bool = (unsigned char & 0x1) ?1 : 0
Joseph S. Myers
jsm28@cam.ac.uk
Mon Apr 23 16:00:00 GMT 2001
On 23 Apr 2001 cesarb@nitnet.com.br wrote:
> _Bool x;
> unsigned char y;
>
> void fn(void)
> {
> x = y & 0x1 ? 1 : 0;
> }
Fixed thus. Bootstrapped against branch with no regressions on
i686-pc-linux-gnu; installed on mainline and branch. (Note: the
included testcase shows that the bug is a regression from 2.95.)
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.
2001-04-23 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.c-torture/compile/20010423-1.c: New test.
--- c-convert.c.orig Mon Nov 13 14:10:46 2000
+++ c-convert.c Mon Apr 23 22:07:52 2001
@@ -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)
--- testsuite/gcc.c-torture/compile/20010423-1.c Mon Mar 26 23:57:02 2001
+++ testsuite/gcc.c-torture/compile/20010423-1.c Mon Apr 23 22:01:56 2001
@@ -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;
+}
--
Joseph S. Myers
jsm28@cam.ac.uk
More information about the Gcc-bugs
mailing list