Commit 733ba9b9 by Nathan Sidwell Committed by Nathan Sidwell

[C++ PATCH] Label checking cleanups

https://gcc.gnu.org/ml/gcc-patches/2017-10/msg01847.html
	* decl.c (identifier_goto): Reduce duplication.
	(check_previous_goto_1): Likewise.
	(check_goto): Move var decls to initialization.
	(check_omp_return, define_label_1, define_label): Likewise.

From-SVN: r254086
parent a4fe6139
2017-10-25 Nathan Sidwell <nathan@acm.org>
* decl.c (identifier_goto): Reduce duplication.
(check_previous_goto_1): Likewise.
(check_goto): Move var decls to initialization.
(check_omp_return, define_label_1, define_label): Likewise.
2017-10-25 Jakub Jelinek <jakub@redhat.com> 2017-10-25 Jakub Jelinek <jakub@redhat.com>
PR libstdc++/81706 PR libstdc++/81706
......
...@@ -3093,8 +3093,9 @@ identify_goto (tree decl, location_t loc, const location_t *locus, ...@@ -3093,8 +3093,9 @@ identify_goto (tree decl, location_t loc, const location_t *locus,
diagnostic_t diag_kind) diagnostic_t diag_kind)
{ {
bool complained bool complained
= (decl ? emit_diagnostic (diag_kind, loc, 0, "jump to label %qD", decl) = emit_diagnostic (diag_kind, loc, 0,
: emit_diagnostic (diag_kind, loc, 0, "jump to case label")); decl ? "jump to label %qD" : "jump to case label",
decl);
if (complained && locus) if (complained && locus)
inform (*locus, " from here"); inform (*locus, " from here");
return complained; return complained;
...@@ -3149,68 +3150,62 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names, ...@@ -3149,68 +3150,62 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
" crosses initialization of %q#D", new_decls); " crosses initialization of %q#D", new_decls);
else else
inform (DECL_SOURCE_LOCATION (new_decls), inform (DECL_SOURCE_LOCATION (new_decls),
" enters scope of %q#D which has " " enters scope of %q#D, which has "
"non-trivial destructor", new_decls); "non-trivial destructor", new_decls);
} }
} }
if (b == level) if (b == level)
break; break;
if ((b->kind == sk_try || b->kind == sk_catch) && !saw_eh)
const char *inf = NULL;
location_t loc = input_location;
switch (b->kind)
{ {
if (identified < 2) case sk_try:
{ if (!saw_eh)
complained = identify_goto (decl, input_location, locus, inf = "enters try block";
DK_ERROR);
identified = 2;
}
if (complained)
{
if (b->kind == sk_try)
inform (input_location, " enters try block");
else
inform (input_location, " enters catch block");
}
saw_eh = true; saw_eh = true;
} break;
if (b->kind == sk_omp && !saw_omp)
{ case sk_catch:
if (identified < 2) if (!saw_eh)
{ inf = "enters catch block";
complained = identify_goto (decl, input_location, locus, saw_eh = true;
DK_ERROR); break;
identified = 2;
} case sk_omp:
if (complained) if (!saw_omp)
inform (input_location, " enters OpenMP structured block"); inf = "enters OpenMP structured block";
saw_omp = true; saw_omp = true;
} break;
if (b->kind == sk_transaction && !saw_tm)
{ case sk_transaction:
if (identified < 2) if (!saw_tm)
inf = "enters synchronized or atomic statement";
saw_tm = true;
break;
case sk_block:
if (!saw_cxif && level_for_constexpr_if (b->level_chain))
{ {
complained = identify_goto (decl, input_location, locus, inf = "enters constexpr if statement";
DK_ERROR); loc = EXPR_LOCATION (b->level_chain->this_entity);
identified = 2; saw_cxif = true;
} }
if (complained) break;
inform (input_location,
" enters synchronized or atomic statement"); default:
saw_tm = true; break;
} }
if (!saw_cxif && b->kind == sk_block
&& level_for_constexpr_if (b->level_chain)) if (inf)
{ {
if (identified < 2) if (identified < 2)
{ complained = identify_goto (decl, input_location, locus, DK_ERROR);
complained = identify_goto (decl, input_location, locus, identified = 2;
DK_ERROR);
identified = 2;
}
if (complained) if (complained)
inform (EXPR_LOCATION (b->level_chain->this_entity), inform (loc, " %s", inf);
" enters constexpr if statement");
saw_cxif = true;
} }
} }
...@@ -3238,10 +3233,6 @@ void ...@@ -3238,10 +3233,6 @@ void
check_goto (tree decl) check_goto (tree decl)
{ {
struct named_label_entry *ent, dummy; struct named_label_entry *ent, dummy;
bool saw_catch = false, complained = false;
int identified = 0;
tree bad;
unsigned ix;
/* We can't know where a computed goto is jumping. /* We can't know where a computed goto is jumping.
So we assume that it's OK. */ So we assume that it's OK. */
...@@ -3279,6 +3270,11 @@ check_goto (tree decl) ...@@ -3279,6 +3270,11 @@ check_goto (tree decl)
return; return;
} }
bool saw_catch = false, complained = false;
int identified = 0;
tree bad;
unsigned ix;
if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope
|| ent->in_constexpr_if || ent->in_constexpr_if
|| ent->in_omp_scope || !vec_safe_is_empty (ent->bad_decls)) || ent->in_omp_scope || !vec_safe_is_empty (ent->bad_decls))
...@@ -3339,27 +3335,24 @@ check_goto (tree decl) ...@@ -3339,27 +3335,24 @@ check_goto (tree decl)
inform (input_location, " enters OpenMP structured block"); inform (input_location, " enters OpenMP structured block");
} }
else if (flag_openmp) else if (flag_openmp)
{ for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
cp_binding_level *b; {
for (b = current_binding_level; b ; b = b->level_chain) if (b == ent->binding_level)
{ break;
if (b == ent->binding_level) if (b->kind == sk_omp)
{
if (identified < 2)
{
complained = identify_goto (decl,
DECL_SOURCE_LOCATION (decl),
&input_location, DK_ERROR);
identified = 2;
}
if (complained)
inform (input_location, " exits OpenMP structured block");
break; break;
if (b->kind == sk_omp) }
{ }
if (identified < 2)
{
complained = identify_goto (decl,
DECL_SOURCE_LOCATION (decl),
&input_location, DK_ERROR);
identified = 2;
}
if (complained)
inform (input_location, " exits OpenMP structured block");
break;
}
}
}
} }
/* Check that a return is ok wrt OpenMP structured blocks. /* Check that a return is ok wrt OpenMP structured blocks.
...@@ -3368,8 +3361,7 @@ check_goto (tree decl) ...@@ -3368,8 +3361,7 @@ check_goto (tree decl)
bool bool
check_omp_return (void) check_omp_return (void)
{ {
cp_binding_level *b; for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain)
for (b = current_binding_level; b ; b = b->level_chain)
if (b->kind == sk_omp) if (b->kind == sk_omp)
{ {
error ("invalid exit from OpenMP structured block"); error ("invalid exit from OpenMP structured block");
...@@ -3413,8 +3405,6 @@ define_label_1 (location_t location, tree name) ...@@ -3413,8 +3405,6 @@ define_label_1 (location_t location, tree name)
} }
else else
{ {
struct named_label_use_entry *use;
/* Mark label as having been defined. */ /* Mark label as having been defined. */
DECL_INITIAL (decl) = error_mark_node; DECL_INITIAL (decl) = error_mark_node;
/* Say where in the source. */ /* Say where in the source. */
...@@ -3423,7 +3413,7 @@ define_label_1 (location_t location, tree name) ...@@ -3423,7 +3413,7 @@ define_label_1 (location_t location, tree name)
ent->binding_level = current_binding_level; ent->binding_level = current_binding_level;
ent->names_in_scope = current_binding_level->names; ent->names_in_scope = current_binding_level->names;
for (use = ent->uses; use ; use = use->next) for (named_label_use_entry *use = ent->uses; use; use = use->next)
check_previous_goto (decl, use); check_previous_goto (decl, use);
ent->uses = NULL; ent->uses = NULL;
} }
...@@ -3436,9 +3426,8 @@ define_label_1 (location_t location, tree name) ...@@ -3436,9 +3426,8 @@ define_label_1 (location_t location, tree name)
tree tree
define_label (location_t location, tree name) define_label (location_t location, tree name)
{ {
tree ret;
bool running = timevar_cond_start (TV_NAME_LOOKUP); bool running = timevar_cond_start (TV_NAME_LOOKUP);
ret = define_label_1 (location, name); tree ret = define_label_1 (location, name);
timevar_cond_stop (TV_NAME_LOOKUP, running); timevar_cond_stop (TV_NAME_LOOKUP, running);
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment