~angelsl/ubuntu/wily/gcc-5/mips-cross

« back to all changes in this revision

Viewing changes to debian/patches/go-escape-analysis6.diff

  • Committer: angelsl
  • Date: 2015-10-30 03:30:35 UTC
  • Revision ID: angelsl-20151030033035-rmug41zm8hyjgisg
Original import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# DP: escape: Analyze multiple result type assertions.
 
2
    
 
3
    For multi-result type assertions, the object being converted is hidden
 
4
    behind unsafe conversions and calls to runtime methods.  This change
 
5
    allows the analysis to make edges between the result of the assertion
 
6
    and the object being asserted.
 
7
 
 
8
Index: b/src/gcc/go/gofrontend/expressions.h
 
9
===================================================================
 
10
--- a/src/gcc/go/gofrontend/expressions.h
 
11
+++ b/src/gcc/go/gofrontend/expressions.h
 
12
@@ -32,6 +32,7 @@ class Temporary_reference_expression;
 
13
 class Set_and_use_temporary_expression;
 
14
 class String_expression;
 
15
 class Type_conversion_expression;
 
16
+class Unsafe_type_conversion_expression;
 
17
 class Unary_expression;
 
18
 class Binary_expression;
 
19
 class Call_expression;
 
20
@@ -571,6 +572,15 @@ class Expression
 
21
   conversion_expression()
 
22
   { return this->convert<Type_conversion_expression, EXPRESSION_CONVERSION>(); }
 
23
 
 
24
+  // If this is an unsafe conversion expression, return the
 
25
+  // Unsafe_type_conversion_expression structure.  Otherwise, return NULL.
 
26
+  Unsafe_type_conversion_expression*
 
27
+  unsafe_conversion_expression()
 
28
+  {
 
29
+    return this->convert<Unsafe_type_conversion_expression,
 
30
+                        EXPRESSION_UNSAFE_CONVERSION>();
 
31
+  }
 
32
+
 
33
   // Return whether this is the expression nil.
 
34
   bool
 
35
   is_nil_expression() const
 
36
@@ -1505,6 +1515,57 @@ class Type_conversion_expression : publi
 
37
   bool may_convert_function_types_;
 
38
 };
 
39
 
 
40
+// An unsafe type conversion, used to pass values to builtin functions.
 
41
+
 
42
+class Unsafe_type_conversion_expression : public Expression
 
43
+{
 
44
+ public:
 
45
+  Unsafe_type_conversion_expression(Type* type, Expression* expr,
 
46
+                                   Location location)
 
47
+    : Expression(EXPRESSION_UNSAFE_CONVERSION, location),
 
48
+      type_(type), expr_(expr)
 
49
+  { }
 
50
+
 
51
+  Expression*
 
52
+  expr() const
 
53
+  { return this->expr_; }
 
54
+
 
55
+ protected:
 
56
+  int
 
57
+  do_traverse(Traverse* traverse);
 
58
+
 
59
+  bool
 
60
+  do_is_immutable() const;
 
61
+
 
62
+  Type*
 
63
+  do_type()
 
64
+  { return this->type_; }
 
65
+
 
66
+  void
 
67
+  do_determine_type(const Type_context*)
 
68
+  { this->expr_->determine_type_no_context(); }
 
69
+
 
70
+  Expression*
 
71
+  do_copy()
 
72
+  {
 
73
+    return new Unsafe_type_conversion_expression(this->type_,
 
74
+                                                this->expr_->copy(),
 
75
+                                                this->location());
 
76
+  }
 
77
+
 
78
+  Bexpression*
 
79
+  do_get_backend(Translate_context*);
 
80
+
 
81
+  void
 
82
+  do_dump_expression(Ast_dump_context*) const;
 
83
+
 
84
+ private:
 
85
+  // The type to convert to.
 
86
+  Type* type_;
 
87
+  // The expression to convert.
 
88
+  Expression* expr_;
 
89
+};
 
90
+
 
91
 // A Unary expression.
 
92
 
 
93
 class Unary_expression : public Expression
 
94
@@ -2024,6 +2085,10 @@ class Call_result_expression : public Ex
 
95
   call() const
 
96
   { return this->call_; }
 
97
 
 
98
+  unsigned int
 
99
+  index() const
 
100
+  { return this->index_; }
 
101
+
 
102
  protected:
 
103
   int
 
104
   do_traverse(Traverse*);
 
105
Index: b/src/gcc/go/gofrontend/escape.cc
 
106
===================================================================
 
107
--- a/src/gcc/go/gofrontend/escape.cc
 
108
+++ b/src/gcc/go/gofrontend/escape.cc
 
109
@@ -547,6 +547,41 @@ Build_connection_graphs::resolve_var_ref
 
110
        expr = expr->type_guard_expression()->expr();
 
111
        break;
 
112
 
 
113
+      case Expression::EXPRESSION_UNSAFE_CONVERSION:
 
114
+       {
 
115
+         Expression* e = expr->unsafe_conversion_expression()->expr();
 
116
+         if (e->call_result_expression() != NULL
 
117
+             && e->call_result_expression()->index() == 0)
 
118
+           {
 
119
+             // a, ok := p.(T) gets lowered into a call to one of the interface
 
120
+             // to type conversion functions instead of a type guard expression.
 
121
+             // We only want to make a connection between a and p, the bool
 
122
+             // result should not escape because p escapes.
 
123
+             e = e->call_result_expression()->call();
 
124
+
 
125
+             Named_object* fn =
 
126
+               e->call_expression()->fn()->func_expression()->named_object();
 
127
+             std::string fn_name = fn->name();
 
128
+             if (fn->package() == NULL
 
129
+                 && fn->is_function_declaration()
 
130
+                 && !fn->func_declaration_value()->asm_name().empty())
 
131
+               {
 
132
+                 if (fn_name == "ifaceI2E2"
 
133
+                     || fn_name == "ifaceI2I2")
 
134
+                   e = e->call_expression()->args()->at(0);
 
135
+                 else if (fn_name == "ifaceE2I2"
 
136
+                          || fn_name == "ifaceI2I2"
 
137
+                          || fn_name == "ifaceE2T2P"
 
138
+                          || fn_name == "ifaceI2T2P"
 
139
+                          || fn_name == "ifaceE2T2"
 
140
+                          || fn_name == "ifaceI2T2")
 
141
+                   e = e->call_expression()->args()->at(1);
 
142
+               }
 
143
+           }
 
144
+         expr = e;
 
145
+       }
 
146
+       break;
 
147
+
 
148
       default:
 
149
        done = true;
 
150
        break;
 
151
Index: b/src/gcc/go/gofrontend/expressions.cc
 
152
===================================================================
 
153
--- a/src/gcc/go/gofrontend/expressions.cc
 
154
+++ b/src/gcc/go/gofrontend/expressions.cc
 
155
@@ -3391,52 +3391,7 @@ Expression::make_cast(Type* type, Expres
 
156
   return new Type_conversion_expression(type, val, location);
 
157
 }
 
158
 
 
159
-// An unsafe type conversion, used to pass values to builtin functions.
 
160
-
 
161
-class Unsafe_type_conversion_expression : public Expression
 
162
-{
 
163
- public:
 
164
-  Unsafe_type_conversion_expression(Type* type, Expression* expr,
 
165
-                                   Location location)
 
166
-    : Expression(EXPRESSION_UNSAFE_CONVERSION, location),
 
167
-      type_(type), expr_(expr)
 
168
-  { }
 
169
-
 
170
- protected:
 
171
-  int
 
172
-  do_traverse(Traverse* traverse);
 
173
-
 
174
-  bool
 
175
-  do_is_immutable() const;
 
176
-
 
177
-  Type*
 
178
-  do_type()
 
179
-  { return this->type_; }
 
180
-
 
181
-  void
 
182
-  do_determine_type(const Type_context*)
 
183
-  { this->expr_->determine_type_no_context(); }
 
184
-
 
185
-  Expression*
 
186
-  do_copy()
 
187
-  {
 
188
-    return new Unsafe_type_conversion_expression(this->type_,
 
189
-                                                this->expr_->copy(),
 
190
-                                                this->location());
 
191
-  }
 
192
-
 
193
-  Bexpression*
 
194
-  do_get_backend(Translate_context*);
 
195
-
 
196
-  void
 
197
-  do_dump_expression(Ast_dump_context*) const;
 
198
-
 
199
- private:
 
200
-  // The type to convert to.
 
201
-  Type* type_;
 
202
-  // The expression to convert.
 
203
-  Expression* expr_;
 
204
-};
 
205
+// Class Unsafe_type_conversion_expression.
 
206
 
 
207
 // Traversal.
 
208