1 |
commit: a824358f19e4fe8445a7bdbbe6c3020b9fd32bee |
2 |
Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Oct 8 22:04:04 2018 +0000 |
4 |
Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Oct 8 22:04:04 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=a824358f |
7 |
|
8 |
8.2.0: fix initialization of empty structs |
9 |
|
10 |
Single new patch: 111_all_ubd-hog-PR85704.patch |
11 |
|
12 |
Fix indefinite memory consumption. |
13 |
|
14 |
Bug: https://gcc.gnu.org/PR85704 |
15 |
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org> |
16 |
|
17 |
8.2.0/gentoo/111_all_ubd-hog-PR85704.patch | 146 +++++++++++++++++++++++++++++ |
18 |
8.2.0/gentoo/README.history | 3 + |
19 |
2 files changed, 149 insertions(+) |
20 |
|
21 |
diff --git a/8.2.0/gentoo/111_all_ubd-hog-PR85704.patch b/8.2.0/gentoo/111_all_ubd-hog-PR85704.patch |
22 |
new file mode 100644 |
23 |
index 0000000..de1c6e6 |
24 |
--- /dev/null |
25 |
+++ b/8.2.0/gentoo/111_all_ubd-hog-PR85704.patch |
26 |
@@ -0,0 +1,146 @@ |
27 |
+From e15966a15764277e180fdae7a606166c702ec3ca Mon Sep 17 00:00:00 2001 |
28 |
+From: jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> |
29 |
+Date: Wed, 1 Aug 2018 09:35:34 +0000 |
30 |
+Subject: [PATCH] PR c/85704 * c-typeck.c (init_field_decl_cmp): |
31 |
+ New function. (output_pending_init_elements): Use it for field comparisons |
32 |
+ instead of pure bit_position comparisons. |
33 |
+ |
34 |
+ * gcc.c-torture/compile/pr85704.c: New test. |
35 |
+ |
36 |
+ |
37 |
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-8-branch@263199 138bc75d-0d04-0410-961f-82ee72b054a4 |
38 |
+--- |
39 |
+ gcc/c/c-typeck.c | 86 +++++++++++++++---- |
40 |
+ gcc/testsuite/gcc.c-torture/compile/pr85704.c | 10 +++ |
41 |
+ 4 files changed, 91 insertions(+), 17 deletions(-) |
42 |
+ create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr85704.c |
43 |
+ |
44 |
+--- a/gcc/c/c-typeck.c |
45 |
++++ b/gcc/c/c-typeck.c |
46 |
+@@ -9316,6 +9316,65 @@ output_init_element (location_t loc, tree value, tree origtype, |
47 |
+ output_pending_init_elements (0, braced_init_obstack); |
48 |
+ } |
49 |
+ |
50 |
++/* For two FIELD_DECLs in the same chain, return -1 if field1 |
51 |
++ comes before field2, 1 if field1 comes after field2 and |
52 |
++ 0 if field1 == field2. */ |
53 |
++ |
54 |
++static int |
55 |
++init_field_decl_cmp (tree field1, tree field2) |
56 |
++{ |
57 |
++ if (field1 == field2) |
58 |
++ return 0; |
59 |
++ |
60 |
++ tree bitpos1 = bit_position (field1); |
61 |
++ tree bitpos2 = bit_position (field2); |
62 |
++ if (tree_int_cst_equal (bitpos1, bitpos2)) |
63 |
++ { |
64 |
++ /* If one of the fields has non-zero bitsize, then that |
65 |
++ field must be the last one in a sequence of zero |
66 |
++ sized fields, fields after it will have bigger |
67 |
++ bit_position. */ |
68 |
++ if (TREE_TYPE (field1) != error_mark_node |
69 |
++ && COMPLETE_TYPE_P (TREE_TYPE (field1)) |
70 |
++ && integer_nonzerop (TREE_TYPE (field1))) |
71 |
++ return 1; |
72 |
++ if (TREE_TYPE (field2) != error_mark_node |
73 |
++ && COMPLETE_TYPE_P (TREE_TYPE (field2)) |
74 |
++ && integer_nonzerop (TREE_TYPE (field2))) |
75 |
++ return -1; |
76 |
++ /* Otherwise, fallback to DECL_CHAIN walk to find out |
77 |
++ which field comes earlier. Walk chains of both |
78 |
++ fields, so that if field1 and field2 are close to each |
79 |
++ other in either order, it is found soon even for large |
80 |
++ sequences of zero sized fields. */ |
81 |
++ tree f1 = field1, f2 = field2; |
82 |
++ while (1) |
83 |
++ { |
84 |
++ f1 = DECL_CHAIN (f1); |
85 |
++ f2 = DECL_CHAIN (f2); |
86 |
++ if (f1 == NULL_TREE) |
87 |
++ { |
88 |
++ gcc_assert (f2); |
89 |
++ return 1; |
90 |
++ } |
91 |
++ if (f2 == NULL_TREE) |
92 |
++ return -1; |
93 |
++ if (f1 == field2) |
94 |
++ return -1; |
95 |
++ if (f2 == field1) |
96 |
++ return 1; |
97 |
++ if (!tree_int_cst_equal (bit_position (f1), bitpos1)) |
98 |
++ return 1; |
99 |
++ if (!tree_int_cst_equal (bit_position (f2), bitpos1)) |
100 |
++ return -1; |
101 |
++ } |
102 |
++ } |
103 |
++ else if (tree_int_cst_lt (bitpos1, bitpos2)) |
104 |
++ return -1; |
105 |
++ else |
106 |
++ return 1; |
107 |
++} |
108 |
++ |
109 |
+ /* Output any pending elements which have become next. |
110 |
+ As we output elements, constructor_unfilled_{fields,index} |
111 |
+ advances, which may cause other elements to become next; |
112 |
+@@ -9387,25 +9446,18 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack) |
113 |
+ } |
114 |
+ else if (RECORD_OR_UNION_TYPE_P (constructor_type)) |
115 |
+ { |
116 |
+- tree ctor_unfilled_bitpos, elt_bitpos; |
117 |
+- |
118 |
+ /* If the current record is complete we are done. */ |
119 |
+ if (constructor_unfilled_fields == NULL_TREE) |
120 |
+ break; |
121 |
+ |
122 |
+- ctor_unfilled_bitpos = bit_position (constructor_unfilled_fields); |
123 |
+- elt_bitpos = bit_position (elt->purpose); |
124 |
+- /* We can't compare fields here because there might be empty |
125 |
+- fields in between. */ |
126 |
+- if (tree_int_cst_equal (elt_bitpos, ctor_unfilled_bitpos)) |
127 |
+- { |
128 |
+- constructor_unfilled_fields = elt->purpose; |
129 |
+- output_init_element (input_location, elt->value, elt->origtype, |
130 |
+- true, TREE_TYPE (elt->purpose), |
131 |
+- elt->purpose, false, false, |
132 |
+- braced_init_obstack); |
133 |
+- } |
134 |
+- else if (tree_int_cst_lt (ctor_unfilled_bitpos, elt_bitpos)) |
135 |
++ int cmp = init_field_decl_cmp (constructor_unfilled_fields, |
136 |
++ elt->purpose); |
137 |
++ if (cmp == 0) |
138 |
++ output_init_element (input_location, elt->value, elt->origtype, |
139 |
++ true, TREE_TYPE (elt->purpose), |
140 |
++ elt->purpose, false, false, |
141 |
++ braced_init_obstack); |
142 |
++ else if (cmp < 0) |
143 |
+ { |
144 |
+ /* Advance to the next smaller node. */ |
145 |
+ if (elt->left) |
146 |
+@@ -9431,8 +9483,8 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack) |
147 |
+ elt = elt->parent; |
148 |
+ elt = elt->parent; |
149 |
+ if (elt |
150 |
+- && (tree_int_cst_lt (ctor_unfilled_bitpos, |
151 |
+- bit_position (elt->purpose)))) |
152 |
++ && init_field_decl_cmp (constructor_unfilled_fields, |
153 |
++ elt->purpose) < 0) |
154 |
+ { |
155 |
+ next = elt->purpose; |
156 |
+ break; |
157 |
+--- /dev/null |
158 |
++++ b/gcc/testsuite/gcc.c-torture/compile/pr85704.c |
159 |
+@@ -0,0 +1,10 @@ |
160 |
++/* PR c/85704 */ |
161 |
++ |
162 |
++struct C { struct {} c; }; |
163 |
++struct D { int d; struct C e; int f; }; |
164 |
++ |
165 |
++void |
166 |
++foo (struct D *x) |
167 |
++{ |
168 |
++ *x = (struct D) { .e = (struct C) { .c = {} } }; |
169 |
++} |
170 |
+-- |
171 |
+2.19.1 |
172 |
+ |
173 |
|
174 |
diff --git a/8.2.0/gentoo/README.history b/8.2.0/gentoo/README.history |
175 |
index 776f49d..d85e258 100644 |
176 |
--- a/8.2.0/gentoo/README.history |
177 |
+++ b/8.2.0/gentoo/README.history |
178 |
@@ -1,3 +1,6 @@ |
179 |
+1.5 TODO |
180 |
+ + 111_all_ubd-hog-PR85704.patch |
181 |
+ |
182 |
1.4 01 Oct 2018 |
183 |
+ 105_all_libgfortran-Werror.patch |
184 |
+ 106_all_libgomp-Werror.patch |