summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2016-12-09 14:04:53 +0000
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2016-12-09 14:04:53 +0000
commit9fdcc7e9428d52b215418d754e5cc67e01b3d33a (patch)
treea42fabac2eab038106cddfefed2432b0908fefe2
parent94adc59ee29cf118d650f8ad3dddc79604a45914 (diff)
downloadgcc-9fdcc7e9428d52b215418d754e5cc67e01b3d33a.tar.gz
PR c++/78550
* convert.c (convert_to_integer_1): Maybe fold conversions to integral types with fewer bits than its mode. testsuite/ PR c++/78550 * g++.dg/cpp1y/pr78550.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-6-branch@243484 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/convert.c9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp1y/pr78550.C22
4 files changed, 38 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 5db30ff49d2..7622597079a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2016-12-09 Nathan Sidwell <nathan@acm.org>
+
+ PR C++/78550
+ * convert.c (convert_to_integer_1): Maybe fold conversions to
+ integral types with fewer bits than its mode.
+
2016-12-09 Richard Biener <rguenther@suse.de>
Backport from mainline
diff --git a/gcc/convert.c b/gcc/convert.c
index e6b4d295c4e..862287bce09 100644
--- a/gcc/convert.c
+++ b/gcc/convert.c
@@ -644,10 +644,11 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
to TYPE. */
else if (TREE_CODE (type) == ENUMERAL_TYPE
|| outprec != GET_MODE_PRECISION (TYPE_MODE (type)))
- return build1 (NOP_EXPR, type,
- convert (lang_hooks.types.type_for_mode
- (TYPE_MODE (type), TYPE_UNSIGNED (type)),
- expr));
+ {
+ expr = convert (lang_hooks.types.type_for_mode
+ (TYPE_MODE (type), TYPE_UNSIGNED (type)), expr);
+ return maybe_fold_build1_loc (dofold, loc, NOP_EXPR, type, expr);
+ }
/* Here detect when we can distribute the truncation down past some
arithmetic. For example, if adding two longs and converting to an
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f31709401aa..c31a19f466f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-12-09 Nathan Sidwell <nathan@acm.org>
+
+ PR c++/78550
+ * g++.dg/cpp1y/pr78550.C: New.
+
2016-12-09 Richard Biener <rguenther@suse.de>
Backport from mainline
diff --git a/gcc/testsuite/g++.dg/cpp1y/pr78550.C b/gcc/testsuite/g++.dg/cpp1y/pr78550.C
new file mode 100644
index 00000000000..95596b10d7c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/pr78550.C
@@ -0,0 +1,22 @@
+// { dg-do compile { target c++14 } }
+
+// PR 78550 ICE with initializer_list and bitfield member
+
+namespace std
+{
+ template <class T>
+ struct initializer_list
+ {
+ const T *a;
+ __SIZE_TYPE__ b;
+ constexpr initializer_list (const T *x, __SIZE_TYPE__ y) : a(x), b(y) { }
+ };
+}
+template <typename T>
+struct A {
+ A (std::initializer_list<T>);
+};
+struct B {
+ int k : 1;
+};
+A<B> a{{0}};