1 |
commit: 21ed34524e3ab3139c811b6d61f50522ebd2b184 |
2 |
Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jun 24 20:14:42 2020 +0000 |
4 |
Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jun 24 20:14:42 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=21ed3452 |
7 |
|
8 |
10.1.0: backport PR95508, ICE on array subscript implicit conversion |
9 |
|
10 |
Reported-by: hsk17 <AT> mail.de |
11 |
Bug: https://bugs.gentoo.org/729434 |
12 |
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org> |
13 |
|
14 |
.../35_all_ICE-array-subscript-PR95508.patch | 106 +++++++++++++++++++++ |
15 |
10.1.0/gentoo/README.history | 1 + |
16 |
2 files changed, 107 insertions(+) |
17 |
|
18 |
diff --git a/10.1.0/gentoo/35_all_ICE-array-subscript-PR95508.patch b/10.1.0/gentoo/35_all_ICE-array-subscript-PR95508.patch |
19 |
new file mode 100644 |
20 |
index 0000000..37abd53 |
21 |
--- /dev/null |
22 |
+++ b/10.1.0/gentoo/35_all_ICE-array-subscript-PR95508.patch |
23 |
@@ -0,0 +1,106 @@ |
24 |
+https://gcc.gnu.org/PR95508 |
25 |
+https://bugs.gentoo.org/729434 |
26 |
+ |
27 |
+From 1bab254fd30c2b94a675b9057349fc80946375b1 Mon Sep 17 00:00:00 2001 |
28 |
+From: Marek Polacek <polacek@××××××.com> |
29 |
+Date: Wed, 17 Jun 2020 14:38:05 -0400 |
30 |
+Subject: [PATCH] c++: ICE with IMPLICIT_CONV_EXPR in array subscript [PR95508] |
31 |
+ |
32 |
+Since r10-7096 convert_like, when called in a template, creates an |
33 |
+IMPLICIT_CONV_EXPR when we're converting to/from array type. |
34 |
+ |
35 |
+In this test, we have e[f], and we're converting f (of type class A) to |
36 |
+int, so convert_like in build_new_op_1 created the IMPLICIT_CONV_EXPR |
37 |
+that got into cp_build_array_ref which calls maybe_constant_value. My |
38 |
+patch above failed to adjust this spot to call fold_non_dependent_expr |
39 |
+instead, which can handle codes like I_C_E in a template. Fixed by |
40 |
+using a new function maybe_fold_non_dependent_expr, which, if the expr |
41 |
+can't be evaluated to a constant, returns the original expression. |
42 |
+ |
43 |
+gcc/cp/ChangeLog: |
44 |
+ |
45 |
+ PR c++/95508 |
46 |
+ * constexpr.c (maybe_fold_non_dependent_expr): New. |
47 |
+ * cp-tree.h (maybe_fold_non_dependent_expr): Declare. |
48 |
+ * typeck.c (cp_build_array_ref): Call maybe_fold_non_dependent_expr |
49 |
+ instead of maybe_constant_value. |
50 |
+ |
51 |
+gcc/testsuite/ChangeLog: |
52 |
+ |
53 |
+ PR c++/95508 |
54 |
+ * g++.dg/template/conv16.C: New test. |
55 |
+--- |
56 |
+ gcc/cp/constexpr.c | 13 +++++++++++++ |
57 |
+ gcc/cp/cp-tree.h | 2 ++ |
58 |
+ gcc/cp/typeck.c | 2 +- |
59 |
+ gcc/testsuite/g++.dg/template/conv16.C | 17 +++++++++++++++++ |
60 |
+ 4 files changed, 33 insertions(+), 1 deletion(-) |
61 |
+ create mode 100644 gcc/testsuite/g++.dg/template/conv16.C |
62 |
+ |
63 |
+--- a/gcc/cp/constexpr.c |
64 |
++++ b/gcc/cp/constexpr.c |
65 |
+@@ -7043,6 +7043,19 @@ fold_non_dependent_expr (tree t, |
66 |
+ return maybe_constant_value (t, object, manifestly_const_eval); |
67 |
+ } |
68 |
+ |
69 |
++/* Like fold_non_dependent_expr, but if EXPR couldn't be folded to a constant, |
70 |
++ return the original expression. */ |
71 |
++ |
72 |
++tree |
73 |
++maybe_fold_non_dependent_expr (tree expr, |
74 |
++ tsubst_flags_t complain/*=tf_warning_or_error*/) |
75 |
++{ |
76 |
++ tree t = fold_non_dependent_expr (expr, complain); |
77 |
++ if (t && TREE_CONSTANT (t)) |
78 |
++ return t; |
79 |
++ |
80 |
++ return expr; |
81 |
++} |
82 |
+ |
83 |
+ /* Like maybe_constant_init but first fully instantiate the argument. */ |
84 |
+ |
85 |
+--- a/gcc/cp/cp-tree.h |
86 |
++++ b/gcc/cp/cp-tree.h |
87 |
+@@ -7955,6 +7955,8 @@ extern tree maybe_constant_init (tree, tree = NULL_TREE, bool = false); |
88 |
+ extern tree fold_non_dependent_expr (tree, |
89 |
+ tsubst_flags_t = tf_warning_or_error, |
90 |
+ bool = false, tree = NULL_TREE); |
91 |
++extern tree maybe_fold_non_dependent_expr (tree, |
92 |
++ tsubst_flags_t = tf_warning_or_error); |
93 |
+ extern tree fold_non_dependent_init (tree, |
94 |
+ tsubst_flags_t = tf_warning_or_error, |
95 |
+ bool = false); |
96 |
+--- a/gcc/cp/typeck.c |
97 |
++++ b/gcc/cp/typeck.c |
98 |
+@@ -3553,7 +3553,7 @@ cp_build_array_ref (location_t loc, tree array, tree idx, |
99 |
+ pointer arithmetic.) */ |
100 |
+ idx = cp_perform_integral_promotions (idx, complain); |
101 |
+ |
102 |
+- idx = maybe_constant_value (idx); |
103 |
++ idx = maybe_fold_non_dependent_expr (idx, complain); |
104 |
+ |
105 |
+ /* An array that is indexed by a non-constant |
106 |
+ cannot be stored in a register; we must be able to do |
107 |
+--- /dev/null |
108 |
++++ b/gcc/testsuite/g++.dg/template/conv16.C |
109 |
+@@ -0,0 +1,17 @@ |
110 |
++// PR c++/95508 |
111 |
++// { dg-do compile } |
112 |
++ |
113 |
++template <typename> |
114 |
++struct A; |
115 |
++template <typename> |
116 |
++struct B { |
117 |
++ operator int () { return 0; } |
118 |
++}; |
119 |
++template <> |
120 |
++struct A<unsigned> : B<int> {}; |
121 |
++struct D { |
122 |
++ template <typename> |
123 |
++ int foo () { return e[f]; } |
124 |
++ int e[6]; |
125 |
++ A<unsigned> f; |
126 |
++}; |
127 |
+-- |
128 |
+2.27.0 |
129 |
+ |
130 |
|
131 |
diff --git a/10.1.0/gentoo/README.history b/10.1.0/gentoo/README.history |
132 |
index 480a54e..72e0086 100644 |
133 |
--- a/10.1.0/gentoo/README.history |
134 |
+++ b/10.1.0/gentoo/README.history |
135 |
@@ -1,6 +1,7 @@ |
136 |
3 TODO |
137 |
33_all_avx512-scalar-PR95528.patch |
138 |
34_all_cet-cross-x86.patch |
139 |
+ 35_all_ICE-array-subscript-PR95508.patch |
140 |
|
141 |
2 11 June 2020 |
142 |
+ 29_all_fix-float-hang-PR95118.patch |