diff mbox

Warn about unclosed pragma omp declare target.

Message ID 20140729144501.GA102135@msticlxl7.ims.intel.com
State New
Headers show

Commit Message

Ilya Tocar July 29, 2014, 2:45 p.m. UTC
Hi,

As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
Gcc should complain about pragma omp declare target without
corresponding pragma omp end declare target. This patch adds a warning
for those cases.
Bootstraps/passes make-check.
Ok for trunk?

ChangeLog:

2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>

	* c-decl.c (omp_declare_target_location_stack): New.
	* c-lang.h (omp_declare_target_location_stack): Declare.
	* c-parser.c (warn_unclosed_pragma_omp_target): New.
	(c_parser_translation_unit): Call it.
	(c_parser_omp_declare_target): Remeber location.
	(c_parser_omp_end_declare_target): Forget location.

And ChangeLog for testsuite:

2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>

	* gcc.dg/gomp//target-3.c: New testcase.

---
 gcc/c/c-decl.c                       |  3 +++
 gcc/c/c-lang.h                       |  3 +++
 gcc/c/c-parser.c                     | 22 +++++++++++++++++++++-
 gcc/testsuite/gcc.dg/gomp/target-3.c | 33 +++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/gomp/target-3.c

Comments

Ilya Tocar Aug. 15, 2014, 12:26 p.m. UTC | #1
Ping.

On 29 Jul 18:45, Ilya Tocar wrote:
> Hi,
> 
> As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> Gcc should complain about pragma omp declare target without
> corresponding pragma omp end declare target. This patch adds a warning
> for those cases.
> Bootstraps/passes make-check.
> Ok for trunk?
> 
> ChangeLog:
> 
> 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> 
> 	* c-decl.c (omp_declare_target_location_stack): New.
> 	* c-lang.h (omp_declare_target_location_stack): Declare.
> 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> 	(c_parser_translation_unit): Call it.
> 	(c_parser_omp_declare_target): Remeber location.
> 	(c_parser_omp_end_declare_target): Forget location.
> 
> And ChangeLog for testsuite:
> 
> 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> 
> 	* gcc.dg/gomp//target-3.c: New testcase.
> 
> ---
>  gcc/c/c-decl.c                       |  3 +++
>  gcc/c/c-lang.h                       |  3 +++
>  gcc/c/c-parser.c                     | 22 +++++++++++++++++++++-
>  gcc/testsuite/gcc.dg/gomp/target-3.c | 33 +++++++++++++++++++++++++++++++++
>  4 files changed, 60 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/gcc.dg/gomp/target-3.c
> 
> diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
> index 2a4b439..2dd5b2c 100644
> --- a/gcc/c/c-decl.c
> +++ b/gcc/c/c-decl.c
> @@ -158,6 +158,9 @@ enum machine_mode c_default_pointer_mode = VOIDmode;
>  /* If non-zero, implicit "omp declare target" attribute is added into the
>     attribute lists.  */
>  int current_omp_declare_target_attribute;
> +
> +/* Holds locations of currently open "omp declare target" pragmas.  */
> +vec<location_t> omp_declare_target_location_stack;
>  
>  /* Each c_binding structure describes one binding of an identifier to
>     a decl.  All the decls in a scope - irrespective of namespace - are
> diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
> index e974906..cef995c 100644
> --- a/gcc/c/c-lang.h
> +++ b/gcc/c/c-lang.h
> @@ -59,4 +59,7 @@ struct GTY(()) language_function {
>     attribute lists.  */
>  extern GTY(()) int current_omp_declare_target_attribute;
>  
> +/* Holds locations of currently open "omp declare target" pragmas.  */
> +extern vec<location_t> omp_declare_target_location_stack;
> +
>  #endif /* ! GCC_C_LANG_H */
> diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> index e32bf04..0b96fe9 100644
> --- a/gcc/c/c-parser.c
> +++ b/gcc/c/c-parser.c
> @@ -1255,6 +1255,8 @@ static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
>  static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
>  static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
>  
> +static void warn_unclosed_pragma_omp_target ();
> +
>  /* Parse a translation unit (C90 6.7, C99 6.9).
>  
>     translation-unit:
> @@ -1290,6 +1292,8 @@ c_parser_translation_unit (c_parser *parser)
>  	}
>        while (c_parser_next_token_is_not (parser, CPP_EOF));
>      }
> +
> +  warn_unclosed_pragma_omp_target ();
>  }
>  
>  /* Parse an external declaration (C90 6.7, C99 6.9).
> @@ -13068,8 +13072,10 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
>  static void
>  c_parser_omp_declare_target (c_parser *parser)
>  {
> +  location_t loc = c_parser_peek_token (parser)->location;
>    c_parser_skip_to_pragma_eol (parser);
>    current_omp_declare_target_attribute++;
> +  omp_declare_target_location_stack.safe_push (loc);
>  }
>  
>  static void
> @@ -13104,7 +13110,10 @@ c_parser_omp_end_declare_target (c_parser *parser)
>      error_at (loc, "%<#pragma omp end declare target%> without corresponding "
>  		   "%<#pragma omp declare target%>");
>    else
> -    current_omp_declare_target_attribute--;
> +    {
> +      current_omp_declare_target_attribute--;
> +      omp_declare_target_location_stack.pop ();
> +    }
>  }
>  
>  
> @@ -14267,4 +14276,15 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
>    return value_tree;
>  }
>  
> +static void
> +warn_unclosed_pragma_omp_target ()
> +{
> +  int i;
> +  for (i = 0; i < current_omp_declare_target_attribute; i++)
> +    warning_at (omp_declare_target_location_stack[i], 0,
> +		"%<#pragma omp declare target%> without corresponding "
> +		"%<#pragma omp end declare target%>");
> +  omp_declare_target_location_stack.release ();
> +}
> +
>  #include "gt-c-c-parser.h"
> diff --git a/gcc/testsuite/gcc.dg/gomp/target-3.c b/gcc/testsuite/gcc.dg/gomp/target-3.c
> new file mode 100644
> index 0000000..d50604f
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/gomp/target-3.c
> @@ -0,0 +1,33 @@
> +/* { dg-do compile } */
> +/* { dg-options "-fopenmp" } */
> +
> +#pragma omp declare target
> +int tgtv = 6;
> +
> +int
> +tgt (void)
> +{
> +  tgtv++;
> +  return 0;
> +}
> +#pragma omp end declare target
> +
> +#pragma omp declare target        /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> +int tgtv1 = 6;
> +#pragma omp declare target	  /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> +
> +int
> +tgt2 (void)
> +{
> +  tgtv1++;
> +  return 0;
> +}
> +
> +#pragma omp declare target
> +int
> +tgt3 (void)
> +{
> +  tgtv1++;
> +  return 0;
> +}
> +#pragma omp end declare target
> -- 
> 1.8.3.1
>
Ilya Tocar Oct. 2, 2014, 1:38 p.m. UTC | #2
Ping.
On 15 Aug 16:26, Ilya Tocar wrote:
> Ping.
> 
> On 29 Jul 18:45, Ilya Tocar wrote:
> > Hi,
> > 
> > As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> > Gcc should complain about pragma omp declare target without
> > corresponding pragma omp end declare target. This patch adds a warning
> > for those cases.
> > Bootstraps/passes make-check.
> > Ok for trunk?
> > 
> > ChangeLog:
> > 
> > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > 
> > 	* c-decl.c (omp_declare_target_location_stack): New.
> > 	* c-lang.h (omp_declare_target_location_stack): Declare.
> > 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> > 	(c_parser_translation_unit): Call it.
> > 	(c_parser_omp_declare_target): Remeber location.
> > 	(c_parser_omp_end_declare_target): Forget location.
> > 
> > And ChangeLog for testsuite:
> > 
> > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > 
> > 	* gcc.dg/gomp//target-3.c: New testcase.
> > 
> > ---
> >  gcc/c/c-decl.c                       |  3 +++
> >  gcc/c/c-lang.h                       |  3 +++
> >  gcc/c/c-parser.c                     | 22 +++++++++++++++++++++-
> >  gcc/testsuite/gcc.dg/gomp/target-3.c | 33 +++++++++++++++++++++++++++++++++
> >  4 files changed, 60 insertions(+), 1 deletion(-)
> >  create mode 100644 gcc/testsuite/gcc.dg/gomp/target-3.c
> > 
> > diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
> > index 2a4b439..2dd5b2c 100644
> > --- a/gcc/c/c-decl.c
> > +++ b/gcc/c/c-decl.c
> > @@ -158,6 +158,9 @@ enum machine_mode c_default_pointer_mode = VOIDmode;
> >  /* If non-zero, implicit "omp declare target" attribute is added into the
> >     attribute lists.  */
> >  int current_omp_declare_target_attribute;
> > +
> > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > +vec<location_t> omp_declare_target_location_stack;
> >  
> >  /* Each c_binding structure describes one binding of an identifier to
> >     a decl.  All the decls in a scope - irrespective of namespace - are
> > diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
> > index e974906..cef995c 100644
> > --- a/gcc/c/c-lang.h
> > +++ b/gcc/c/c-lang.h
> > @@ -59,4 +59,7 @@ struct GTY(()) language_function {
> >     attribute lists.  */
> >  extern GTY(()) int current_omp_declare_target_attribute;
> >  
> > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > +extern vec<location_t> omp_declare_target_location_stack;
> > +
> >  #endif /* ! GCC_C_LANG_H */
> > diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> > index e32bf04..0b96fe9 100644
> > --- a/gcc/c/c-parser.c
> > +++ b/gcc/c/c-parser.c
> > @@ -1255,6 +1255,8 @@ static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
> >  static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
> >  static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
> >  
> > +static void warn_unclosed_pragma_omp_target ();
> > +
> >  /* Parse a translation unit (C90 6.7, C99 6.9).
> >  
> >     translation-unit:
> > @@ -1290,6 +1292,8 @@ c_parser_translation_unit (c_parser *parser)
> >  	}
> >        while (c_parser_next_token_is_not (parser, CPP_EOF));
> >      }
> > +
> > +  warn_unclosed_pragma_omp_target ();
> >  }
> >  
> >  /* Parse an external declaration (C90 6.7, C99 6.9).
> > @@ -13068,8 +13072,10 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
> >  static void
> >  c_parser_omp_declare_target (c_parser *parser)
> >  {
> > +  location_t loc = c_parser_peek_token (parser)->location;
> >    c_parser_skip_to_pragma_eol (parser);
> >    current_omp_declare_target_attribute++;
> > +  omp_declare_target_location_stack.safe_push (loc);
> >  }
> >  
> >  static void
> > @@ -13104,7 +13110,10 @@ c_parser_omp_end_declare_target (c_parser *parser)
> >      error_at (loc, "%<#pragma omp end declare target%> without corresponding "
> >  		   "%<#pragma omp declare target%>");
> >    else
> > -    current_omp_declare_target_attribute--;
> > +    {
> > +      current_omp_declare_target_attribute--;
> > +      omp_declare_target_location_stack.pop ();
> > +    }
> >  }
> >  
> >  
> > @@ -14267,4 +14276,15 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
> >    return value_tree;
> >  }
> >  
> > +static void
> > +warn_unclosed_pragma_omp_target ()
> > +{
> > +  int i;
> > +  for (i = 0; i < current_omp_declare_target_attribute; i++)
> > +    warning_at (omp_declare_target_location_stack[i], 0,
> > +		"%<#pragma omp declare target%> without corresponding "
> > +		"%<#pragma omp end declare target%>");
> > +  omp_declare_target_location_stack.release ();
> > +}
> > +
> >  #include "gt-c-c-parser.h"
> > diff --git a/gcc/testsuite/gcc.dg/gomp/target-3.c b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > new file mode 100644
> > index 0000000..d50604f
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > @@ -0,0 +1,33 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-fopenmp" } */
> > +
> > +#pragma omp declare target
> > +int tgtv = 6;
> > +
> > +int
> > +tgt (void)
> > +{
> > +  tgtv++;
> > +  return 0;
> > +}
> > +#pragma omp end declare target
> > +
> > +#pragma omp declare target        /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > +int tgtv1 = 6;
> > +#pragma omp declare target	  /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > +
> > +int
> > +tgt2 (void)
> > +{
> > +  tgtv1++;
> > +  return 0;
> > +}
> > +
> > +#pragma omp declare target
> > +int
> > +tgt3 (void)
> > +{
> > +  tgtv1++;
> > +  return 0;
> > +}
> > +#pragma omp end declare target
> > -- 
> > 1.8.3.1
> >
Ilya Tocar Oct. 20, 2014, 3:26 p.m. UTC | #3
Ping.

On 02 Oct 17:38, Ilya Tocar wrote:
> Ping.
> On 15 Aug 16:26, Ilya Tocar wrote:
> > Ping.
> > 
> > On 29 Jul 18:45, Ilya Tocar wrote:
> > > Hi,
> > > 
> > > As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> > > Gcc should complain about pragma omp declare target without
> > > corresponding pragma omp end declare target. This patch adds a warning
> > > for those cases.
> > > Bootstraps/passes make-check.
> > > Ok for trunk?
> > > 
> > > ChangeLog:
> > > 
> > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > 
> > > 	* c-decl.c (omp_declare_target_location_stack): New.
> > > 	* c-lang.h (omp_declare_target_location_stack): Declare.
> > > 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> > > 	(c_parser_translation_unit): Call it.
> > > 	(c_parser_omp_declare_target): Remeber location.
> > > 	(c_parser_omp_end_declare_target): Forget location.
> > > 
> > > And ChangeLog for testsuite:
> > > 
> > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > 
> > > 	* gcc.dg/gomp//target-3.c: New testcase.
> > > 
> > > ---
> > >  gcc/c/c-decl.c                       |  3 +++
> > >  gcc/c/c-lang.h                       |  3 +++
> > >  gcc/c/c-parser.c                     | 22 +++++++++++++++++++++-
> > >  gcc/testsuite/gcc.dg/gomp/target-3.c | 33 +++++++++++++++++++++++++++++++++
> > >  4 files changed, 60 insertions(+), 1 deletion(-)
> > >  create mode 100644 gcc/testsuite/gcc.dg/gomp/target-3.c
> > > 
> > > diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
> > > index 2a4b439..2dd5b2c 100644
> > > --- a/gcc/c/c-decl.c
> > > +++ b/gcc/c/c-decl.c
> > > @@ -158,6 +158,9 @@ enum machine_mode c_default_pointer_mode = VOIDmode;
> > >  /* If non-zero, implicit "omp declare target" attribute is added into the
> > >     attribute lists.  */
> > >  int current_omp_declare_target_attribute;
> > > +
> > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > +vec<location_t> omp_declare_target_location_stack;
> > >  
> > >  /* Each c_binding structure describes one binding of an identifier to
> > >     a decl.  All the decls in a scope - irrespective of namespace - are
> > > diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
> > > index e974906..cef995c 100644
> > > --- a/gcc/c/c-lang.h
> > > +++ b/gcc/c/c-lang.h
> > > @@ -59,4 +59,7 @@ struct GTY(()) language_function {
> > >     attribute lists.  */
> > >  extern GTY(()) int current_omp_declare_target_attribute;
> > >  
> > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > +extern vec<location_t> omp_declare_target_location_stack;
> > > +
> > >  #endif /* ! GCC_C_LANG_H */
> > > diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> > > index e32bf04..0b96fe9 100644
> > > --- a/gcc/c/c-parser.c
> > > +++ b/gcc/c/c-parser.c
> > > @@ -1255,6 +1255,8 @@ static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
> > >  static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
> > >  static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
> > >  
> > > +static void warn_unclosed_pragma_omp_target ();
> > > +
> > >  /* Parse a translation unit (C90 6.7, C99 6.9).
> > >  
> > >     translation-unit:
> > > @@ -1290,6 +1292,8 @@ c_parser_translation_unit (c_parser *parser)
> > >  	}
> > >        while (c_parser_next_token_is_not (parser, CPP_EOF));
> > >      }
> > > +
> > > +  warn_unclosed_pragma_omp_target ();
> > >  }
> > >  
> > >  /* Parse an external declaration (C90 6.7, C99 6.9).
> > > @@ -13068,8 +13072,10 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
> > >  static void
> > >  c_parser_omp_declare_target (c_parser *parser)
> > >  {
> > > +  location_t loc = c_parser_peek_token (parser)->location;
> > >    c_parser_skip_to_pragma_eol (parser);
> > >    current_omp_declare_target_attribute++;
> > > +  omp_declare_target_location_stack.safe_push (loc);
> > >  }
> > >  
> > >  static void
> > > @@ -13104,7 +13110,10 @@ c_parser_omp_end_declare_target (c_parser *parser)
> > >      error_at (loc, "%<#pragma omp end declare target%> without corresponding "
> > >  		   "%<#pragma omp declare target%>");
> > >    else
> > > -    current_omp_declare_target_attribute--;
> > > +    {
> > > +      current_omp_declare_target_attribute--;
> > > +      omp_declare_target_location_stack.pop ();
> > > +    }
> > >  }
> > >  
> > >  
> > > @@ -14267,4 +14276,15 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
> > >    return value_tree;
> > >  }
> > >  
> > > +static void
> > > +warn_unclosed_pragma_omp_target ()
> > > +{
> > > +  int i;
> > > +  for (i = 0; i < current_omp_declare_target_attribute; i++)
> > > +    warning_at (omp_declare_target_location_stack[i], 0,
> > > +		"%<#pragma omp declare target%> without corresponding "
> > > +		"%<#pragma omp end declare target%>");
> > > +  omp_declare_target_location_stack.release ();
> > > +}
> > > +
> > >  #include "gt-c-c-parser.h"
> > > diff --git a/gcc/testsuite/gcc.dg/gomp/target-3.c b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > new file mode 100644
> > > index 0000000..d50604f
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > @@ -0,0 +1,33 @@
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-fopenmp" } */
> > > +
> > > +#pragma omp declare target
> > > +int tgtv = 6;
> > > +
> > > +int
> > > +tgt (void)
> > > +{
> > > +  tgtv++;
> > > +  return 0;
> > > +}
> > > +#pragma omp end declare target
> > > +
> > > +#pragma omp declare target        /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > +int tgtv1 = 6;
> > > +#pragma omp declare target	  /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > +
> > > +int
> > > +tgt2 (void)
> > > +{
> > > +  tgtv1++;
> > > +  return 0;
> > > +}
> > > +
> > > +#pragma omp declare target
> > > +int
> > > +tgt3 (void)
> > > +{
> > > +  tgtv1++;
> > > +  return 0;
> > > +}
> > > +#pragma omp end declare target
> > > -- 
> > > 1.8.3.1
> > >
Ilya Tocar Oct. 30, 2014, 3:31 p.m. UTC | #4
Ping.
On 20 Oct 19:26, Ilya Tocar wrote:
> Ping.
> 
> On 02 Oct 17:38, Ilya Tocar wrote:
> > Ping.
> > On 15 Aug 16:26, Ilya Tocar wrote:
> > > Ping.
> > > 
> > > On 29 Jul 18:45, Ilya Tocar wrote:
> > > > Hi,
> > > > 
> > > > As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> > > > Gcc should complain about pragma omp declare target without
> > > > corresponding pragma omp end declare target. This patch adds a warning
> > > > for those cases.
> > > > Bootstraps/passes make-check.
> > > > Ok for trunk?
> > > > 
> > > > ChangeLog:
> > > > 
> > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > 
> > > > 	* c-decl.c (omp_declare_target_location_stack): New.
> > > > 	* c-lang.h (omp_declare_target_location_stack): Declare.
> > > > 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> > > > 	(c_parser_translation_unit): Call it.
> > > > 	(c_parser_omp_declare_target): Remeber location.
> > > > 	(c_parser_omp_end_declare_target): Forget location.
> > > > 
> > > > And ChangeLog for testsuite:
> > > > 
> > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > 
> > > > 	* gcc.dg/gomp//target-3.c: New testcase.
> > > > 
> > > > ---
> > > >  gcc/c/c-decl.c                       |  3 +++
> > > >  gcc/c/c-lang.h                       |  3 +++
> > > >  gcc/c/c-parser.c                     | 22 +++++++++++++++++++++-
> > > >  gcc/testsuite/gcc.dg/gomp/target-3.c | 33 +++++++++++++++++++++++++++++++++
> > > >  4 files changed, 60 insertions(+), 1 deletion(-)
> > > >  create mode 100644 gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > 
> > > > diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
> > > > index 2a4b439..2dd5b2c 100644
> > > > --- a/gcc/c/c-decl.c
> > > > +++ b/gcc/c/c-decl.c
> > > > @@ -158,6 +158,9 @@ enum machine_mode c_default_pointer_mode = VOIDmode;
> > > >  /* If non-zero, implicit "omp declare target" attribute is added into the
> > > >     attribute lists.  */
> > > >  int current_omp_declare_target_attribute;
> > > > +
> > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > +vec<location_t> omp_declare_target_location_stack;
> > > >  
> > > >  /* Each c_binding structure describes one binding of an identifier to
> > > >     a decl.  All the decls in a scope - irrespective of namespace - are
> > > > diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
> > > > index e974906..cef995c 100644
> > > > --- a/gcc/c/c-lang.h
> > > > +++ b/gcc/c/c-lang.h
> > > > @@ -59,4 +59,7 @@ struct GTY(()) language_function {
> > > >     attribute lists.  */
> > > >  extern GTY(()) int current_omp_declare_target_attribute;
> > > >  
> > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > +extern vec<location_t> omp_declare_target_location_stack;
> > > > +
> > > >  #endif /* ! GCC_C_LANG_H */
> > > > diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> > > > index e32bf04..0b96fe9 100644
> > > > --- a/gcc/c/c-parser.c
> > > > +++ b/gcc/c/c-parser.c
> > > > @@ -1255,6 +1255,8 @@ static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
> > > >  static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
> > > >  static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
> > > >  
> > > > +static void warn_unclosed_pragma_omp_target ();
> > > > +
> > > >  /* Parse a translation unit (C90 6.7, C99 6.9).
> > > >  
> > > >     translation-unit:
> > > > @@ -1290,6 +1292,8 @@ c_parser_translation_unit (c_parser *parser)
> > > >  	}
> > > >        while (c_parser_next_token_is_not (parser, CPP_EOF));
> > > >      }
> > > > +
> > > > +  warn_unclosed_pragma_omp_target ();
> > > >  }
> > > >  
> > > >  /* Parse an external declaration (C90 6.7, C99 6.9).
> > > > @@ -13068,8 +13072,10 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
> > > >  static void
> > > >  c_parser_omp_declare_target (c_parser *parser)
> > > >  {
> > > > +  location_t loc = c_parser_peek_token (parser)->location;
> > > >    c_parser_skip_to_pragma_eol (parser);
> > > >    current_omp_declare_target_attribute++;
> > > > +  omp_declare_target_location_stack.safe_push (loc);
> > > >  }
> > > >  
> > > >  static void
> > > > @@ -13104,7 +13110,10 @@ c_parser_omp_end_declare_target (c_parser *parser)
> > > >      error_at (loc, "%<#pragma omp end declare target%> without corresponding "
> > > >  		   "%<#pragma omp declare target%>");
> > > >    else
> > > > -    current_omp_declare_target_attribute--;
> > > > +    {
> > > > +      current_omp_declare_target_attribute--;
> > > > +      omp_declare_target_location_stack.pop ();
> > > > +    }
> > > >  }
> > > >  
> > > >  
> > > > @@ -14267,4 +14276,15 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
> > > >    return value_tree;
> > > >  }
> > > >  
> > > > +static void
> > > > +warn_unclosed_pragma_omp_target ()
> > > > +{
> > > > +  int i;
> > > > +  for (i = 0; i < current_omp_declare_target_attribute; i++)
> > > > +    warning_at (omp_declare_target_location_stack[i], 0,
> > > > +		"%<#pragma omp declare target%> without corresponding "
> > > > +		"%<#pragma omp end declare target%>");
> > > > +  omp_declare_target_location_stack.release ();
> > > > +}
> > > > +
> > > >  #include "gt-c-c-parser.h"
> > > > diff --git a/gcc/testsuite/gcc.dg/gomp/target-3.c b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > new file mode 100644
> > > > index 0000000..d50604f
> > > > --- /dev/null
> > > > +++ b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > @@ -0,0 +1,33 @@
> > > > +/* { dg-do compile } */
> > > > +/* { dg-options "-fopenmp" } */
> > > > +
> > > > +#pragma omp declare target
> > > > +int tgtv = 6;
> > > > +
> > > > +int
> > > > +tgt (void)
> > > > +{
> > > > +  tgtv++;
> > > > +  return 0;
> > > > +}
> > > > +#pragma omp end declare target
> > > > +
> > > > +#pragma omp declare target        /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > +int tgtv1 = 6;
> > > > +#pragma omp declare target	  /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > +
> > > > +int
> > > > +tgt2 (void)
> > > > +{
> > > > +  tgtv1++;
> > > > +  return 0;
> > > > +}
> > > > +
> > > > +#pragma omp declare target
> > > > +int
> > > > +tgt3 (void)
> > > > +{
> > > > +  tgtv1++;
> > > > +  return 0;
> > > > +}
> > > > +#pragma omp end declare target
> > > > -- 
> > > > 1.8.3.1
> > > >
Ilya Tocar Nov. 6, 2014, 12:27 p.m. UTC | #5
Ping.
On 30 Oct 18:31, Ilya Tocar wrote:
> Ping.
> On 20 Oct 19:26, Ilya Tocar wrote:
> > Ping.
> > 
> > On 02 Oct 17:38, Ilya Tocar wrote:
> > > Ping.
> > > On 15 Aug 16:26, Ilya Tocar wrote:
> > > > Ping.
> > > > 
> > > > On 29 Jul 18:45, Ilya Tocar wrote:
> > > > > Hi,
> > > > > 
> > > > > As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> > > > > Gcc should complain about pragma omp declare target without
> > > > > corresponding pragma omp end declare target. This patch adds a warning
> > > > > for those cases.
> > > > > Bootstraps/passes make-check.
> > > > > Ok for trunk?
> > > > > 
> > > > > ChangeLog:
> > > > > 
> > > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > > 
> > > > > 	* c-decl.c (omp_declare_target_location_stack): New.
> > > > > 	* c-lang.h (omp_declare_target_location_stack): Declare.
> > > > > 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> > > > > 	(c_parser_translation_unit): Call it.
> > > > > 	(c_parser_omp_declare_target): Remeber location.
> > > > > 	(c_parser_omp_end_declare_target): Forget location.
> > > > > 
> > > > > And ChangeLog for testsuite:
> > > > > 
> > > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > > 
> > > > > 	* gcc.dg/gomp//target-3.c: New testcase.
> > > > > 
> > > > > ---
> > > > >  gcc/c/c-decl.c                       |  3 +++
> > > > >  gcc/c/c-lang.h                       |  3 +++
> > > > >  gcc/c/c-parser.c                     | 22 +++++++++++++++++++++-
> > > > >  gcc/testsuite/gcc.dg/gomp/target-3.c | 33 +++++++++++++++++++++++++++++++++
> > > > >  4 files changed, 60 insertions(+), 1 deletion(-)
> > > > >  create mode 100644 gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > 
> > > > > diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
> > > > > index 2a4b439..2dd5b2c 100644
> > > > > --- a/gcc/c/c-decl.c
> > > > > +++ b/gcc/c/c-decl.c
> > > > > @@ -158,6 +158,9 @@ enum machine_mode c_default_pointer_mode = VOIDmode;
> > > > >  /* If non-zero, implicit "omp declare target" attribute is added into the
> > > > >     attribute lists.  */
> > > > >  int current_omp_declare_target_attribute;
> > > > > +
> > > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > > +vec<location_t> omp_declare_target_location_stack;
> > > > >  
> > > > >  /* Each c_binding structure describes one binding of an identifier to
> > > > >     a decl.  All the decls in a scope - irrespective of namespace - are
> > > > > diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
> > > > > index e974906..cef995c 100644
> > > > > --- a/gcc/c/c-lang.h
> > > > > +++ b/gcc/c/c-lang.h
> > > > > @@ -59,4 +59,7 @@ struct GTY(()) language_function {
> > > > >     attribute lists.  */
> > > > >  extern GTY(()) int current_omp_declare_target_attribute;
> > > > >  
> > > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > > +extern vec<location_t> omp_declare_target_location_stack;
> > > > > +
> > > > >  #endif /* ! GCC_C_LANG_H */
> > > > > diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> > > > > index e32bf04..0b96fe9 100644
> > > > > --- a/gcc/c/c-parser.c
> > > > > +++ b/gcc/c/c-parser.c
> > > > > @@ -1255,6 +1255,8 @@ static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
> > > > >  static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
> > > > >  static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
> > > > >  
> > > > > +static void warn_unclosed_pragma_omp_target ();
> > > > > +
> > > > >  /* Parse a translation unit (C90 6.7, C99 6.9).
> > > > >  
> > > > >     translation-unit:
> > > > > @@ -1290,6 +1292,8 @@ c_parser_translation_unit (c_parser *parser)
> > > > >  	}
> > > > >        while (c_parser_next_token_is_not (parser, CPP_EOF));
> > > > >      }
> > > > > +
> > > > > +  warn_unclosed_pragma_omp_target ();
> > > > >  }
> > > > >  
> > > > >  /* Parse an external declaration (C90 6.7, C99 6.9).
> > > > > @@ -13068,8 +13072,10 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
> > > > >  static void
> > > > >  c_parser_omp_declare_target (c_parser *parser)
> > > > >  {
> > > > > +  location_t loc = c_parser_peek_token (parser)->location;
> > > > >    c_parser_skip_to_pragma_eol (parser);
> > > > >    current_omp_declare_target_attribute++;
> > > > > +  omp_declare_target_location_stack.safe_push (loc);
> > > > >  }
> > > > >  
> > > > >  static void
> > > > > @@ -13104,7 +13110,10 @@ c_parser_omp_end_declare_target (c_parser *parser)
> > > > >      error_at (loc, "%<#pragma omp end declare target%> without corresponding "
> > > > >  		   "%<#pragma omp declare target%>");
> > > > >    else
> > > > > -    current_omp_declare_target_attribute--;
> > > > > +    {
> > > > > +      current_omp_declare_target_attribute--;
> > > > > +      omp_declare_target_location_stack.pop ();
> > > > > +    }
> > > > >  }
> > > > >  
> > > > >  
> > > > > @@ -14267,4 +14276,15 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
> > > > >    return value_tree;
> > > > >  }
> > > > >  
> > > > > +static void
> > > > > +warn_unclosed_pragma_omp_target ()
> > > > > +{
> > > > > +  int i;
> > > > > +  for (i = 0; i < current_omp_declare_target_attribute; i++)
> > > > > +    warning_at (omp_declare_target_location_stack[i], 0,
> > > > > +		"%<#pragma omp declare target%> without corresponding "
> > > > > +		"%<#pragma omp end declare target%>");
> > > > > +  omp_declare_target_location_stack.release ();
> > > > > +}
> > > > > +
> > > > >  #include "gt-c-c-parser.h"
> > > > > diff --git a/gcc/testsuite/gcc.dg/gomp/target-3.c b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > new file mode 100644
> > > > > index 0000000..d50604f
> > > > > --- /dev/null
> > > > > +++ b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > @@ -0,0 +1,33 @@
> > > > > +/* { dg-do compile } */
> > > > > +/* { dg-options "-fopenmp" } */
> > > > > +
> > > > > +#pragma omp declare target
> > > > > +int tgtv = 6;
> > > > > +
> > > > > +int
> > > > > +tgt (void)
> > > > > +{
> > > > > +  tgtv++;
> > > > > +  return 0;
> > > > > +}
> > > > > +#pragma omp end declare target
> > > > > +
> > > > > +#pragma omp declare target        /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > > +int tgtv1 = 6;
> > > > > +#pragma omp declare target	  /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > > +
> > > > > +int
> > > > > +tgt2 (void)
> > > > > +{
> > > > > +  tgtv1++;
> > > > > +  return 0;
> > > > > +}
> > > > > +
> > > > > +#pragma omp declare target
> > > > > +int
> > > > > +tgt3 (void)
> > > > > +{
> > > > > +  tgtv1++;
> > > > > +  return 0;
> > > > > +}
> > > > > +#pragma omp end declare target
> > > > > -- 
> > > > > 1.8.3.1
> > > > >
Ilya Tocar Nov. 19, 2014, 1:34 p.m. UTC | #6
As omp target and offloading support is committed to trunk,
I think it's reasonable to add some new warnings.

On 06 Nov 15:27, Ilya Tocar wrote:
> Ping.
> On 30 Oct 18:31, Ilya Tocar wrote:
> > Ping.
> > On 20 Oct 19:26, Ilya Tocar wrote:
> > > Ping.
> > > 
> > > On 02 Oct 17:38, Ilya Tocar wrote:
> > > > Ping.
> > > > On 15 Aug 16:26, Ilya Tocar wrote:
> > > > > Ping.
> > > > > 
> > > > > On 29 Jul 18:45, Ilya Tocar wrote:
> > > > > > Hi,
> > > > > > 
> > > > > > As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> > > > > > Gcc should complain about pragma omp declare target without
> > > > > > corresponding pragma omp end declare target. This patch adds a warning
> > > > > > for those cases.
> > > > > > Bootstraps/passes make-check.
> > > > > > Ok for trunk?
> > > > > > 
> > > > > > ChangeLog:
> > > > > > 
> > > > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > > > 
> > > > > > 	* c-decl.c (omp_declare_target_location_stack): New.
> > > > > > 	* c-lang.h (omp_declare_target_location_stack): Declare.
> > > > > > 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> > > > > > 	(c_parser_translation_unit): Call it.
> > > > > > 	(c_parser_omp_declare_target): Remeber location.
> > > > > > 	(c_parser_omp_end_declare_target): Forget location.
> > > > > > 
> > > > > > And ChangeLog for testsuite:
> > > > > > 
> > > > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > > > 
> > > > > > 	* gcc.dg/gomp//target-3.c: New testcase.
> > > > > > 
> > > > > > ---
> > > > > >  gcc/c/c-decl.c                       |  3 +++
> > > > > >  gcc/c/c-lang.h                       |  3 +++
> > > > > >  gcc/c/c-parser.c                     | 22 +++++++++++++++++++++-
> > > > > >  gcc/testsuite/gcc.dg/gomp/target-3.c | 33 +++++++++++++++++++++++++++++++++
> > > > > >  4 files changed, 60 insertions(+), 1 deletion(-)
> > > > > >  create mode 100644 gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > > 
> > > > > > diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
> > > > > > index 2a4b439..2dd5b2c 100644
> > > > > > --- a/gcc/c/c-decl.c
> > > > > > +++ b/gcc/c/c-decl.c
> > > > > > @@ -158,6 +158,9 @@ enum machine_mode c_default_pointer_mode = VOIDmode;
> > > > > >  /* If non-zero, implicit "omp declare target" attribute is added into the
> > > > > >     attribute lists.  */
> > > > > >  int current_omp_declare_target_attribute;
> > > > > > +
> > > > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > > > +vec<location_t> omp_declare_target_location_stack;
> > > > > >  
> > > > > >  /* Each c_binding structure describes one binding of an identifier to
> > > > > >     a decl.  All the decls in a scope - irrespective of namespace - are
> > > > > > diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
> > > > > > index e974906..cef995c 100644
> > > > > > --- a/gcc/c/c-lang.h
> > > > > > +++ b/gcc/c/c-lang.h
> > > > > > @@ -59,4 +59,7 @@ struct GTY(()) language_function {
> > > > > >     attribute lists.  */
> > > > > >  extern GTY(()) int current_omp_declare_target_attribute;
> > > > > >  
> > > > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > > > +extern vec<location_t> omp_declare_target_location_stack;
> > > > > > +
> > > > > >  #endif /* ! GCC_C_LANG_H */
> > > > > > diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> > > > > > index e32bf04..0b96fe9 100644
> > > > > > --- a/gcc/c/c-parser.c
> > > > > > +++ b/gcc/c/c-parser.c
> > > > > > @@ -1255,6 +1255,8 @@ static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
> > > > > >  static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
> > > > > >  static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
> > > > > >  
> > > > > > +static void warn_unclosed_pragma_omp_target ();
> > > > > > +
> > > > > >  /* Parse a translation unit (C90 6.7, C99 6.9).
> > > > > >  
> > > > > >     translation-unit:
> > > > > > @@ -1290,6 +1292,8 @@ c_parser_translation_unit (c_parser *parser)
> > > > > >  	}
> > > > > >        while (c_parser_next_token_is_not (parser, CPP_EOF));
> > > > > >      }
> > > > > > +
> > > > > > +  warn_unclosed_pragma_omp_target ();
> > > > > >  }
> > > > > >  
> > > > > >  /* Parse an external declaration (C90 6.7, C99 6.9).
> > > > > > @@ -13068,8 +13072,10 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
> > > > > >  static void
> > > > > >  c_parser_omp_declare_target (c_parser *parser)
> > > > > >  {
> > > > > > +  location_t loc = c_parser_peek_token (parser)->location;
> > > > > >    c_parser_skip_to_pragma_eol (parser);
> > > > > >    current_omp_declare_target_attribute++;
> > > > > > +  omp_declare_target_location_stack.safe_push (loc);
> > > > > >  }
> > > > > >  
> > > > > >  static void
> > > > > > @@ -13104,7 +13110,10 @@ c_parser_omp_end_declare_target (c_parser *parser)
> > > > > >      error_at (loc, "%<#pragma omp end declare target%> without corresponding "
> > > > > >  		   "%<#pragma omp declare target%>");
> > > > > >    else
> > > > > > -    current_omp_declare_target_attribute--;
> > > > > > +    {
> > > > > > +      current_omp_declare_target_attribute--;
> > > > > > +      omp_declare_target_location_stack.pop ();
> > > > > > +    }
> > > > > >  }
> > > > > >  
> > > > > >  
> > > > > > @@ -14267,4 +14276,15 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
> > > > > >    return value_tree;
> > > > > >  }
> > > > > >  
> > > > > > +static void
> > > > > > +warn_unclosed_pragma_omp_target ()
> > > > > > +{
> > > > > > +  int i;
> > > > > > +  for (i = 0; i < current_omp_declare_target_attribute; i++)
> > > > > > +    warning_at (omp_declare_target_location_stack[i], 0,
> > > > > > +		"%<#pragma omp declare target%> without corresponding "
> > > > > > +		"%<#pragma omp end declare target%>");
> > > > > > +  omp_declare_target_location_stack.release ();
> > > > > > +}
> > > > > > +
> > > > > >  #include "gt-c-c-parser.h"
> > > > > > diff --git a/gcc/testsuite/gcc.dg/gomp/target-3.c b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > > new file mode 100644
> > > > > > index 0000000..d50604f
> > > > > > --- /dev/null
> > > > > > +++ b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > > @@ -0,0 +1,33 @@
> > > > > > +/* { dg-do compile } */
> > > > > > +/* { dg-options "-fopenmp" } */
> > > > > > +
> > > > > > +#pragma omp declare target
> > > > > > +int tgtv = 6;
> > > > > > +
> > > > > > +int
> > > > > > +tgt (void)
> > > > > > +{
> > > > > > +  tgtv++;
> > > > > > +  return 0;
> > > > > > +}
> > > > > > +#pragma omp end declare target
> > > > > > +
> > > > > > +#pragma omp declare target        /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > > > +int tgtv1 = 6;
> > > > > > +#pragma omp declare target	  /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > > > +
> > > > > > +int
> > > > > > +tgt2 (void)
> > > > > > +{
> > > > > > +  tgtv1++;
> > > > > > +  return 0;
> > > > > > +}
> > > > > > +
> > > > > > +#pragma omp declare target
> > > > > > +int
> > > > > > +tgt3 (void)
> > > > > > +{
> > > > > > +  tgtv1++;
> > > > > > +  return 0;
> > > > > > +}
> > > > > > +#pragma omp end declare target
> > > > > > -- 
> > > > > > 1.8.3.1
> > > > > >
Ilya Tocar Dec. 4, 2014, 12:18 p.m. UTC | #7
Ping.
On 19 Nov 16:34, Ilya Tocar wrote:
> As omp target and offloading support is committed to trunk,
> I think it's reasonable to add some new warnings.
> 
> On 06 Nov 15:27, Ilya Tocar wrote:
> > Ping.
> > On 30 Oct 18:31, Ilya Tocar wrote:
> > > Ping.
> > > On 20 Oct 19:26, Ilya Tocar wrote:
> > > > Ping.
> > > > 
> > > > On 02 Oct 17:38, Ilya Tocar wrote:
> > > > > Ping.
> > > > > On 15 Aug 16:26, Ilya Tocar wrote:
> > > > > > Ping.
> > > > > > 
> > > > > > On 29 Jul 18:45, Ilya Tocar wrote:
> > > > > > > Hi,
> > > > > > > 
> > > > > > > As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> > > > > > > Gcc should complain about pragma omp declare target without
> > > > > > > corresponding pragma omp end declare target. This patch adds a warning
> > > > > > > for those cases.
> > > > > > > Bootstraps/passes make-check.
> > > > > > > Ok for trunk?
> > > > > > > 
> > > > > > > ChangeLog:
> > > > > > > 
> > > > > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > > > > 
> > > > > > > 	* c-decl.c (omp_declare_target_location_stack): New.
> > > > > > > 	* c-lang.h (omp_declare_target_location_stack): Declare.
> > > > > > > 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> > > > > > > 	(c_parser_translation_unit): Call it.
> > > > > > > 	(c_parser_omp_declare_target): Remeber location.
> > > > > > > 	(c_parser_omp_end_declare_target): Forget location.
> > > > > > > 
> > > > > > > And ChangeLog for testsuite:
> > > > > > > 
> > > > > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > > > > 
> > > > > > > 	* gcc.dg/gomp//target-3.c: New testcase.
> > > > > > > 
> > > > > > > ---
> > > > > > >  gcc/c/c-decl.c                       |  3 +++
> > > > > > >  gcc/c/c-lang.h                       |  3 +++
> > > > > > >  gcc/c/c-parser.c                     | 22 +++++++++++++++++++++-
> > > > > > >  gcc/testsuite/gcc.dg/gomp/target-3.c | 33 +++++++++++++++++++++++++++++++++
> > > > > > >  4 files changed, 60 insertions(+), 1 deletion(-)
> > > > > > >  create mode 100644 gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > > > 
> > > > > > > diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
> > > > > > > index 2a4b439..2dd5b2c 100644
> > > > > > > --- a/gcc/c/c-decl.c
> > > > > > > +++ b/gcc/c/c-decl.c
> > > > > > > @@ -158,6 +158,9 @@ enum machine_mode c_default_pointer_mode = VOIDmode;
> > > > > > >  /* If non-zero, implicit "omp declare target" attribute is added into the
> > > > > > >     attribute lists.  */
> > > > > > >  int current_omp_declare_target_attribute;
> > > > > > > +
> > > > > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > > > > +vec<location_t> omp_declare_target_location_stack;
> > > > > > >  
> > > > > > >  /* Each c_binding structure describes one binding of an identifier to
> > > > > > >     a decl.  All the decls in a scope - irrespective of namespace - are
> > > > > > > diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
> > > > > > > index e974906..cef995c 100644
> > > > > > > --- a/gcc/c/c-lang.h
> > > > > > > +++ b/gcc/c/c-lang.h
> > > > > > > @@ -59,4 +59,7 @@ struct GTY(()) language_function {
> > > > > > >     attribute lists.  */
> > > > > > >  extern GTY(()) int current_omp_declare_target_attribute;
> > > > > > >  
> > > > > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > > > > +extern vec<location_t> omp_declare_target_location_stack;
> > > > > > > +
> > > > > > >  #endif /* ! GCC_C_LANG_H */
> > > > > > > diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> > > > > > > index e32bf04..0b96fe9 100644
> > > > > > > --- a/gcc/c/c-parser.c
> > > > > > > +++ b/gcc/c/c-parser.c
> > > > > > > @@ -1255,6 +1255,8 @@ static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
> > > > > > >  static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
> > > > > > >  static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
> > > > > > >  
> > > > > > > +static void warn_unclosed_pragma_omp_target ();
> > > > > > > +
> > > > > > >  /* Parse a translation unit (C90 6.7, C99 6.9).
> > > > > > >  
> > > > > > >     translation-unit:
> > > > > > > @@ -1290,6 +1292,8 @@ c_parser_translation_unit (c_parser *parser)
> > > > > > >  	}
> > > > > > >        while (c_parser_next_token_is_not (parser, CPP_EOF));
> > > > > > >      }
> > > > > > > +
> > > > > > > +  warn_unclosed_pragma_omp_target ();
> > > > > > >  }
> > > > > > >  
> > > > > > >  /* Parse an external declaration (C90 6.7, C99 6.9).
> > > > > > > @@ -13068,8 +13072,10 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
> > > > > > >  static void
> > > > > > >  c_parser_omp_declare_target (c_parser *parser)
> > > > > > >  {
> > > > > > > +  location_t loc = c_parser_peek_token (parser)->location;
> > > > > > >    c_parser_skip_to_pragma_eol (parser);
> > > > > > >    current_omp_declare_target_attribute++;
> > > > > > > +  omp_declare_target_location_stack.safe_push (loc);
> > > > > > >  }
> > > > > > >  
> > > > > > >  static void
> > > > > > > @@ -13104,7 +13110,10 @@ c_parser_omp_end_declare_target (c_parser *parser)
> > > > > > >      error_at (loc, "%<#pragma omp end declare target%> without corresponding "
> > > > > > >  		   "%<#pragma omp declare target%>");
> > > > > > >    else
> > > > > > > -    current_omp_declare_target_attribute--;
> > > > > > > +    {
> > > > > > > +      current_omp_declare_target_attribute--;
> > > > > > > +      omp_declare_target_location_stack.pop ();
> > > > > > > +    }
> > > > > > >  }
> > > > > > >  
> > > > > > >  
> > > > > > > @@ -14267,4 +14276,15 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
> > > > > > >    return value_tree;
> > > > > > >  }
> > > > > > >  
> > > > > > > +static void
> > > > > > > +warn_unclosed_pragma_omp_target ()
> > > > > > > +{
> > > > > > > +  int i;
> > > > > > > +  for (i = 0; i < current_omp_declare_target_attribute; i++)
> > > > > > > +    warning_at (omp_declare_target_location_stack[i], 0,
> > > > > > > +		"%<#pragma omp declare target%> without corresponding "
> > > > > > > +		"%<#pragma omp end declare target%>");
> > > > > > > +  omp_declare_target_location_stack.release ();
> > > > > > > +}
> > > > > > > +
> > > > > > >  #include "gt-c-c-parser.h"
> > > > > > > diff --git a/gcc/testsuite/gcc.dg/gomp/target-3.c b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > > > new file mode 100644
> > > > > > > index 0000000..d50604f
> > > > > > > --- /dev/null
> > > > > > > +++ b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > > > @@ -0,0 +1,33 @@
> > > > > > > +/* { dg-do compile } */
> > > > > > > +/* { dg-options "-fopenmp" } */
> > > > > > > +
> > > > > > > +#pragma omp declare target
> > > > > > > +int tgtv = 6;
> > > > > > > +
> > > > > > > +int
> > > > > > > +tgt (void)
> > > > > > > +{
> > > > > > > +  tgtv++;
> > > > > > > +  return 0;
> > > > > > > +}
> > > > > > > +#pragma omp end declare target
> > > > > > > +
> > > > > > > +#pragma omp declare target        /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > > > > +int tgtv1 = 6;
> > > > > > > +#pragma omp declare target	  /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > > > > +
> > > > > > > +int
> > > > > > > +tgt2 (void)
> > > > > > > +{
> > > > > > > +  tgtv1++;
> > > > > > > +  return 0;
> > > > > > > +}
> > > > > > > +
> > > > > > > +#pragma omp declare target
> > > > > > > +int
> > > > > > > +tgt3 (void)
> > > > > > > +{
> > > > > > > +  tgtv1++;
> > > > > > > +  return 0;
> > > > > > > +}
> > > > > > > +#pragma omp end declare target
> > > > > > > -- 
> > > > > > > 1.8.3.1
> > > > > > >
Ilya Verbin Jan. 11, 2015, 9:28 p.m. UTC | #8
Ping :)

On 04 Dec 15:18, Ilya Tocar wrote:
> Ping.
> On 19 Nov 16:34, Ilya Tocar wrote:
> > As omp target and offloading support is committed to trunk,
> > I think it's reasonable to add some new warnings.
> > 
> > On 06 Nov 15:27, Ilya Tocar wrote:
> > > Ping.
> > > On 30 Oct 18:31, Ilya Tocar wrote:
> > > > Ping.
> > > > On 20 Oct 19:26, Ilya Tocar wrote:
> > > > > Ping.
> > > > > 
> > > > > On 02 Oct 17:38, Ilya Tocar wrote:
> > > > > > Ping.
> > > > > > On 15 Aug 16:26, Ilya Tocar wrote:
> > > > > > > Ping.
> > > > > > > 
> > > > > > > On 29 Jul 18:45, Ilya Tocar wrote:
> > > > > > > > Hi,
> > > > > > > > 
> > > > > > > > As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> > > > > > > > Gcc should complain about pragma omp declare target without
> > > > > > > > corresponding pragma omp end declare target. This patch adds a warning
> > > > > > > > for those cases.
> > > > > > > > Bootstraps/passes make-check.
> > > > > > > > Ok for trunk?
> > > > > > > > 
> > > > > > > > ChangeLog:
> > > > > > > > 
> > > > > > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > > > > > 
> > > > > > > > 	* c-decl.c (omp_declare_target_location_stack): New.
> > > > > > > > 	* c-lang.h (omp_declare_target_location_stack): Declare.
> > > > > > > > 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> > > > > > > > 	(c_parser_translation_unit): Call it.
> > > > > > > > 	(c_parser_omp_declare_target): Remeber location.
> > > > > > > > 	(c_parser_omp_end_declare_target): Forget location.
> > > > > > > > 
> > > > > > > > And ChangeLog for testsuite:
> > > > > > > > 
> > > > > > > > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > > > > > > > 
> > > > > > > > 	* gcc.dg/gomp//target-3.c: New testcase.
> > > > > > > > 
> > > > > > > > ---
> > > > > > > >  gcc/c/c-decl.c                       |  3 +++
> > > > > > > >  gcc/c/c-lang.h                       |  3 +++
> > > > > > > >  gcc/c/c-parser.c                     | 22 +++++++++++++++++++++-
> > > > > > > >  gcc/testsuite/gcc.dg/gomp/target-3.c | 33 +++++++++++++++++++++++++++++++++
> > > > > > > >  4 files changed, 60 insertions(+), 1 deletion(-)
> > > > > > > >  create mode 100644 gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > > > > 
> > > > > > > > diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
> > > > > > > > index 2a4b439..2dd5b2c 100644
> > > > > > > > --- a/gcc/c/c-decl.c
> > > > > > > > +++ b/gcc/c/c-decl.c
> > > > > > > > @@ -158,6 +158,9 @@ enum machine_mode c_default_pointer_mode = VOIDmode;
> > > > > > > >  /* If non-zero, implicit "omp declare target" attribute is added into the
> > > > > > > >     attribute lists.  */
> > > > > > > >  int current_omp_declare_target_attribute;
> > > > > > > > +
> > > > > > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > > > > > +vec<location_t> omp_declare_target_location_stack;
> > > > > > > >  
> > > > > > > >  /* Each c_binding structure describes one binding of an identifier to
> > > > > > > >     a decl.  All the decls in a scope - irrespective of namespace - are
> > > > > > > > diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
> > > > > > > > index e974906..cef995c 100644
> > > > > > > > --- a/gcc/c/c-lang.h
> > > > > > > > +++ b/gcc/c/c-lang.h
> > > > > > > > @@ -59,4 +59,7 @@ struct GTY(()) language_function {
> > > > > > > >     attribute lists.  */
> > > > > > > >  extern GTY(()) int current_omp_declare_target_attribute;
> > > > > > > >  
> > > > > > > > +/* Holds locations of currently open "omp declare target" pragmas.  */
> > > > > > > > +extern vec<location_t> omp_declare_target_location_stack;
> > > > > > > > +
> > > > > > > >  #endif /* ! GCC_C_LANG_H */
> > > > > > > > diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
> > > > > > > > index e32bf04..0b96fe9 100644
> > > > > > > > --- a/gcc/c/c-parser.c
> > > > > > > > +++ b/gcc/c/c-parser.c
> > > > > > > > @@ -1255,6 +1255,8 @@ static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
> > > > > > > >  static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
> > > > > > > >  static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
> > > > > > > >  
> > > > > > > > +static void warn_unclosed_pragma_omp_target ();
> > > > > > > > +
> > > > > > > >  /* Parse a translation unit (C90 6.7, C99 6.9).
> > > > > > > >  
> > > > > > > >     translation-unit:
> > > > > > > > @@ -1290,6 +1292,8 @@ c_parser_translation_unit (c_parser *parser)
> > > > > > > >  	}
> > > > > > > >        while (c_parser_next_token_is_not (parser, CPP_EOF));
> > > > > > > >      }
> > > > > > > > +
> > > > > > > > +  warn_unclosed_pragma_omp_target ();
> > > > > > > >  }
> > > > > > > >  
> > > > > > > >  /* Parse an external declaration (C90 6.7, C99 6.9).
> > > > > > > > @@ -13068,8 +13072,10 @@ c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
> > > > > > > >  static void
> > > > > > > >  c_parser_omp_declare_target (c_parser *parser)
> > > > > > > >  {
> > > > > > > > +  location_t loc = c_parser_peek_token (parser)->location;
> > > > > > > >    c_parser_skip_to_pragma_eol (parser);
> > > > > > > >    current_omp_declare_target_attribute++;
> > > > > > > > +  omp_declare_target_location_stack.safe_push (loc);
> > > > > > > >  }
> > > > > > > >  
> > > > > > > >  static void
> > > > > > > > @@ -13104,7 +13110,10 @@ c_parser_omp_end_declare_target (c_parser *parser)
> > > > > > > >      error_at (loc, "%<#pragma omp end declare target%> without corresponding "
> > > > > > > >  		   "%<#pragma omp declare target%>");
> > > > > > > >    else
> > > > > > > > -    current_omp_declare_target_attribute--;
> > > > > > > > +    {
> > > > > > > > +      current_omp_declare_target_attribute--;
> > > > > > > > +      omp_declare_target_location_stack.pop ();
> > > > > > > > +    }
> > > > > > > >  }
> > > > > > > >  
> > > > > > > >  
> > > > > > > > @@ -14267,4 +14276,15 @@ c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
> > > > > > > >    return value_tree;
> > > > > > > >  }
> > > > > > > >  
> > > > > > > > +static void
> > > > > > > > +warn_unclosed_pragma_omp_target ()
> > > > > > > > +{
> > > > > > > > +  int i;
> > > > > > > > +  for (i = 0; i < current_omp_declare_target_attribute; i++)
> > > > > > > > +    warning_at (omp_declare_target_location_stack[i], 0,
> > > > > > > > +		"%<#pragma omp declare target%> without corresponding "
> > > > > > > > +		"%<#pragma omp end declare target%>");
> > > > > > > > +  omp_declare_target_location_stack.release ();
> > > > > > > > +}
> > > > > > > > +
> > > > > > > >  #include "gt-c-c-parser.h"
> > > > > > > > diff --git a/gcc/testsuite/gcc.dg/gomp/target-3.c b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > > > > new file mode 100644
> > > > > > > > index 0000000..d50604f
> > > > > > > > --- /dev/null
> > > > > > > > +++ b/gcc/testsuite/gcc.dg/gomp/target-3.c
> > > > > > > > @@ -0,0 +1,33 @@
> > > > > > > > +/* { dg-do compile } */
> > > > > > > > +/* { dg-options "-fopenmp" } */
> > > > > > > > +
> > > > > > > > +#pragma omp declare target
> > > > > > > > +int tgtv = 6;
> > > > > > > > +
> > > > > > > > +int
> > > > > > > > +tgt (void)
> > > > > > > > +{
> > > > > > > > +  tgtv++;
> > > > > > > > +  return 0;
> > > > > > > > +}
> > > > > > > > +#pragma omp end declare target
> > > > > > > > +
> > > > > > > > +#pragma omp declare target        /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > > > > > +int tgtv1 = 6;
> > > > > > > > +#pragma omp declare target	  /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
> > > > > > > > +
> > > > > > > > +int
> > > > > > > > +tgt2 (void)
> > > > > > > > +{
> > > > > > > > +  tgtv1++;
> > > > > > > > +  return 0;
> > > > > > > > +}
> > > > > > > > +
> > > > > > > > +#pragma omp declare target
> > > > > > > > +int
> > > > > > > > +tgt3 (void)
> > > > > > > > +{
> > > > > > > > +  tgtv1++;
> > > > > > > > +  return 0;
> > > > > > > > +}
> > > > > > > > +#pragma omp end declare target
> > > > > > > > -- 
> > > > > > > > 1.8.3.1
> > > > > > > >
Jakub Jelinek Feb. 2, 2015, 12:05 p.m. UTC | #9
On Tue, Jul 29, 2014 at 06:45:01PM +0400, Ilya Tocar wrote:
> Hi,
> 
> As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> Gcc should complain about pragma omp declare target without
> corresponding pragma omp end declare target. This patch adds a warning
> for those cases.
> Bootstraps/passes make-check.
> Ok for trunk?
> 
> ChangeLog:
> 
> 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> 
> 	* c-decl.c (omp_declare_target_location_stack): New.
> 	* c-lang.h (omp_declare_target_location_stack): Declare.
> 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> 	(c_parser_translation_unit): Call it.
> 	(c_parser_omp_declare_target): Remeber location.
> 	(c_parser_omp_end_declare_target): Forget location.

Sorry for the long delay on this.
Can you check what will happen if you have unclosed #pragma omp declare target
in some header you precompile?  If you get the warning during the header
compilation and then not during compilation using that PCH header,
supposedly it might be fine and the patch might be ok as is.

I mean something like
a.h:
#pragma omp declare target
int i;
a.c:
#include "a.c"

#pragma omp declare target
int j;
#pragma omp declare target
int k;

int
main ()
{
}
gcc -fopenmp -o a.gch a.h
gcc -fopenmp -o a a.c

If we wanted to warn even on a.c, supposedly the vector would need to be
marked for GC.

	Jakub
Ilya Tocar March 26, 2015, 3:15 p.m. UTC | #10
On 02 Feb 13:05, Jakub Jelinek wrote:
> On Tue, Jul 29, 2014 at 06:45:01PM +0400, Ilya Tocar wrote:
> > Hi,
> > 
> > As discussed here in https://gcc.gnu.org/ml/gcc/2014-01/msg00189.html
> > Gcc should complain about pragma omp declare target without
> > corresponding pragma omp end declare target. This patch adds a warning
> > for those cases.
> > Bootstraps/passes make-check.
> > Ok for trunk?
> > 
> > ChangeLog:
> > 
> > 2014-07-29  Ilya Tocar  <ilya.tocar@intel.com>
> > 
> > 	* c-decl.c (omp_declare_target_location_stack): New.
> > 	* c-lang.h (omp_declare_target_location_stack): Declare.
> > 	* c-parser.c (warn_unclosed_pragma_omp_target): New.
> > 	(c_parser_translation_unit): Call it.
> > 	(c_parser_omp_declare_target): Remeber location.
> > 	(c_parser_omp_end_declare_target): Forget location.
> 
> Sorry for the long delay on this.
> Can you check what will happen if you have unclosed #pragma omp declare target
> in some header you precompile?  If you get the warning during the header
> compilation and then not during compilation using that PCH header,
> supposedly it might be fine and the patch might be ok as is.
>
I've completely forgot about PCH.
With them this patch fails with segfault.
Moreover even if I fix segfault, we will produce strange results for
something like:
#include "a.h"
#pragma omp end declare target
// some code
> 
> If we wanted to warn even on a.c, supposedly the vector would need to be
> marked for GC.
>
I've tried:

static GTY(()) vec<int,va_gc_atomic>
*omp_declare_target_location_stack;

However it fails with:

vec.h:1118: undefined reference to `gt_pch_nx(int&)'

But in ggc.h (included in c-parser.c) i see

gt_pch_nx (unsigned int)
{
}

So I'm not sure how to properly mark vector for PCH.
diff mbox

Patch

diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 2a4b439..2dd5b2c 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -158,6 +158,9 @@  enum machine_mode c_default_pointer_mode = VOIDmode;
 /* If non-zero, implicit "omp declare target" attribute is added into the
    attribute lists.  */
 int current_omp_declare_target_attribute;
+
+/* Holds locations of currently open "omp declare target" pragmas.  */
+vec<location_t> omp_declare_target_location_stack;
 
 /* Each c_binding structure describes one binding of an identifier to
    a decl.  All the decls in a scope - irrespective of namespace - are
diff --git a/gcc/c/c-lang.h b/gcc/c/c-lang.h
index e974906..cef995c 100644
--- a/gcc/c/c-lang.h
+++ b/gcc/c/c-lang.h
@@ -59,4 +59,7 @@  struct GTY(()) language_function {
    attribute lists.  */
 extern GTY(()) int current_omp_declare_target_attribute;
 
+/* Holds locations of currently open "omp declare target" pragmas.  */
+extern vec<location_t> omp_declare_target_location_stack;
+
 #endif /* ! GCC_C_LANG_H */
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index e32bf04..0b96fe9 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -1255,6 +1255,8 @@  static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context);
 static tree c_parser_array_notation (location_t, c_parser *, tree, tree);
 static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool);
 
+static void warn_unclosed_pragma_omp_target ();
+
 /* Parse a translation unit (C90 6.7, C99 6.9).
 
    translation-unit:
@@ -1290,6 +1292,8 @@  c_parser_translation_unit (c_parser *parser)
 	}
       while (c_parser_next_token_is_not (parser, CPP_EOF));
     }
+
+  warn_unclosed_pragma_omp_target ();
 }
 
 /* Parse an external declaration (C90 6.7, C99 6.9).
@@ -13068,8 +13072,10 @@  c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms,
 static void
 c_parser_omp_declare_target (c_parser *parser)
 {
+  location_t loc = c_parser_peek_token (parser)->location;
   c_parser_skip_to_pragma_eol (parser);
   current_omp_declare_target_attribute++;
+  omp_declare_target_location_stack.safe_push (loc);
 }
 
 static void
@@ -13104,7 +13110,10 @@  c_parser_omp_end_declare_target (c_parser *parser)
     error_at (loc, "%<#pragma omp end declare target%> without corresponding "
 		   "%<#pragma omp declare target%>");
   else
-    current_omp_declare_target_attribute--;
+    {
+      current_omp_declare_target_attribute--;
+      omp_declare_target_location_stack.pop ();
+    }
 }
 
 
@@ -14267,4 +14276,15 @@  c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index,
   return value_tree;
 }
 
+static void
+warn_unclosed_pragma_omp_target ()
+{
+  int i;
+  for (i = 0; i < current_omp_declare_target_attribute; i++)
+    warning_at (omp_declare_target_location_stack[i], 0,
+		"%<#pragma omp declare target%> without corresponding "
+		"%<#pragma omp end declare target%>");
+  omp_declare_target_location_stack.release ();
+}
+
 #include "gt-c-c-parser.h"
diff --git a/gcc/testsuite/gcc.dg/gomp/target-3.c b/gcc/testsuite/gcc.dg/gomp/target-3.c
new file mode 100644
index 0000000..d50604f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gomp/target-3.c
@@ -0,0 +1,33 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+#pragma omp declare target
+int tgtv = 6;
+
+int
+tgt (void)
+{
+  tgtv++;
+  return 0;
+}
+#pragma omp end declare target
+
+#pragma omp declare target        /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
+int tgtv1 = 6;
+#pragma omp declare target	  /* { dg-warning "'#pragma omp declare target' without corresponding '#pragma omp end declare target'" } */
+
+int
+tgt2 (void)
+{
+  tgtv1++;
+  return 0;
+}
+
+#pragma omp declare target
+int
+tgt3 (void)
+{
+  tgtv1++;
+  return 0;
+}
+#pragma omp end declare target