re PR c++/63558 (cannot silence "jump to case label" with fpermissive)

/cp
2014-12-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/63558
	* decl.c (identify_goto): Return a bool if diagnostic is emitted.
	(check_previous_goto_1): Consistently emit permerror + inform.
	(check_goto): Likewise.

/testsuite
2014-12-03  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/63558
	* g++.dg/init/goto3.C: New.
	* g++.dg/eh/goto2.C: Adjust.
	* g++.dg/ext/vla14.C: Likewise.
	* g++.dg/gomp/block-1.C: Likewise.
	* g++.dg/gomp/block-2.C: Likewise.
	* g++.dg/gomp/block-3.C: Likewise.
	* g++.dg/gomp/block-5.C: Likewise.
	* g++.dg/gomp/target-1.C: Likewise.
	* g++.dg/gomp/target-2.C: Likewise.
	* g++.dg/gomp/taskgroup-1.C: Likewise.
	* g++.dg/gomp/teams-1.C: Likewise.
	* g++.dg/init/goto2.C: Likewise.
	* g++.dg/warn/pedantic1.C: Likewise.
	* g++.old-deja/g++.jason/jump.C: Likewise.
	* g++.old-deja/g++.law/arm6.C: Likewise.
	* g++.old-deja/g++.other/goto1.C: Likewise.
	* g++.old-deja/g++.other/goto3.C: Likewise.
	* g++.old-deja/g++.other/init9.C: Likewise.

From-SVN: r218328
This commit is contained in:
Paolo Carlini 2014-12-03 18:41:42 +00:00 committed by Paolo Carlini
parent c430f419e9
commit 61a1a73ecb
21 changed files with 196 additions and 102 deletions

View File

@ -1,3 +1,10 @@
2014-12-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/63558
* decl.c (identify_goto): Return a bool if diagnostic is emitted.
(check_previous_goto_1): Consistently emit permerror + inform.
(check_goto): Likewise.
2014-12-03 Richard Biener <rguenther@suse.de>
* constexpr.c (cxx_eval_builtin_function_call): Use

View File

@ -2874,15 +2874,15 @@ decl_jump_unsafe (tree decl)
/* A subroutine of check_previous_goto_1 to identify a branch to the user. */
static void
static bool
identify_goto (tree decl, const location_t *locus)
{
if (decl)
permerror (input_location, "jump to label %qD", decl);
else
permerror (input_location, "jump to case label");
if (locus)
permerror (*locus, " from here");
bool complained = (decl
? permerror (input_location, "jump to label %qD", decl)
: permerror (input_location, "jump to case label"));
if (complained && locus)
inform (*locus, " from here");
return complained;
}
/* Check that a single previously seen jump to a newly defined label
@ -2896,12 +2896,14 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
bool exited_omp, const location_t *locus)
{
cp_binding_level *b;
bool identified = false, saw_eh = false, saw_omp = false;
bool identified = false, complained = false;
bool saw_eh = false, saw_omp = false;
if (exited_omp)
{
identify_goto (decl, locus);
error (" exits OpenMP structured block");
complained = identify_goto (decl, locus);
if (complained)
inform (input_location, " exits OpenMP structured block");
identified = saw_omp = true;
}
@ -2919,14 +2921,18 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
if (!identified)
{
identify_goto (decl, locus);
complained = identify_goto (decl, locus);
identified = true;
}
if (problem > 1)
error (" crosses initialization of %q+#D", new_decls);
else
permerror (input_location, " enters scope of %q+#D which has "
"non-trivial destructor", new_decls);
if (complained)
{
if (problem > 1)
inform (input_location,
" crosses initialization of %q+#D", new_decls);
else
inform (input_location, " enters scope of %q+#D which has "
"non-trivial destructor", new_decls);
}
}
if (b == level)
@ -2935,23 +2941,27 @@ check_previous_goto_1 (tree decl, cp_binding_level* level, tree names,
{
if (!identified)
{
identify_goto (decl, locus);
complained = identify_goto (decl, locus);
identified = true;
}
if (b->kind == sk_try)
error (" enters try block");
else
error (" enters catch block");
if (complained)
{
if (b->kind == sk_try)
inform (input_location, " enters try block");
else
inform (input_location, " enters catch block");
}
saw_eh = true;
}
if (b->kind == sk_omp && !saw_omp)
{
if (!identified)
{
identify_goto (decl, locus);
complained = identify_goto (decl, locus);
identified = true;
}
error (" enters OpenMP structured block");
if (complained)
inform (input_location, " enters OpenMP structured block");
saw_omp = true;
}
}
@ -2980,7 +2990,7 @@ void
check_goto (tree decl)
{
struct named_label_entry *ent, dummy;
bool saw_catch = false, identified = false;
bool saw_catch = false, identified = false, complained = false;
tree bad;
unsigned ix;
@ -3023,8 +3033,9 @@ check_goto (tree decl)
if (ent->in_try_scope || ent->in_catch_scope
|| ent->in_omp_scope || !vec_safe_is_empty (ent->bad_decls))
{
permerror (input_location, "jump to label %q+D", decl);
permerror (input_location, " from here");
complained = permerror (input_location, "jump to label %q+D", decl);
if (complained)
inform (input_location, " from here");
identified = true;
}
@ -3035,23 +3046,33 @@ check_goto (tree decl)
if (u > 1 && DECL_ARTIFICIAL (bad))
{
/* Can't skip init of __exception_info. */
error_at (DECL_SOURCE_LOCATION (bad), " enters catch block");
if (complained)
inform (DECL_SOURCE_LOCATION (bad), " enters catch block");
saw_catch = true;
}
else if (u > 1)
error (" skips initialization of %q+#D", bad);
else
permerror (input_location, " enters scope of %q+#D which has "
"non-trivial destructor", bad);
else if (complained)
{
if (u > 1)
inform (input_location, " skips initialization of %q+#D", bad);
else
inform (input_location, " enters scope of %q+#D which has "
"non-trivial destructor", bad);
}
}
if (ent->in_try_scope)
error (" enters try block");
else if (ent->in_catch_scope && !saw_catch)
error (" enters catch block");
if (complained)
{
if (ent->in_try_scope)
inform (input_location, " enters try block");
else if (ent->in_catch_scope && !saw_catch)
inform (input_location, " enters catch block");
}
if (ent->in_omp_scope)
error (" enters OpenMP structured block");
{
if (complained)
inform (input_location, " enters OpenMP structured block");
}
else if (flag_openmp)
{
cp_binding_level *b;
@ -3063,11 +3084,14 @@ check_goto (tree decl)
{
if (!identified)
{
permerror (input_location, "jump to label %q+D", decl);
permerror (input_location, " from here");
complained = permerror (input_location,
"jump to label %q+D", decl);
if (complained)
inform (input_location, " from here");
identified = true;
}
error (" exits OpenMP structured block");
if (complained)
inform (input_location, " exits OpenMP structured block");
break;
}
}

View File

@ -1,3 +1,25 @@
2014-12-03 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/63558
* g++.dg/init/goto3.C: New.
* g++.dg/eh/goto2.C: Adjust.
* g++.dg/ext/vla14.C: Likewise.
* g++.dg/gomp/block-1.C: Likewise.
* g++.dg/gomp/block-2.C: Likewise.
* g++.dg/gomp/block-3.C: Likewise.
* g++.dg/gomp/block-5.C: Likewise.
* g++.dg/gomp/target-1.C: Likewise.
* g++.dg/gomp/target-2.C: Likewise.
* g++.dg/gomp/taskgroup-1.C: Likewise.
* g++.dg/gomp/teams-1.C: Likewise.
* g++.dg/init/goto2.C: Likewise.
* g++.dg/warn/pedantic1.C: Likewise.
* g++.old-deja/g++.jason/jump.C: Likewise.
* g++.old-deja/g++.law/arm6.C: Likewise.
* g++.old-deja/g++.other/goto1.C: Likewise.
* g++.old-deja/g++.other/goto3.C: Likewise.
* g++.old-deja/g++.other/init9.C: Likewise.
2014-12-03 Michael Meissner <meissner@linux.vnet.ibm.com>
PR target/64019

View File

@ -3,10 +3,11 @@
void f()
try
{
goto l2; // { dg-error "from here" }
goto l2; // { dg-message "from here" }
l1: ; // { dg-error "jump to label 'l1'" }
} catch (...)
{
l2: ; // { dg-error "jump to label 'l2'|enters catch block" }
goto l1; // { dg-error "from here|enters try block" }
l2: ; // { dg-error "jump to label 'l2'" }
// { dg-message "enters catch block" "" { target *-*-*} 10 }
goto l1; // { dg-message "from here|enters try block" }
}

View File

@ -4,8 +4,8 @@
void
f (int n)
{
goto label; // { dg-error "from here" }
int a[n]; // { dg-error "crosses initialization" }
goto label; // { dg-message "from here" }
int a[n]; // { dg-message "crosses initialization" }
label: // { dg-error "jump to label" }
;
}
@ -16,7 +16,7 @@ g (int n)
switch (1)
{
case 1:
int (*a)[n]; // { dg-error "crosses initialization" }
int (*a)[n]; // { dg-message "crosses initialization" }
default: // { dg-error "jump to case label" }
;
}

View File

@ -4,12 +4,13 @@ void foo()
{
bad1: // { dg-error "jump to label" }
#pragma omp parallel
goto bad1; // { dg-error "from here|exits OpenMP" }
goto bad1; // { dg-message "from here|exits OpenMP" }
goto bad2; // { dg-error "from here" }
goto bad2; // { dg-message "from here" }
#pragma omp parallel
{
bad2: ; // { dg-error "jump to label|enters OpenMP" }
bad2: ; // { dg-error "jump to label" }
// { dg-message "enters OpenMP" "" { target *-*-* } 12 }
}
#pragma omp parallel

View File

@ -11,13 +11,14 @@ void foo()
bad1: // { dg-error "jump to label" }
#pragma omp for
for (i = 0; i < 10; ++i)
goto bad1; // { dg-error "from here|exits OpenMP" }
goto bad1; // { dg-message "from here|exits OpenMP" }
goto bad2; // { dg-error "from here" }
goto bad2; // { dg-message "from here" }
#pragma omp for
for (i = 0; i < 10; ++i)
{
bad2: ; // { dg-error "jump|enters OpenMP" }
bad2: ; // { dg-error "jump" }
// { dg-message "enters OpenMP" "" { target *-*-* } 20 }
}
#pragma omp for

View File

@ -18,19 +18,21 @@ void foo()
#pragma omp section
{ bad1: ; } // { dg-error "jump to label" }
#pragma omp section
goto bad1; // { dg-error "from here|enters OpenMP" }
goto bad1; // { dg-message "from here|enters OpenMP" }
}
#pragma omp sections
{
goto bad2; // { dg-error "from here" }
goto bad2; // { dg-message "from here" }
}
bad2:; // { dg-error "jump|exits OpenMP" }
bad2:; // { dg-error "jump" }
// { dg-message "exits OpenMP" "" { target *-*-* } 28 }
goto bad3; // { dg-error "from here" }
goto bad3; // { dg-message "from here" }
#pragma omp sections
{
bad3: ; // { dg-error "jump|enters OpenMP" }
bad3: ; // { dg-error "jump" }
// { dg-message "enters OpenMP" "" { target *-*-* } 34 }
}
#pragma omp sections
@ -60,4 +62,4 @@ void foo()
// { dg-message "error: invalid branch to/from an OpenMP structured block" "" { target *-*-* } 21 }
// { dg-message "error: invalid branch to/from an OpenMP structured block" "" { target *-*-* } 26 }
// { dg-message "error: invalid entry to OpenMP structured block" "" { target *-*-* } 30 }
// { dg-message "error: invalid entry to OpenMP structured block" "" { target *-*-* } 31 }

View File

@ -4,12 +4,13 @@ void foo()
{
#pragma omp master
{
goto bad1; // { dg-error "from here" }
goto bad1; // { dg-message "from here" }
}
#pragma omp master
{
bad1: // { dg-error "jump|exits OpenMP" }
bad1: // { dg-error "jump" }
// { dg-message "exits OpenMP" "" { target *-*-* } 12 }
return; // { dg-error "invalid exit" }
}
}

View File

@ -5,12 +5,13 @@ foo (int x)
{
bad1: // { dg-error "jump to label" }
#pragma omp target
goto bad1; // { dg-error "from here|exits OpenMP" }
goto bad1; // { dg-message "from here|exits OpenMP" }
goto bad2; // { dg-error "from here" }
goto bad2; // { dg-message "from here" }
#pragma omp target
{
bad2: ; // { dg-error "jump to label|enters OpenMP" }
bad2: ; // { dg-error "jump to label" }
// { dg-message "enters OpenMP" "" { target *-*-* } 13 }
}
#pragma omp target
@ -24,7 +25,8 @@ foo (int x)
switch (x)
{
#pragma omp target
{ case 0:; } // { dg-error "jump|enters" }
{ case 0:; } // { dg-error "jump" }
// { dg-message "enters" "" { target *-*-* } 28 }
}
}

View File

@ -5,12 +5,13 @@ foo (int x, int y)
{
bad1: // { dg-error "jump to label" }
#pragma omp target data map(tofrom: y)
goto bad1; // { dg-error "from here|exits OpenMP" }
goto bad1; // { dg-message "from here|exits OpenMP" }
goto bad2; // { dg-error "from here" }
goto bad2; // { dg-message "from here" }
#pragma omp target data map(tofrom: y)
{
bad2: ; // { dg-error "jump to label|enters OpenMP" }
bad2: ; // { dg-error "jump to label" }
// { dg-message "enters OpenMP" "" { target *-*-* } 13 }
}
#pragma omp target data map(tofrom: y)
@ -24,7 +25,8 @@ foo (int x, int y)
switch (x)
{
#pragma omp target data map(tofrom: y)
{ case 0:; } // { dg-error "jump|enters" }
{ case 0:; } // { dg-error "jump" }
// { dg-message "enters" "" { target *-*-* } 28 }
}
}

View File

@ -5,12 +5,13 @@ foo (int x)
{
bad1: // { dg-error "jump to label" }
#pragma omp taskgroup
goto bad1; // { dg-error "from here|exits OpenMP" }
goto bad1; // { dg-message "from here|exits OpenMP" }
goto bad2; // { dg-error "from here" }
goto bad2; // { dg-message "from here" }
#pragma omp taskgroup
{
bad2: ; // { dg-error "jump to label|enters OpenMP" }
bad2: ; // { dg-error "jump to label" }
// { dg-message "enters OpenMP" "" { target *-*-* } 13 }
}
#pragma omp taskgroup
@ -24,7 +25,8 @@ foo (int x)
switch (x)
{
#pragma omp taskgroup
{ case 0:; } // { dg-error "jump|enters" }
{ case 0:; } // { dg-error "jump" }
// { dg-message "enters" "" { target *-*-* } 28 }
}
}

View File

@ -5,12 +5,13 @@ foo (int x)
{
bad1: // { dg-error "jump to label" }
#pragma omp target teams
goto bad1; // { dg-error "from here|exits OpenMP" }
goto bad1; // { dg-message "from here|exits OpenMP" }
goto bad2; // { dg-error "from here" }
goto bad2; // { dg-message "from here" }
#pragma omp target teams
{
bad2: ; // { dg-error "jump to label|enters OpenMP" }
bad2: ; // { dg-error "jump to label" }
// { dg-message "enters OpenMP" "" { target *-*-* } 13 }
}
#pragma omp target teams
@ -24,7 +25,8 @@ foo (int x)
switch (x)
{
#pragma omp target teams
{ case 0:; } // { dg-error "jump|enters" }
{ case 0:; } // { dg-error "jump" }
// { dg-message "enters" "" { target *-*-* } 28 }
}
}
@ -34,13 +36,14 @@ bar (int x)
bad1: // { dg-error "jump to label" }
#pragma omp target
#pragma omp teams
goto bad1; // { dg-error "from here|exits OpenMP" }
goto bad1; // { dg-message "from here|exits OpenMP" }
goto bad2; // { dg-error "from here" }
goto bad2; // { dg-message "from here" }
#pragma omp target
#pragma omp teams
{
bad2: ; // { dg-error "jump to label|enters OpenMP" }
bad2: ; // { dg-error "jump to label" }
// { dg-message "enters OpenMP" "" { target *-*-* } 45 }
}
#pragma omp target
@ -56,11 +59,12 @@ bar (int x)
{
#pragma omp target
#pragma omp teams
{ case 0:; } // { dg-error "jump|enters" }
{ case 0:; } // { dg-error "jump" }
// { dg-message "enters" "" { target *-*-* } 62 }
}
}
// { dg-error "invalid branch to/from an OpenMP structured block" "" { target *-*-* } 8 }
// { dg-error "invalid entry to OpenMP structured block" "" { target *-*-* } 10 }
// { dg-error "invalid branch to/from an OpenMP structured block" "" { target *-*-* } 37 }
// { dg-error "invalid entry to OpenMP structured block" "" { target *-*-* } 39 }
// { dg-error "invalid branch to/from an OpenMP structured block" "" { target *-*-* } 39 }
// { dg-error "invalid entry to OpenMP structured block" "" { target *-*-* } 41 }

View File

@ -3,8 +3,8 @@
bool f();
void g(int i)
{
if (i) goto bad; // { dg-error "from" }
bool a = f(); // { dg-error "initialization" }
if (i) goto bad; // { dg-message "from" }
bool a = f(); // { dg-message "initialization" }
bad: // { dg-error "jump" }
;
}

View File

@ -0,0 +1,25 @@
// PR c++/63558
// { dg-options "-fpermissive -w" }
extern int abs(int);
static long int n_ants;
enum enum_var_types
{ VAR_NONE, VAR_DELTA, VAR_SWITCH };
static enum enum_var_types option_var_n_ants;
void
adapt_parameters_next_iteration(void)
{
switch(option_var_n_ants) {
case VAR_NONE: break;
case VAR_DELTA:
int trunc_n_ants = 0;
n_ants += trunc_n_ants;
break;
case VAR_SWITCH:
break;
default: break;
}
}

View File

@ -2,9 +2,9 @@
// { dg-options "-pedantic" }
int main() {
goto label; // { dg-error "" }
goto label; // { dg-message "" }
int temp = 1; // { dg-error "" }
int temp = 1; // { dg-message "" }
label: // { dg-error "" }
return 1;

View File

@ -6,7 +6,7 @@ extern int a;
int main() {
switch (a) {
case 1:
int v2 = 3; // { dg-error "" } referenced below
int v2 = 3; // { dg-message "" } referenced below
case 2: // { dg-error "" } jumping past initializer
if (v2 == 7)
;

View File

@ -12,7 +12,7 @@ int main() {
switch (a) {
case 1:
int v2 = 3;// { dg-error "" } crosses.*
int v2 = 3;// { dg-message "" } crosses.*
case 2:// { dg-error "" } jump.*
if (v2 == 7) // error not flagged by 2.3.1
;

View File

@ -10,12 +10,12 @@ struct S
void f ()
{
{
S s1; // { dg-error "" } skips initialization
S s1; // { dg-message "" } skips initialization
t: // { dg-error "" } jump to label
S s2;
;
}
goto t; // { dg-error "" } from here
goto t; // { dg-message "" } from here
}

View File

@ -4,17 +4,17 @@
void f ()
{
goto foo1; // { dg-error "" } jumps
goto foo1; // { dg-message "" } jumps
try { foo1:; } catch (...) { } // { dg-error "" } into try
goto foo2; // { dg-error "" } jumps
goto foo2; // { dg-message "" } jumps
try { } catch (...) { foo2:; } // { dg-error "" } into catch
goto foo3; // { dg-error "" } jumps
goto foo3; // { dg-message "" } jumps
{ int i=2; foo3:; } // { dg-error "" } past init
try { foo4:; } catch (...) { } // { dg-error "" }
goto foo4; // { dg-error "" }
goto foo4; // { dg-message "" }
try { } catch (...) { foo5:; } // { dg-error "" }
goto foo5; // { dg-error "" }
goto foo5; // { dg-message "" }
{ int i=2; foo6:; } // { dg-error "" }
goto foo6; // { dg-error "" }
goto foo6; // { dg-message "" }
}

View File

@ -13,8 +13,8 @@ struct A {
};
void a() {
goto bar; // { dg-error "" } jump from here
A x; // { dg-error "" } jump crosses initialization
goto bar; // { dg-message "" } jump from here
A x; // { dg-message "" } jump crosses initialization
bar: // { dg-error "" } jump to here
;
}
@ -24,8 +24,8 @@ struct X {
};
void b() {
goto bar; // { dg-error "" } jump from here
X x; // { dg-error "" } jump crosses initialization
goto bar; // { dg-message "" } jump from here
X x; // { dg-message "" } jump crosses initialization
bar: // { dg-error "" } jump to here
;
}
@ -33,8 +33,8 @@ void b() {
#include <vector>
void c() {
goto bar; // { dg-error "" } jump from here
std::vector<int> x; // { dg-error "" } jump crosses initialization
goto bar; // { dg-message "" } jump from here
std::vector<int> x; // { dg-message "" } jump crosses initialization
bar: // { dg-error "" } jump to here
;
}