~ubuntu-branches/debian/sid/gnat-4.4/sid

« back to all changes in this revision

Viewing changes to debian/patches/pr43323.diff

  • Committer: Bazaar Package Importer
  • Author(s): Ludovic Brenta
  • Date: 2010-05-09 23:28:13 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100509232813-bykj33gg0mc34opr
Tags: 4.4.4-2
* debian/control.m4, debian/control: make upgrades from Lenny work without
  broken packages or hard decisions.
  (gnat-4.4): replace all previous versions of gnat-X.Y.
  (libgnat{vsn,prj}4.4-dev):
  - Replace the corresponding 4.3 package in addition to Conflicting with it.
  - Suggest the -dbg package, too.
  (libgnat{vsn,prj}4.4-dbg):
  - Depend on the -dev package, too.
  - Do not recommend gnat-gdb, superseded by gdb.
  (libgnatprj4.4-dbg): do not recommend libgnatprj-dev, no longer in the archive.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# DP: Fix PR middle-end/43323 wrong-code for bitfields
 
2
 
 
3
This patch fixes PR middle-end/43323, wrong-code for bitfields
 
4
and type casts.  This is a 4.4 regression, 4.3 and 4.5 work.
 
5
 
 
6
For 4.5 the bug was fixed by r148631, Adam Nemet's STRIP_NOPS
 
7
conversion patch.  This patch backports that patch to 4.4, and
 
8
adds the new PR43323 test case.
 
9
 
 
10
Bootstrapped and regression tested with all default languages
 
11
on {i686,x86_64,sparc64,powerpc64}-unknown-linux and
 
12
armv5tel-unknown-linux-gnueabi.  Both Adam's original test case
 
13
and the new PR43323 one pass with this patch but fail without it.
 
14
 
 
15
Ok for 4.4? (I don't have svn write access.)
 
16
 
 
17
gcc/
 
18
 
 
19
2010-03-13  Mikael Pettersson  <mikpe@it.uu.se>
 
20
 
 
21
        PR middle-end/43323
 
22
 
 
23
        Backport from mainline:
 
24
        2009-06-17  Adam Nemet  <anemet@caviumnetworks.com>
 
25
 
 
26
        * tree.h (STRIP_NOPS, STRIP_SIGN_NOPS,
 
27
        STRIP_USELESS_TYPE_CONVERSION): Use tree_strip_nop_conversions,
 
28
        tree_strip_sign_nop_conversions and
 
29
        tree_ssa_strip_useless_type_conversions rather than stripping
 
30
        the operations here.
 
31
        (tree_strip_nop_conversions, tree_strip_sign_nop_conversions):
 
32
        Declare them.
 
33
        * gimple.h (tree_ssa_strip_useless_type_conversions): Declare it.
 
34
        * tree-ssa.c (tree_ssa_strip_useless_type_conversions): New function.
 
35
        * tree.c (tree_nop_conversion, tree_sign_nop_conversion,
 
36
        tree_strip_nop_conversions, tree_strip_sign_nop_conversions): New
 
37
        functions.
 
38
 
 
39
gcc/testsuite/
 
40
 
 
41
2010-03-13  Mikael Pettersson  <mikpe@it.uu.se>
 
42
 
 
43
        PR middle-end/43323
 
44
 
 
45
        * gcc.c-torture/execute/pr43323.c: New test.
 
46
 
 
47
        Backport from mainline:
 
48
        2009-06-17  Adam Nemet  <anemet@caviumnetworks.com>
 
49
 
 
50
        * gcc.c-torture/execute/bitfld-5.c: New test.
 
51
 
 
52
diff -rupN a/src/gcc/gimple.h b/src/gcc/gimple.h
 
53
--- a/src/gcc/gimple.h  2009-05-18 12:13:43.000000000 +0200
 
54
+++ b/src/gcc/gimple.h  2010-03-13 10:59:57.000000000 +0100
 
55
@@ -1020,6 +1020,7 @@ extern void gimple_add_to_addresses_take
 
56
 
 
57
 /* In tree-ssa.c  */
 
58
 extern bool tree_ssa_useless_type_conversion (tree);
 
59
+extern tree tree_ssa_strip_useless_type_conversions (tree);
 
60
 extern bool useless_type_conversion_p (tree, tree);
 
61
 extern bool types_compatible_p (tree, tree);
 
62
 
 
63
diff -rupN a/src/gcc/testsuite/gcc.c-torture/execute/bitfld-5.c b/src/gcc/testsuite/gcc.c-torture/execute/bitfld-5.c
 
64
--- a/src/gcc/testsuite/gcc.c-torture/execute/bitfld-5.c        1970-01-01 01:00:00.000000000 +0100
 
65
+++ b/src/gcc/testsuite/gcc.c-torture/execute/bitfld-5.c        2010-03-13 10:59:57.000000000 +0100
 
66
@@ -0,0 +1,35 @@
 
67
+/* See http://gcc.gnu.org/ml/gcc/2009-06/msg00072.html.  */
 
68
+
 
69
+extern void abort (void);
 
70
+
 
71
+struct s
 
72
+{
 
73
+  unsigned long long a:2;
 
74
+  unsigned long long b:40;
 
75
+  unsigned long long c:22;
 
76
+};
 
77
+
 
78
+__attribute__ ((noinline)) void
 
79
+g (unsigned long long a, unsigned long long b)
 
80
+{
 
81
+  asm ("");
 
82
+  if (a != b)
 
83
+    abort ();
 
84
+}
 
85
+
 
86
+__attribute__ ((noinline)) void
 
87
+f (struct s s, unsigned long long b)
 
88
+{
 
89
+  asm ("");
 
90
+  g (((unsigned long long) (s.b-8)) + 8, b);
 
91
+}
 
92
+
 
93
+int
 
94
+main ()
 
95
+{
 
96
+  struct s s = {1, 10, 3};
 
97
+  struct s t = {1, 2, 3};
 
98
+  f (s, 10);
 
99
+  f (t, 0x10000000002);
 
100
+  return 0;
 
101
+}
 
102
diff -rupN a/src/gcc/testsuite/gcc.c-torture/execute/pr43323.c b/src/gcc/testsuite/gcc.c-torture/execute/pr43323.c
 
103
--- a/src/gcc/testsuite/gcc.c-torture/execute/pr43323.c 1970-01-01 01:00:00.000000000 +0100
 
104
+++ b/src/gcc/testsuite/gcc.c-torture/execute/pr43323.c 2010-03-13 10:59:57.000000000 +0100
 
105
@@ -0,0 +1,14 @@
 
106
+/* PR middle-end/43323 */
 
107
+
 
108
+extern void abort (void);
 
109
+
 
110
+int main()
 
111
+{
 
112
+  struct { unsigned bar:1; } foo;
 
113
+  foo.bar = 0x1;
 
114
+  if ((unsigned char)(foo.bar * 0xfe) != 0xfeu)
 
115
+    abort ();
 
116
+  if ((unsigned char)(foo.bar * 0xff) != 0xffu)
 
117
+    abort ();
 
118
+  return 0;
 
119
+}
 
120
diff -rupN a/src/gcc/tree-ssa.c b/src/gcc/tree-ssa.c
 
121
--- a/src/gcc/tree-ssa.c        2009-08-03 21:27:32.000000000 +0200
 
122
+++ b/src/gcc/tree-ssa.c        2010-03-13 10:59:57.000000000 +0100
 
123
@@ -1271,6 +1271,18 @@ tree_ssa_useless_type_conversion (tree e
 
124
   return false;
 
125
 }
 
126
 
 
127
+/* Strip conversions from EXP according to
 
128
+   tree_ssa_useless_type_conversion and return the resulting
 
129
+   expression.  */
 
130
+
 
131
+tree
 
132
+tree_ssa_strip_useless_type_conversions (tree exp)
 
133
+{
 
134
+  while (tree_ssa_useless_type_conversion (exp))
 
135
+    exp = TREE_OPERAND (exp, 0);
 
136
+  return exp;
 
137
+}
 
138
+
 
139
 
 
140
 /* Internal helper for walk_use_def_chains.  VAR, FN and DATA are as
 
141
    described in walk_use_def_chains.
 
142
diff -rupN a/src/gcc/tree.c b/src/gcc/tree.c
 
143
--- a/src/gcc/tree.c    2009-07-20 16:39:32.000000000 +0200
 
144
+++ b/src/gcc/tree.c    2010-03-13 10:59:57.000000000 +0100
 
145
@@ -9094,6 +9094,79 @@ tree_nonartificial_location (tree exp)
 
146
     return EXPR_LOCATION (exp);
 
147
 }
 
148
 
 
149
+/* Return true iff conversion in EXP generates no instruction.  Mark
 
150
+   it inline so that we fully inline into the stripping functions even
 
151
+   though we have two uses of this function.  */
 
152
+
 
153
+static inline bool
 
154
+tree_nop_conversion (const_tree exp)
 
155
+{
 
156
+  tree outer_type, inner_type;
 
157
+
 
158
+  if (!CONVERT_EXPR_P (exp)
 
159
+      && TREE_CODE (exp) != NON_LVALUE_EXPR)
 
160
+    return false;
 
161
+  if (TREE_OPERAND (exp, 0) == error_mark_node)
 
162
+    return false;
 
163
+
 
164
+  outer_type = TREE_TYPE (exp);
 
165
+  inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
 
166
+
 
167
+  /* Use precision rather then machine mode when we can, which gives
 
168
+     the correct answer even for submode (bit-field) types.  */
 
169
+  if ((INTEGRAL_TYPE_P (outer_type)
 
170
+       || POINTER_TYPE_P (outer_type)
 
171
+       || TREE_CODE (outer_type) == OFFSET_TYPE)
 
172
+      && (INTEGRAL_TYPE_P (inner_type)
 
173
+         || POINTER_TYPE_P (inner_type)
 
174
+         || TREE_CODE (inner_type) == OFFSET_TYPE))
 
175
+    return TYPE_PRECISION (outer_type) == TYPE_PRECISION (inner_type);
 
176
+
 
177
+  /* Otherwise fall back on comparing machine modes (e.g. for
 
178
+     aggregate types, floats).  */
 
179
+  return TYPE_MODE (outer_type) == TYPE_MODE (inner_type);
 
180
+}
 
181
+
 
182
+/* Return true iff conversion in EXP generates no instruction.  Don't
 
183
+   consider conversions changing the signedness.  */
 
184
+
 
185
+static bool
 
186
+tree_sign_nop_conversion (const_tree exp)
 
187
+{
 
188
+  tree outer_type, inner_type;
 
189
+
 
190
+  if (!tree_nop_conversion (exp))
 
191
+    return false;
 
192
+
 
193
+  outer_type = TREE_TYPE (exp);
 
194
+  inner_type = TREE_TYPE (TREE_OPERAND (exp, 0));
 
195
+
 
196
+  return (TYPE_UNSIGNED (outer_type) == TYPE_UNSIGNED (inner_type)
 
197
+         && POINTER_TYPE_P (outer_type) == POINTER_TYPE_P (inner_type));
 
198
+}
 
199
+
 
200
+/* Strip conversions from EXP according to tree_nop_conversion and
 
201
+   return the resulting expression.  */
 
202
+
 
203
+tree
 
204
+tree_strip_nop_conversions (tree exp)
 
205
+{
 
206
+  while (tree_nop_conversion (exp))
 
207
+    exp = TREE_OPERAND (exp, 0);
 
208
+  return exp;
 
209
+}
 
210
+
 
211
+/* Strip conversions from EXP according to tree_sign_nop_conversion
 
212
+   and return the resulting expression.  */
 
213
+
 
214
+tree
 
215
+tree_strip_sign_nop_conversions (tree exp)
 
216
+{
 
217
+  while (tree_sign_nop_conversion (exp))
 
218
+    exp = TREE_OPERAND (exp, 0);
 
219
+  return exp;
 
220
+}
 
221
+
 
222
 
 
223
 /* These are the hash table functions for the hash table of OPTIMIZATION_NODEq
 
224
    nodes.  */
 
225
diff -rupN a/src/gcc/tree.h b/src/gcc/tree.h
 
226
--- a/src/gcc/tree.h    2009-06-02 09:18:16.000000000 +0200
 
227
+++ b/src/gcc/tree.h    2010-03-13 10:59:57.000000000 +0100
 
228
@@ -974,30 +974,17 @@ extern void omp_clause_range_check_faile
 
229
   case NOP_EXPR:                                               \
 
230
   case CONVERT_EXPR
 
231
 
 
232
-/* Given an expression as a tree, strip any NON_LVALUE_EXPRs and NOP_EXPRs
 
233
-   that don't change the machine mode.  */
 
234
+/* Given an expression as a tree, strip any conversion that generates
 
235
+   no instruction.  Accepts both tree and const_tree arguments since
 
236
+   we are not modifying the tree itself.  */
 
237
 
 
238
-#define STRIP_NOPS(EXP)                                                \
 
239
-  while ((CONVERT_EXPR_P (EXP)                                 \
 
240
-         || TREE_CODE (EXP) == NON_LVALUE_EXPR)                \
 
241
-        && TREE_OPERAND (EXP, 0) != error_mark_node            \
 
242
-        && (TYPE_MODE (TREE_TYPE (EXP))                        \
 
243
-            == TYPE_MODE (TREE_TYPE (TREE_OPERAND (EXP, 0))))) \
 
244
-    (EXP) = TREE_OPERAND (EXP, 0)
 
245
+#define STRIP_NOPS(EXP) \
 
246
+  (EXP) = tree_strip_nop_conversions (CONST_CAST_TREE (EXP))
 
247
 
 
248
 /* Like STRIP_NOPS, but don't let the signedness change either.  */
 
249
 
 
250
 #define STRIP_SIGN_NOPS(EXP) \
 
251
-  while ((CONVERT_EXPR_P (EXP)                                 \
 
252
-         || TREE_CODE (EXP) == NON_LVALUE_EXPR)                \
 
253
-        && TREE_OPERAND (EXP, 0) != error_mark_node            \
 
254
-        && (TYPE_MODE (TREE_TYPE (EXP))                        \
 
255
-            == TYPE_MODE (TREE_TYPE (TREE_OPERAND (EXP, 0))))  \
 
256
-        && (TYPE_UNSIGNED (TREE_TYPE (EXP))                    \
 
257
-            == TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (EXP, 0)))) \
 
258
-        && (POINTER_TYPE_P (TREE_TYPE (EXP))                   \
 
259
-            == POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (EXP, 0))))) \
 
260
-    (EXP) = TREE_OPERAND (EXP, 0)
 
261
+  (EXP) = tree_strip_sign_nop_conversions (CONST_CAST_TREE (EXP))
 
262
 
 
263
 /* Like STRIP_NOPS, but don't alter the TREE_TYPE either.  */
 
264
 
 
265
@@ -1012,9 +999,8 @@ extern void omp_clause_range_check_faile
 
266
 /* Remove unnecessary type conversions according to
 
267
    tree_ssa_useless_type_conversion.  */
 
268
 
 
269
-#define STRIP_USELESS_TYPE_CONVERSION(EXP)                             \
 
270
-      while (tree_ssa_useless_type_conversion (EXP))                   \
 
271
-       EXP = TREE_OPERAND (EXP, 0)
 
272
+#define STRIP_USELESS_TYPE_CONVERSION(EXP) \
 
273
+  (EXP) = tree_ssa_strip_useless_type_conversions (EXP)
 
274
 
 
275
 /* Nonzero if TYPE represents an integral type.  Note that we do not
 
276
    include COMPLEX types here.  Keep these checks in ascending code
 
277
@@ -4702,6 +4688,8 @@ extern bool stdarg_p (tree);
 
278
 extern bool prototype_p (tree);
 
279
 extern int function_args_count (tree);
 
280
 extern bool auto_var_in_fn_p (const_tree, const_tree);
 
281
+extern tree tree_strip_nop_conversions (tree);
 
282
+extern tree tree_strip_sign_nop_conversions (tree);
 
283
 
 
284
 /* In gimplify.c */
 
285
 extern tree unshare_expr (tree);