* C++ PATCH to fix ICE with bit-fields and ?: (PR c++/81607)
@ 2017-07-31 11:09 Marek Polacek
2017-08-07 18:33 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2017-07-31 11:09 UTC (permalink / raw)
To: GCC Patches, Jason Merrill
We crash in the gimplifier because it sees a shift expression with different
types of op1/op2. The problem arises in cp_fold: it gets "1 ? d.c : 0" of type
int which is folded to "d.c", but it then sees that d.c is a bit-field with
declared type long int, so if produces "(long int) d.c" -- but that differs
from the original COND_EXPR type! Folding should not change the type of the
CODE_EXPR, thus this fix.
Bootstrapped/regtested on x86_64-linux, ok for trunk/7/6?
2017-07-31 Marek Polacek <polacek@redhat.com>
PR c++/81607
* cp-gimplify.c (cp_fold): If folding exposed a branch of
a COND_EXPR, convert it to the original type of the COND_EXPR, if
they differ.
* g++.dg/other/bitfield6.C: New test.
diff --git gcc/cp/cp-gimplify.c gcc/cp/cp-gimplify.c
index a9563b1a8cd..9fc4ab18207 100644
--- gcc/cp/cp-gimplify.c
+++ gcc/cp/cp-gimplify.c
@@ -2314,9 +2314,9 @@ cp_fold (tree x)
/* A COND_EXPR might have incompatible types in branches if one or both
arms are bitfields. If folding exposed such a branch, fix it up. */
- if (TREE_CODE (x) != code)
- if (tree type = is_bitfield_expr_with_lowered_type (x))
- x = fold_convert (type, x);
+ if (TREE_CODE (x) != code
+ && !useless_type_conversion_p (TREE_TYPE (org_x), TREE_TYPE (x)))
+ x = fold_convert (TREE_TYPE (org_x), x);
break;
diff --git gcc/testsuite/g++.dg/other/bitfield6.C gcc/testsuite/g++.dg/other/bitfield6.C
index e69de29bb2d..c1e8a17989b 100644
--- gcc/testsuite/g++.dg/other/bitfield6.C
+++ gcc/testsuite/g++.dg/other/bitfield6.C
@@ -0,0 +1,9 @@
+// PR c++/81607
+
+int a;
+
+struct b {
+ long c : 32;
+} d;
+
+char f = (903092 ? int(d.c) : 0) << a;
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH to fix ICE with bit-fields and ?: (PR c++/81607)
2017-07-31 11:09 C++ PATCH to fix ICE with bit-fields and ?: (PR c++/81607) Marek Polacek
@ 2017-08-07 18:33 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2017-08-07 18:33 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
OK.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-08-07 18:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-31 11:09 C++ PATCH to fix ICE with bit-fields and ?: (PR c++/81607) Marek Polacek
2017-08-07 18:33 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).