diff options
Diffstat (limited to 'gcc/go/gofrontend/escape.cc')
-rw-r--r-- | gcc/go/gofrontend/escape.cc | 177 |
1 files changed, 91 insertions, 86 deletions
diff --git a/gcc/go/gofrontend/escape.cc b/gcc/go/gofrontend/escape.cc index ea4978bb555..1c810769d22 100644 --- a/gcc/go/gofrontend/escape.cc +++ b/gcc/go/gofrontend/escape.cc @@ -17,6 +17,7 @@ #include "escape.h" #include "ast-dump.h" #include "go-optimize.h" +#include "go-diagnostics.h" // class Node. @@ -737,9 +738,9 @@ Gogo::analyze_escape() { Node::Escape_state* state = (*n)->state(context, NULL); if (((*n)->encoding() & ESCAPE_MASK) == int(Node::ESCAPE_NONE)) - inform((*n)->location(), "%s %s does not escape", - strip_packed_prefix(this, debug_function_name(state->fn)).c_str(), - (*n)->ast_format(this).c_str()); + go_inform((*n)->location(), "%s %s does not escape", + strip_packed_prefix(this, debug_function_name(state->fn)).c_str(), + (*n)->ast_format(this).c_str()); } // TODO(cmang): Which objects in context->noesc actually don't escape. } @@ -1039,9 +1040,9 @@ Escape_analysis_assign::statement(Block*, size_t*, Statement* s) { Node* n = Node::make_node(s); std::string fn_name = this->context_->current_function_name(); - inform(s->location(), "[%d] %s esc: %s", - this->context_->loop_depth(), fn_name.c_str(), - n->ast_format(gogo).c_str()); + go_inform(s->location(), "[%d] %s esc: %s", + this->context_->loop_depth(), fn_name.c_str(), + n->ast_format(gogo).c_str()); } switch (s->classification()) @@ -1074,9 +1075,9 @@ Escape_analysis_assign::statement(Block*, size_t*, Statement* s) std::string label_type = (label_stmt->label()->looping() ? "looping" : "nonlooping"); - inform(s->location(), "%s %s label", - label_stmt->label()->name().c_str(), - label_type.c_str()); + go_inform(s->location(), "%s %s label", + label_stmt->label()->name().c_str(), + label_type.c_str()); } } break; @@ -1163,7 +1164,7 @@ Escape_analysis_assign::expression(Expression** pexpr) && n->is_big(this->context_)) { if (debug_level > 1) - inform((*pexpr)->location(), "too large for stack"); + go_inform((*pexpr)->location(), "too large for stack"); n->set_encoding(Node::ESCAPE_HEAP); (*pexpr)->address_taken(true); this->assign(this->context_->sink(), n); @@ -1176,9 +1177,9 @@ Escape_analysis_assign::expression(Expression** pexpr) { Node* n = Node::make_node(*pexpr); std::string fn_name = this->context_->current_function_name(); - inform((*pexpr)->location(), "[%d] %s esc: %s", - this->context_->loop_depth(), fn_name.c_str(), - n->ast_format(gogo).c_str()); + go_inform((*pexpr)->location(), "[%d] %s esc: %s", + this->context_->loop_depth(), fn_name.c_str(), + n->ast_format(gogo).c_str()); } switch ((*pexpr)->classification()) @@ -1210,7 +1211,7 @@ Escape_analysis_assign::expression(Expression** pexpr) this->assign_deref(this->context_->sink(), appended); if (debug_level > 2) - error_at((*pexpr)->location(), + go_error_at((*pexpr)->location(), "special treatment of append(slice1, slice2...)"); // The content of the original slice leaks as well. @@ -1507,9 +1508,9 @@ Escape_analysis_assign::call(Call_expression* call) ++p) { if (debug_level > 2) - inform(call->location(), - "esccall:: indirect call <- %s, untracked", - (*p)->ast_format(gogo).c_str()); + go_inform(call->location(), + "esccall:: indirect call <- %s, untracked", + (*p)->ast_format(gogo).c_str()); this->assign(this->context_->sink(), *p); } @@ -1523,8 +1524,8 @@ Escape_analysis_assign::call(Call_expression* call) && !fntype->is_tagged()) { if (debug_level > 2) - inform(call->location(), "esccall:: %s in recursive group", - call_node->ast_format(gogo).c_str()); + go_inform(call->location(), "esccall:: %s in recursive group", + call_node->ast_format(gogo).c_str()); Function* f = fn->named_object()->func_value(); const Bindings* callee_bindings = f->block()->bindings(); @@ -1592,8 +1593,8 @@ Escape_analysis_assign::call(Call_expression* call) for (; p != arg_nodes.end(); ++p) { if (debug_level > 2) - inform(call->location(), "esccall:: ... <- %s, untracked", - (*p)->ast_format(gogo).c_str()); + go_inform(call->location(), "esccall:: ... <- %s, untracked", + (*p)->ast_format(gogo).c_str()); this->assign(this->context_->sink(), *p); } } @@ -1602,12 +1603,14 @@ Escape_analysis_assign::call(Call_expression* call) } if (debug_level > 2) - inform(call->location(), "esccall:: %s not recursive", - call_node->ast_format(gogo).c_str()); + go_inform(call->location(), "esccall:: %s not recursive", + call_node->ast_format(gogo).c_str()); Node::Escape_state* call_state = call_node->state(this->context_, NULL); if (!call_state->retvals.empty()) - error("esc already decorated call %s", call_node->ast_format(gogo).c_str()); + go_error_at(Linemap::unknown_location(), + "esc already decorated call %s", + call_node->ast_format(gogo).c_str()); this->context_->init_retvals(call_node, fntype); // Receiver. @@ -1676,8 +1679,8 @@ Escape_analysis_assign::call(Call_expression* call) for (; p != arg_nodes.end(); ++p) { if (debug_level > 2) - inform(call->location(), "esccall:: ... <- %s, untracked", - (*p)->ast_format(gogo).c_str()); + go_inform(call->location(), "esccall:: ... <- %s, untracked", + (*p)->ast_format(gogo).c_str()); this->assign(this->context_->sink(), *p); } } @@ -1695,13 +1698,13 @@ Escape_analysis_assign::assign(Node* dst, Node* src) Gogo* gogo = this->context_->gogo(); int debug_level = gogo->debug_escape_level(); if (debug_level > 1) - inform(dst->location(), "[%d] %s escassign: %s(%s)[%s] = %s(%s)[%s]", - this->context_->loop_depth(), - strip_packed_prefix(gogo, this->context_->current_function_name()).c_str(), - dst->ast_format(gogo).c_str(), dst->details().c_str(), - dst->op_format().c_str(), - src->ast_format(gogo).c_str(), src->details().c_str(), - src->op_format().c_str()); + go_inform(dst->location(), "[%d] %s escassign: %s(%s)[%s] = %s(%s)[%s]", + this->context_->loop_depth(), + strip_packed_prefix(gogo, this->context_->current_function_name()).c_str(), + dst->ast_format(gogo).c_str(), dst->details().c_str(), + dst->op_format().c_str(), + src->ast_format(gogo).c_str(), src->details().c_str(), + src->op_format().c_str()); if (dst->expr() != NULL) { @@ -2123,8 +2126,8 @@ Escape_analysis_assign::assign_from_note(std::string* note, } if (this->context_->gogo()->debug_escape_level() > 2) - inform(src->location(), "assignfromtag:: src= em=%s", - Escape_note::make_tag(enc).c_str()); + go_inform(src->location(), "assignfromtag:: src= em=%s", + Escape_note::make_tag(enc).c_str()); if (enc == Node::ESCAPE_UNKNOWN) { @@ -2194,8 +2197,8 @@ Escape_analysis_assign::flows(Node* dst, Node* src) Gogo* gogo = this->context_->gogo(); if (gogo->debug_escape_level() > 2) - inform(Linemap::unknown_location(), "flows:: %s <- %s", - dst->ast_format(gogo).c_str(), src->ast_format(gogo).c_str()); + go_inform(Linemap::unknown_location(), "flows:: %s <- %s", + dst->ast_format(gogo).c_str(), src->ast_format(gogo).c_str()); if (dst_state->flows.empty()) this->context_->add_dst(dst); @@ -2355,18 +2358,18 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, Gogo* gogo = this->context_->gogo(); int debug_level = gogo->debug_escape_level(); if (debug_level > 1) - inform(Linemap::unknown_location(), - "escwalk: level:{%d %d} depth:%d " - "op=%s %s(%s) " - "scope:%s[%d] " - "extraloopdepth=%d", - level.value(), level.suffix_value(), this->context_->pdepth(), - src->op_format().c_str(), - src->ast_format(gogo).c_str(), - src->details().c_str(), - debug_function_name(src_state->fn).c_str(), - src_state->loop_depth, - extra_loop_depth); + go_inform(Linemap::unknown_location(), + "escwalk: level:{%d %d} depth:%d " + "op=%s %s(%s) " + "scope:%s[%d] " + "extraloopdepth=%d", + level.value(), level.suffix_value(), this->context_->pdepth(), + src->op_format().c_str(), + src->ast_format(gogo).c_str(), + src->details().c_str(), + debug_function_name(src_state->fn).c_str(), + src_state->loop_depth, + extra_loop_depth); this->context_->increase_pdepth(); @@ -2400,15 +2403,17 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, if (debug_level != 0) { if (debug_level == 1) - inform(src->location(), - "leaking param: %s to result %s level=%d", - src->ast_format(gogo).c_str(), dst->ast_format(gogo).c_str(), - level.value()); + go_inform(src->location(), + "leaking param: %s to result %s level=%d", + src->ast_format(gogo).c_str(), + dst->ast_format(gogo).c_str(), + level.value()); else - inform(src->location(), - "leaking param: %s to result %s level={%d %d}", - src->ast_format(gogo).c_str(), dst->ast_format(gogo).c_str(), - level.value(), level.suffix_value()); + go_inform(src->location(), + "leaking param: %s to result %s level={%d %d}", + src->ast_format(gogo).c_str(), + dst->ast_format(gogo).c_str(), + level.value(), level.suffix_value()); } if ((src->encoding() & ESCAPE_MASK) != Node::ESCAPE_RETURN) @@ -2446,8 +2451,8 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, Node::ESCAPE_NONE); src->set_encoding(enc); if (debug_level != 0) - inform(src->location(), "mark escaped content: %s", - src->ast_format(gogo).c_str()); + go_inform(src->location(), "mark escaped content: %s", + src->ast_format(gogo).c_str()); } // A src object leaks if its value or address is assigned to a dst object @@ -2468,13 +2473,13 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, Node::ESCAPE_NONE); src->set_encoding(enc); if (debug_level != 0) - inform(src->location(), "leaking param content: %s", - src->ast_format(gogo).c_str()); + go_inform(src->location(), "leaking param content: %s", + src->ast_format(gogo).c_str()); } else { if (debug_level != 0) - inform(src->location(), "leaking param"); + go_inform(src->location(), "leaking param"); src->set_encoding(Node::ESCAPE_SCOPE); } } @@ -2484,8 +2489,8 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, if (e->enclosed_var_expression() != NULL) { if (src_leaks && debug_level != 0) - inform(src->location(), "leaking closure reference %s", - src->ast_format(gogo).c_str()); + go_inform(src->location(), "leaking closure reference %s", + src->ast_format(gogo).c_str()); Node* enclosed_node = Node::make_node(e->enclosed_var_expression()->variable()); @@ -2511,19 +2516,19 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, src->set_encoding(Node::ESCAPE_HEAP); if (debug_level != 0) { - inform(underlying->location(), "moved to heap: %s", - underlying_node->ast_format(gogo).c_str()); + go_inform(underlying->location(), "moved to heap: %s", + underlying_node->ast_format(gogo).c_str()); if (debug_level > 1) - inform(src->location(), - "%s escapes to heap, level={%d %d}, " - "dst.eld=%d, src.eld=%d", - src->ast_format(gogo).c_str(), level.value(), - level.suffix_value(), dst_state->loop_depth, - mod_loop_depth); + go_inform(src->location(), + "%s escapes to heap, level={%d %d}, " + "dst.eld=%d, src.eld=%d", + src->ast_format(gogo).c_str(), level.value(), + level.suffix_value(), dst_state->loop_depth, + mod_loop_depth); else - inform(src->location(), "%s escapes to heap", - src->ast_format(gogo).c_str()); + go_inform(src->location(), "%s escapes to heap", + src->ast_format(gogo).c_str()); } this->flood(level.decrease(), dst, @@ -2553,8 +2558,8 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, { src->set_encoding(Node::ESCAPE_HEAP); if (debug_level != 0) - inform(src->location(), "%s escapes to heap", - src->ast_format(gogo).c_str()); + go_inform(src->location(), "%s escapes to heap", + src->ast_format(gogo).c_str()); extra_loop_depth = mod_loop_depth; } } @@ -2598,8 +2603,8 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, { src->set_encoding(Node::ESCAPE_HEAP); if (debug_level != 0) - inform(src->location(), "%s escapes to heap", - src->ast_format(gogo).c_str()); + go_inform(src->location(), "%s escapes to heap", + src->ast_format(gogo).c_str()); extra_loop_depth = mod_loop_depth; } break; @@ -2616,8 +2621,8 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, // so if this leaks, this call must be done on the heap. src->set_encoding(Node::ESCAPE_HEAP); if (debug_level != 0) - inform(src->location(), "%s escapes to heap", - src->ast_format(gogo).c_str()); + go_inform(src->location(), "%s escapes to heap", + src->ast_format(gogo).c_str()); } } } @@ -2626,8 +2631,8 @@ Escape_analysis_flood::flood(Level level, Node* dst, Node* src, // Calls to Runtime::NEW get lowered into an allocation expression. src->set_encoding(Node::ESCAPE_HEAP); if (debug_level != 0) - inform(src->location(), "%s escapes to heap", - src->ast_format(gogo).c_str()); + go_inform(src->location(), "%s escapes to heap", + src->ast_format(gogo).c_str()); } else if ((e->field_reference_expression() != NULL && e->field_reference_expression()->expr()->unary_expression() == NULL) @@ -2703,10 +2708,10 @@ Gogo::propagate_escape(Escape_context* context, Node* dst) Node::Escape_state* state = dst->state(context, NULL); Gogo* gogo = context->gogo(); if (gogo->debug_escape_level() > 1) - inform(Linemap::unknown_location(), "escflood:%d: dst %s scope:%s[%d]", - context->flood_id(), dst->ast_format(gogo).c_str(), - debug_function_name(state->fn).c_str(), - state->loop_depth); + go_inform(Linemap::unknown_location(), "escflood:%d: dst %s scope:%s[%d]", + context->flood_id(), dst->ast_format(gogo).c_str(), + debug_function_name(state->fn).c_str(), + state->loop_depth); Escape_analysis_flood eaf(context); for (std::set<Node*>::const_iterator p = state->flows.begin(); |