diff mbox series

OpenMP: Add -Wopenmp and use it

Message ID 958dc0d6-7b1f-4a03-b7d4-1e13b47a545b@codesourcery.com
State New
Headers show
Series OpenMP: Add -Wopenmp and use it | expand

Commit Message

Tobias Burnus Nov. 24, 2023, 1:51 p.m. UTC
Following the general trend to add a "[-W...]" to the warning messages
for both better grouping of the warnings and - more importantly - for providing
a means to silence such a warning (or to -Werror= them explicitly), this patch
replaces several '0' by OPT_Wopenmp.

Comments or remarks before I commit it?

Tobias

PS: This does not cover all OpenMP warnings: Besides those '0' that I have missed,
there are also some warnings which use a different -W...  - I have not checked
whether their current -W... value or -Wopenmp makes more sense for them.
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955

Comments

Jakub Jelinek Nov. 24, 2023, 2:08 p.m. UTC | #1
On Fri, Nov 24, 2023 at 02:51:28PM +0100, Tobias Burnus wrote:
> Following the general trend to add a "[-W...]" to the warning messages
> for both better grouping of the warnings and - more importantly - for providing
> a means to silence such a warning (or to -Werror= them explicitly), this patch
> replaces several '0' by OPT_Wopenmp.
> 
> Comments or remarks before I commit it?

LGTM, thanks for working on it.

	Jakub
Christophe Lyon Nov. 27, 2023, 10:20 a.m. UTC | #2
Hi!

On Fri, 24 Nov 2023 at 15:08, Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Fri, Nov 24, 2023 at 02:51:28PM +0100, Tobias Burnus wrote:
> > Following the general trend to add a "[-W...]" to the warning messages
> > for both better grouping of the warnings and - more importantly - for providing
> > a means to silence such a warning (or to -Werror= them explicitly), this patch
> > replaces several '0' by OPT_Wopenmp.
> >
> > Comments or remarks before I commit it?
>
> LGTM, thanks for working on it.
>
>         Jakub
>

I think the lack of final '.' in:
gcc/c-family/c.opt
+ Warn about suspicious OpenMP code

has caused the following regressions:
Running gcc:gcc.misc-tests/help.exp ...
FAIL: compiler driver --help=c option(s): "^ +-.*[^:.]$" absent from
output: "  -Wopenmp                    Warn about suspicious OpenMP
code"
FAIL: compiler driver --help=c++ option(s): "^ +-.*[^:.]$" absent from
output: "  -Wopenmp                    Warn about suspicious OpenMP
code"
FAIL: compiler driver --help=fortran option(s): "^ +-.*[^:.]$" absent
from output: "  -Wopenmp                    Warn about suspicious
OpenMP code"
FAIL: compiler driver --help=warnings option(s): "^ +-.*[^:.]$" absent
from output: "  -Wopenmp                    Warn about suspicious
OpenMP code"

I think you have received a notification from our CI about that?

Can you check it's as simple as that?

Thanks,

Christophe
Jakub Jelinek Nov. 27, 2023, 10:30 a.m. UTC | #3
On Mon, Nov 27, 2023 at 11:20:20AM +0100, Christophe Lyon wrote:
> On Fri, 24 Nov 2023 at 15:08, Jakub Jelinek <jakub@redhat.com> wrote:
> > > Comments or remarks before I commit it?
> >
> > LGTM, thanks for working on it.
> >
> >         Jakub
> >
> 
> I think the lack of final '.' in:
> gcc/c-family/c.opt
> + Warn about suspicious OpenMP code

Tobias has fixed that a few commits later:
r14-5835-g6eb1507107dee3e67e3a136e2917b93cdffba7c4

Sorry for missing that during patch review.

	Jakub
Tobias Burnus Nov. 27, 2023, 10:33 a.m. UTC | #4
Hi,

On 27.11.23 11:20, Christophe Lyon wrote:

> I think the lack of final '.' in:

Indeed - but you are lagging a bit behind:

https://gcc.gnu.org/pipermail/gcc-patches/2023-November/638128.html

[committed] c-family/c.opt (-Wopenmp): Add missing tailing '.'

Fri Nov 24 18:56:21 GMT 2023

Committed as r14-5835-g6eb1507107dee3

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
Christophe Lyon Nov. 27, 2023, 3:06 p.m. UTC | #5
On Mon, 27 Nov 2023 at 11:33, Tobias Burnus <tobias@codesourcery.com> wrote:
>
> Hi,
>
> On 27.11.23 11:20, Christophe Lyon wrote:
>
> > I think the lack of final '.' in:
>
> Indeed - but you are lagging a bit behind:
>
> https://gcc.gnu.org/pipermail/gcc-patches/2023-November/638128.html
>
> [committed] c-family/c.opt (-Wopenmp): Add missing tailing '.'
>
> Fri Nov 24 18:56:21 GMT 2023
>
> Committed as r14-5835-g6eb1507107dee3
>

Great thanks! Sorry for the noise, it's a bit hard and error-prone to
track which regressions have already fixed and/or are being worked on.
Our bisect started at r14-5830, just a bit too early :-)

Thanks,

Christophe


> Tobias
>
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
diff mbox series

Patch

OpenMP: Add -Wopenmp and use it

The new warning has two purposes: First, it makes clearer to the
user that it is about OpenMP and, secondly and more importantly,
it permits to use -Wno-openmp.

The newly added -Wopenmp is enabled by default and replaces the
'0' (always warning) in several OpenMP-related warning calls.
For code shared with OpenACC, it only uses OPT_Wopenmp for
'flag_openmp | flag_openmp_simd'.

gcc/c-family/ChangeLog:

	* c.opt (Wopenmp): Add, enable by default.

gcc/c/ChangeLog:

	* c-parser.cc (c_parser_omp_clause_num_threads,
	c_parser_omp_clause_num_tasks, c_parser_omp_clause_grainsize,
	c_parser_omp_clause_priority, c_parser_omp_clause_schedule,
	c_parser_omp_clause_num_teams, c_parser_omp_clause_thread_limit,
	c_parser_omp_clause_dist_schedule, c_parser_omp_scan_loop_body,
	c_parser_omp_assumption_clauses): Add OPT_Wopenmp to warning_at.

gcc/cp/ChangeLog:

	* parser.cc (cp_parser_omp_clause_dist_schedule,
	cp_parser_omp_scan_loop_body, cp_parser_omp_assumption_clauses):
	Add OPT_Wopenmp to warning_at.
	* semantics.cc (finish_omp_clauses): Likewise.

gcc/ChangeLog:

	* doc/invoke.texi (-Wopenmp): Add.
	* gimplify.cc (gimplify_omp_for): Add OPT_Wopenmp to warning_at.
	* omp-expand.cc (expand_omp_ordered_sink): Likewise.
	* omp-general.cc (omp_check_context_selector): Likewise.
	* omp-low.cc (scan_omp_for, check_omp_nesting_restrictions,
	lower_omp_ordered_clauses): Likewise.
	* omp-simd-clone.cc (simd_clone_clauses_extract): Likewise.

gcc/fortran/ChangeLog:

	* lang.opt (Wopenmp): Add, enabled by dafault and documented in C.
	* openmp.cc (gfc_match_omp_declare_target, resolve_positive_int_expr,
	resolve_nonnegative_int_expr, resolve_omp_clauses,
	gfc_resolve_omp_do_blocks): Use OPT_Wopenmp with gfc_warning{,_now}.

 gcc/c-family/c.opt    |  4 ++++
 gcc/c/c-parser.cc     | 38 +++++++++++++++++++++++---------------
 gcc/cp/parser.cc      | 14 ++++++++------
 gcc/cp/semantics.cc   | 18 ++++++++++--------
 gcc/doc/invoke.texi   |  7 ++++++-
 gcc/fortran/lang.opt  |  4 ++++
 gcc/fortran/openmp.cc | 32 +++++++++++++++++++-------------
 gcc/gimplify.cc       |  4 ++--
 gcc/omp-expand.cc     | 11 ++++++-----
 gcc/omp-general.cc    |  4 ++--
 gcc/omp-low.cc        | 29 +++++++++++++++--------------
 gcc/omp-simd-clone.cc |  8 ++++----
 12 files changed, 103 insertions(+), 70 deletions(-)

diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 3848f378de1..c3d45a6ed96 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -1175,6 +1175,10 @@  Wopenacc-parallelism
 C C++ Var(warn_openacc_parallelism) Warning
 Warn about potentially suboptimal choices related to OpenACC parallelism.
 
+Wopenmp
+C ObjC C++ ObjC++ Warning Var(warn_openmp) Init(1)
+Warn about suspicious OpenMP code
+
 Wopenmp-simd
 C C++ Var(warn_openmp_simd) Warning LangEnabledBy(C C++,Wall)
 Warn if a simd directive is overridden by the vectorizer cost model.
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 371dd29557b..f493d764627 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -16071,7 +16071,7 @@  c_parser_omp_clause_num_threads (c_parser *parser, tree list)
       protected_set_expr_location (c, expr_loc);
       if (c == boolean_true_node)
 	{
-	  warning_at (expr_loc, 0,
+	  warning_at (expr_loc, OPT_Wopenmp,
 		      "%<num_threads%> value must be positive");
 	  t = integer_one_node;
 	}
@@ -16132,7 +16132,8 @@  c_parser_omp_clause_num_tasks (c_parser *parser, tree list)
 	SET_EXPR_LOCATION (c, expr_loc);
       if (c == boolean_true_node)
 	{
-	  warning_at (expr_loc, 0, "%<num_tasks%> value must be positive");
+	  warning_at (expr_loc, OPT_Wopenmp,
+		      "%<num_tasks%> value must be positive");
 	  t = integer_one_node;
 	}
 
@@ -16193,7 +16194,8 @@  c_parser_omp_clause_grainsize (c_parser *parser, tree list)
 	SET_EXPR_LOCATION (c, expr_loc);
       if (c == boolean_true_node)
 	{
-	  warning_at (expr_loc, 0, "%<grainsize%> value must be positive");
+	  warning_at (expr_loc, OPT_Wopenmp,
+		      "%<grainsize%> value must be positive");
 	  t = integer_one_node;
 	}
 
@@ -16241,7 +16243,8 @@  c_parser_omp_clause_priority (c_parser *parser, tree list)
 	SET_EXPR_LOCATION (c, expr_loc);
       if (c == boolean_true_node)
 	{
-	  warning_at (expr_loc, 0, "%<priority%> value must be non-negative");
+	  warning_at (expr_loc, OPT_Wopenmp,
+		      "%<priority%> value must be non-negative");
 	  t = integer_one_node;
 	}
 
@@ -17383,7 +17386,7 @@  c_parser_omp_clause_schedule (c_parser *parser, tree list)
 	  protected_set_expr_location (s, loc);
 	  if (s == boolean_true_node)
 	    {
-	      warning_at (loc, 0,
+	      warning_at (loc, OPT_Wopenmp,
 			  "chunk size value must be positive");
 	      t = integer_one_node;
 	    }
@@ -17545,7 +17548,8 @@  c_parser_omp_clause_num_teams (c_parser *parser, tree list)
       protected_set_expr_location (c, upper_loc);
       if (c == boolean_true_node)
 	{
-	  warning_at (upper_loc, 0, "%<num_teams%> value must be positive");
+	  warning_at (upper_loc, OPT_Wopenmp,
+		      "%<num_teams%> value must be positive");
 	  upper = integer_one_node;
 	}
       if (lower)
@@ -17555,15 +17559,17 @@  c_parser_omp_clause_num_teams (c_parser *parser, tree list)
 	  protected_set_expr_location (c, lower_loc);
 	  if (c == boolean_true_node)
 	    {
-	      warning_at (lower_loc, 0, "%<num_teams%> value must be positive");
+	      warning_at (lower_loc, OPT_Wopenmp,
+			  "%<num_teams%> value must be positive");
 	      lower = NULL_TREE;
 	    }
 	  else if (TREE_CODE (lower) == INTEGER_CST
 		   && TREE_CODE (upper) == INTEGER_CST
 		   && tree_int_cst_lt (upper, lower))
 	    {
-	      warning_at (lower_loc, 0, "%<num_teams%> lower bound %qE bigger "
-					"than upper bound %qE", lower, upper);
+	      warning_at (lower_loc, OPT_Wopenmp,
+			  "%<num_teams%> lower bound %qE bigger than upper "
+			  "bound %qE", lower, upper);
 	      lower = NULL_TREE;
 	    }
 	}
@@ -17610,7 +17616,8 @@  c_parser_omp_clause_thread_limit (c_parser *parser, tree list)
       protected_set_expr_location (c, expr_loc);
       if (c == boolean_true_node)
 	{
-	  warning_at (expr_loc, 0, "%<thread_limit%> value must be positive");
+	  warning_at (expr_loc, OPT_Wopenmp,
+		      "%<thread_limit%> value must be positive");
 	  t = integer_one_node;
 	}
 
@@ -18840,7 +18847,7 @@  c_parser_omp_clause_dist_schedule (c_parser *parser, tree list)
   /* check_no_duplicate_clause (list, OMP_CLAUSE_DIST_SCHEDULE,
 				"dist_schedule"); */
   if (omp_find_clause (list, OMP_CLAUSE_DIST_SCHEDULE))
-    warning_at (loc, 0, "too many %qs clauses", "dist_schedule");
+    warning_at (loc, OPT_Wopenmp, "too many %qs clauses", "dist_schedule");
   if (t == error_mark_node)
     return list;
 
@@ -21893,7 +21900,7 @@  c_parser_omp_scan_loop_body (c_parser *parser, bool open_brace_parsed)
     substmt = c_parser_omp_structured_block_sequence (parser, PRAGMA_OMP_SCAN);
   else
     {
-      warning_at (c_parser_peek_token (parser)->location, 0,
+      warning_at (c_parser_peek_token (parser)->location, OPT_Wopenmp,
 		  "%<#pragma omp scan%> with zero preceding executable "
 		  "statements");
       substmt = build_empty_stmt (loc);
@@ -21941,8 +21948,9 @@  c_parser_omp_scan_loop_body (c_parser *parser, bool open_brace_parsed)
   else
     {
       if (found_scan)
-	warning_at (loc, 0, "%<#pragma omp scan%> with zero succeeding "
-			    "executable statements");
+	warning_at (loc, OPT_Wopenmp,
+		    "%<#pragma omp scan%> with zero succeeding executable "
+		    "statements");
       substmt = build_empty_stmt (loc);
     }
   substmt = build2 (OMP_SCAN, void_type_node, substmt, clauses);
@@ -26248,7 +26256,7 @@  c_parser_omp_assumption_clauses (c_parser *parser, bool is_assume)
 	}
       else if (startswith (p, "ext_"))
 	{
-	  warning_at (cloc, 0, "unknown assumption clause %qs", p);
+	  warning_at (cloc, OPT_Wopenmp, "unknown assumption clause %qs", p);
 	  c_parser_consume_token (parser);
 	  if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
 	    {
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index f6d088bc73f..052560331ef 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -41161,7 +41161,7 @@  cp_parser_omp_clause_dist_schedule (cp_parser *parser, tree list,
   /* check_no_duplicate_clause (list, OMP_CLAUSE_DIST_SCHEDULE,
 				"dist_schedule", location); */
   if (omp_find_clause (list, OMP_CLAUSE_DIST_SCHEDULE))
-    warning_at (location, 0, "too many %qs clauses", "dist_schedule");
+    warning_at (location, OPT_Wopenmp, "too many %qs clauses", "dist_schedule");
   OMP_CLAUSE_CHAIN (c) = list;
   return c;
 
@@ -44083,8 +44083,9 @@  cp_parser_omp_scan_loop_body (cp_parser *parser)
     substmt = cp_parser_omp_structured_block_sequence (parser, PRAGMA_OMP_SCAN);
   else
     {
-      warning_at (tok->location, 0, "%<#pragma omp scan%> with zero preceding "
-				    "executable statements");
+      warning_at (tok->location, OPT_Wopenmp,
+		  "%<#pragma omp scan%> with zero preceding executable "
+		  "statements");
       substmt = build_empty_stmt (tok->location);
     }
   substmt = build2 (OMP_SCAN, void_type_node, substmt, NULL_TREE);
@@ -44130,8 +44131,9 @@  cp_parser_omp_scan_loop_body (cp_parser *parser)
   else
     {
       if (found_scan)
-	warning_at (tok->location, 0, "%<#pragma omp scan%> with zero "
-				      "succeeding executable statements");
+	warning_at (tok->location, OPT_Wopenmp,
+		    "%<#pragma omp scan%> with zero succeeding executable "
+		    "statements");
       substmt = build_empty_stmt (tok->location);
     }
   substmt = build2_loc (tok->location, OMP_SCAN, void_type_node, substmt,
@@ -47828,7 +47830,7 @@  cp_parser_omp_assumption_clauses (cp_parser *parser, cp_token *pragma_tok,
 	}
       else if (startswith (p, "ext_"))
 	{
-	  warning_at (cloc, 0, "unknown assumption clause %qs", p);
+	  warning_at (cloc, OPT_Wopenmp, "unknown assumption clause %qs", p);
 	  cp_lexer_consume_token (parser->lexer);
 	  if (cp_lexer_next_token_is (parser->lexer, CPP_OPEN_PAREN))
 	    for (size_t n = cp_parser_skip_balanced_tokens (parser, 1) - 1;
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index f0a8372683d..3bf586453dc 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -7561,7 +7561,9 @@  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 				      "positive");
 			  break;
 			default:
-			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
+			  warning_at (OMP_CLAUSE_LOCATION (c),
+				      (flag_openmp || flag_openmp_simd)
+				      ? OPT_Wopenmp : 0,
 				      "%qs value must be positive",
 				      omp_clause_code_name
 				      [OMP_CLAUSE_CODE (c)]);
@@ -7596,7 +7598,7 @@  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 		      if (TREE_CODE (t) == INTEGER_CST
 			  && tree_int_cst_sgn (t) != 1)
 			{
-			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
+			  warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
 				      "%qs value must be positive",
 				      omp_clause_code_name
 				      [OMP_CLAUSE_CODE (c)]);
@@ -7610,7 +7612,7 @@  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 			  && TREE_CODE (upper) == INTEGER_CST
 			  && tree_int_cst_lt (upper, t))
 			{
-			  warning_at (OMP_CLAUSE_LOCATION (c), 0,
+			  warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
 				      "%<num_teams%> lower bound %qE bigger "
 				      "than upper bound %qE", t, upper);
 			  t = NULL_TREE;
@@ -7643,7 +7645,7 @@  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 		  if (TREE_CODE (t) == INTEGER_CST
 		      && tree_int_cst_sgn (t) != 1)
 		  {
-		    warning_at (OMP_CLAUSE_LOCATION (c), 0,
+		    warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
 			      "chunk size value must be positive");
 		    t = integer_one_node;
 		  }
@@ -7739,7 +7741,7 @@  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 		  if (TREE_CODE (t) == INTEGER_CST
 		      && tree_int_cst_sgn (t) != 1)
 		    {
-		      warning_at (OMP_CLAUSE_LOCATION (c), 0,
+		      warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
 				  "%<thread_limit%> value must be positive");
 		      t = integer_one_node;
 		    }
@@ -7935,7 +7937,7 @@  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 	    }
 	  else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
 	    {
-	      warning_at (OMP_CLAUSE_LOCATION (c), 0,
+	      warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
 			"%qD appears more than once in %<allocate%> clauses",
 			t);
 	      remove = true;
@@ -8707,7 +8709,7 @@  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 		  if (TREE_CODE (t) == INTEGER_CST
 		      && tree_int_cst_sgn (t) != 1)
 		    {
-		      warning_at (OMP_CLAUSE_LOCATION (c), 0,
+		      warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
 				  "%<grainsize%> value must be positive");
 		      t = integer_one_node;
 		    }
@@ -8737,7 +8739,7 @@  finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
 		  if (TREE_CODE (t) == INTEGER_CST
 		      && tree_int_cst_sgn (t) == -1)
 		    {
-		      warning_at (OMP_CLAUSE_LOCATION (c), 0,
+		      warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
 				  "%<priority%> value must be non-negative");
 		      t = integer_one_node;
 		    }
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 7801f80ff3c..23e2b7415b1 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -383,7 +383,7 @@  Objective-C and Objective-C++ Dialects}.
 -Wnormalized=@r{[}none@r{|}id@r{|}nfc@r{|}nfkc@r{]}
 -Wnull-dereference  -Wno-odr
 -Wopenacc-parallelism
--Wopenmp-simd
+-Wopenmp -Wopenmp-simd
 -Wno-overflow  -Woverlength-strings  -Wno-override-init-side-effects
 -Wpacked  -Wno-packed-bitfield-compat  -Wpacked-not-aligned  -Wpadded
 -Wparentheses  -Wno-pedantic-ms-format
@@ -9957,6 +9957,11 @@  Enabled by default.
 @item -Wopenacc-parallelism
 Warn about potentially suboptimal choices related to OpenACC parallelism.
 
+@opindex Wopenmp
+@opindex Wno-openmp
+@item -Wno-openmp
+Warn about suspicious OpenMP code.
+
 @opindex Wopenmp-simd
 @opindex Wno-openmp-simd
 @item -Wopenmp-simd
diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt
index 08c75394aa0..adcfc280b5a 100644
--- a/gcc/fortran/lang.opt
+++ b/gcc/fortran/lang.opt
@@ -289,6 +289,10 @@  Wopenacc-parallelism
 Fortran
 ; Documented in C
 
+Wopenmp
+Fortran
+; Documented in C
+
 Wopenmp-simd
 Fortran
 ; Documented in C
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 2e2e23d567b..c71014908a2 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -21,6 +21,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
+#include "options.h"
 #include "gfortran.h"
 #include "arith.h"
 #include "match.h"
@@ -5553,8 +5554,9 @@  gfc_match_omp_declare_target (void)
       && !c->lists[OMP_LIST_ENTER]
       && !c->lists[OMP_LIST_TO]
       && !c->lists[OMP_LIST_LINK])
-    gfc_warning_now (0, "OMP DECLARE TARGET directive at %L with only "
-			"DEVICE_TYPE clause is ignored", &old_loc);
+    gfc_warning_now (OPT_Wopenmp,
+		     "OMP DECLARE TARGET directive at %L with only "
+		     "DEVICE_TYPE clause is ignored", &old_loc);
 
   gfc_buffer_error (true);
 
@@ -7020,7 +7022,8 @@  resolve_positive_int_expr (gfc_expr *expr, const char *clause)
   if (expr->expr_type == EXPR_CONSTANT
       && expr->ts.type == BT_INTEGER
       && mpz_sgn (expr->value.integer) <= 0)
-    gfc_warning (0, "INTEGER expression of %s clause at %L must be positive",
+    gfc_warning ((flag_openmp || flag_openmp_simd) ? OPT_Wopenmp : 0,
+		 "INTEGER expression of %s clause at %L must be positive",
 		 clause, &expr->where);
 }
 
@@ -7031,8 +7034,9 @@  resolve_nonnegative_int_expr (gfc_expr *expr, const char *clause)
   if (expr->expr_type == EXPR_CONSTANT
       && expr->ts.type == BT_INTEGER
       && mpz_sgn (expr->value.integer) < 0)
-    gfc_warning (0, "INTEGER expression of %s clause at %L must be "
-		 "non-negative", clause, &expr->where);
+    gfc_warning ((flag_openmp || flag_openmp_simd) ? OPT_Wopenmp : 0,
+		 "INTEGER expression of %s clause at %L must be non-negative",
+		 clause, &expr->where);
 }
 
 /* Emits error when symbol is pointer, cray pointer or cray pointee
@@ -7595,8 +7599,8 @@  resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
       else if (expr->expr_type == EXPR_CONSTANT
 	       && expr->ts.type == BT_INTEGER
 	       && mpz_sgn (expr->value.integer) <= 0)
-	gfc_warning (0, "INTEGER expression of SCHEDULE clause's chunk_size "
-		     "at %L must be positive", &expr->where);
+	gfc_warning (OPT_Wopenmp, "INTEGER expression of SCHEDULE clause's "
+		     "chunk_size at %L must be positive", &expr->where);
     }
   if (omp_clauses->sched_kind != OMP_SCHED_NONE
       && omp_clauses->sched_nonmonotonic)
@@ -7906,8 +7910,8 @@  resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
 	    }
 	  if (n->sym->mark == 1)
 	    {
-	      gfc_warning (0, "%qs appears more than once in %<allocate%> "
-			   "at %L" , n->sym->name, &n->where);
+	      gfc_warning (OPT_Wopenmp, "%qs appears more than once in "
+			   "%<allocate%> at %L" , n->sym->name, &n->where);
 	      /* We have already seen this variable so it is a duplicate.
 		 Remove it.  */
 	      if (prev != NULL && prev->next == n)
@@ -8905,8 +8909,8 @@  resolve_omp_clauses (gfc_code *code, gfc_omp_clauses *omp_clauses,
       && omp_clauses->num_teams_upper->expr_type == EXPR_CONSTANT
       && mpz_cmp (omp_clauses->num_teams_lower->value.integer,
 		  omp_clauses->num_teams_upper->value.integer) > 0)
-    gfc_warning (0, "NUM_TEAMS lower bound at %L larger than upper bound at %L",
-		 &omp_clauses->num_teams_lower->where,
+    gfc_warning (OPT_Wopenmp, "NUM_TEAMS lower bound at %L larger than upper "
+		 "bound at %L", &omp_clauses->num_teams_lower->where,
 		 &omp_clauses->num_teams_upper->where);
   if (omp_clauses->device)
     resolve_scalar_int_expr (omp_clauses->device, "DEVICE");
@@ -9743,13 +9747,15 @@  gfc_resolve_omp_do_blocks (gfc_code *code, gfc_namespace *ns)
 	      else
 		{
 		  if (block->op == EXEC_OMP_SCAN)
-		    gfc_warning (0, "!$OMP SCAN at %L with zero executable "
+		    gfc_warning (OPT_Wopenmp,
+				 "!$OMP SCAN at %L with zero executable "
 				 "statements in preceding structured block "
 				 "sequence", &block->loc);
 		  if ((block->op == EXEC_OMP_SCAN && !block->next)
 		      || (block->next && block->next->op == EXEC_OMP_SCAN
 			  && !block->next->next))
-		    gfc_warning (0, "!$OMP SCAN at %L with zero executable "
+		    gfc_warning (OPT_Wopenmp,
+				 "!$OMP SCAN at %L with zero executable "
 				 "statements in succeeding structured block "
 				 "sequence", block->op == EXEC_OMP_SCAN
 				 ? &block->loc : &block->next->loc);
diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index d52d71b9b6b..02f85e7109b 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -14382,7 +14382,7 @@  gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
 					       OMP_CLAUSE_LASTPRIVATE))
 		  if (OMP_CLAUSE_DECL (c3) == decl)
 		    {
-		      warning_at (OMP_CLAUSE_LOCATION (c3), 0,
+		      warning_at (OMP_CLAUSE_LOCATION (c3), OPT_Wopenmp,
 				  "conditional %<lastprivate%> on loop "
 				  "iterator %qD ignored", decl);
 		      OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c3) = 0;
@@ -14490,7 +14490,7 @@  gimplify_omp_for (tree *expr_p, gimple_seq *pre_p)
 					   OMP_CLAUSE_LASTPRIVATE))
 	      if (OMP_CLAUSE_DECL (c3) == decl)
 		{
-		  warning_at (OMP_CLAUSE_LOCATION (c3), 0,
+		  warning_at (OMP_CLAUSE_LOCATION (c3), OPT_Wopenmp,
 			      "conditional %<lastprivate%> on loop "
 			      "iterator %qD ignored", decl);
 		  OMP_CLAUSE_LASTPRIVATE_CONDITIONAL (c3) = 0;
diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc
index 5c6a7f2e381..8281ec67e00 100644
--- a/gcc/omp-expand.cc
+++ b/gcc/omp-expand.cc
@@ -3416,8 +3416,9 @@  expand_omp_ordered_sink (gimple_stmt_iterator *gsi, struct omp_for_data *fd,
 	      forward = tree_int_cst_sgn (step) != -1;
 	    }
 	  if (forward ^ OMP_CLAUSE_DOACROSS_SINK_NEGATIVE (deps))
-	    warning_at (loc, 0, "%qs clause with %<sink%> modifier "
-				"waiting for lexically later iteration",
+	    warning_at (loc, OPT_Wopenmp,
+			"%qs clause with %<sink%> modifier "
+			"waiting for lexically later iteration",
 			OMP_CLAUSE_DOACROSS_DEPEND (c)
 			? "depend" : "doacross");
 	  break;
@@ -3555,9 +3556,9 @@  expand_omp_ordered_sink (gimple_stmt_iterator *gsi, struct omp_for_data *fd,
 			       build_int_cst (itype, 0));
 	  if (integer_zerop (t) && !warned_step)
 	    {
-	      warning_at (loc, 0, "%qs clause with %<sink%> modifier "
-				  "refers to iteration never in the iteration "
-				  "space",
+	      warning_at (loc, OPT_Wopenmp,
+			  "%qs clause with %<sink%> modifier refers to "
+			  "iteration never in the iteration space",
 			  OMP_CLAUSE_DOACROSS_DEPEND (c)
 			  ? "depend" : "doacross");
 	      warned_step = true;
diff --git a/gcc/omp-general.cc b/gcc/omp-general.cc
index b88d5930aab..8241574651d 100644
--- a/gcc/omp-general.cc
+++ b/gcc/omp-general.cc
@@ -1201,12 +1201,12 @@  omp_check_context_selector (location_t loc, tree ctx)
 			  return error_mark_node;
 			}
 		      else if (TREE_PURPOSE (t2))
-			warning_at (loc, 0,
+			warning_at (loc, OPT_Wopenmp,
 				    "unknown property %qs of %qs selector",
 				    IDENTIFIER_POINTER (TREE_PURPOSE (t2)),
 				    props[i].selector);
 		      else
-			warning_at (loc, 0,
+			warning_at (loc, OPT_Wopenmp,
 				    "unknown property %qE of %qs selector",
 				    TREE_VALUE (t2), props[i].selector);
 		      break;
diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc
index 161bcfeec05..dd802ca37a6 100644
--- a/gcc/omp-low.cc
+++ b/gcc/omp-low.cc
@@ -2844,12 +2844,13 @@  scan_omp_for (gomp_for *stmt, omp_context *outer_ctx)
 	      tree_code outer_op = OMP_CLAUSE_REDUCTION_CODE (outer_clause);
 	      if (outer_var == local_var && outer_op != local_op)
 		{
-		  warning_at (OMP_CLAUSE_LOCATION (local_clause), 0,
-			      "conflicting reduction operations for %qE",
-			      local_var);
-		  inform (OMP_CLAUSE_LOCATION (outer_clause),
-			  "location of the previous reduction for %qE",
-			  outer_var);
+		  if (warning_at (OMP_CLAUSE_LOCATION (local_clause),
+				  OPT_Wopenmp, "conflicting reduction "
+					       "operations for %qE",
+				  local_var))
+		    inform (OMP_CLAUSE_LOCATION (outer_clause),
+			    "location of the previous reduction for %qE",
+			    outer_var);
 		}
 	      if (outer_var == local_var)
 		{
@@ -2880,7 +2881,7 @@  scan_omp_for (gomp_for *stmt, omp_context *outer_ctx)
 			}
 		    }
 		  if (!found)
-		    warning_at (gimple_location (curr_loop->stmt), 0,
+		    warning_at (gimple_location (curr_loop->stmt), OPT_Wopenmp,
 				"nested loop in reduction needs "
 				"reduction clause for %qE",
 				local_var);
@@ -3427,12 +3428,12 @@  check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx)
 		  ctx->cancellable = true;
 		  if (omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
 				       OMP_CLAUSE_NOWAIT))
-		    warning_at (gimple_location (stmt), 0,
+		    warning_at (gimple_location (stmt), OPT_Wopenmp,
 				"%<cancel for%> inside "
 				"%<nowait%> for construct");
 		  if (omp_find_clause (gimple_omp_for_clauses (ctx->stmt),
 				       OMP_CLAUSE_ORDERED))
-		    warning_at (gimple_location (stmt), 0,
+		    warning_at (gimple_location (stmt), OPT_Wopenmp,
 				"%<cancel for%> inside "
 				"%<ordered%> for construct");
 		}
@@ -3452,7 +3453,7 @@  check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx)
 		      if (omp_find_clause (gimple_omp_sections_clauses
 								(ctx->stmt),
 					   OMP_CLAUSE_NOWAIT))
-			warning_at (gimple_location (stmt), 0,
+			warning_at (gimple_location (stmt), OPT_Wopenmp,
 				    "%<cancel sections%> inside "
 				    "%<nowait%> sections construct");
 		    }
@@ -3465,7 +3466,7 @@  check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx)
 		      if (omp_find_clause (gimple_omp_sections_clauses
 							(ctx->outer->stmt),
 					   OMP_CLAUSE_NOWAIT))
-			warning_at (gimple_location (stmt), 0,
+			warning_at (gimple_location (stmt), OPT_Wopenmp,
 				    "%<cancel sections%> inside "
 				    "%<nowait%> sections construct");
 		    }
@@ -3928,7 +3929,7 @@  check_omp_nesting_restrictions (gimple *stmt, omp_context *ctx)
 		      if (c && OMP_CLAUSE_DEVICE_ANCESTOR (c))
 			break;
 		    }
-		  warning_at (gimple_location (stmt), 0,
+		  warning_at (gimple_location (stmt), OPT_Wopenmp,
 			      "%qs construct inside of %qs region",
 			      stmt_name, ctx_stmt_name);
 		}
@@ -9783,8 +9784,8 @@  lower_omp_ordered_clauses (gimple_stmt_iterator *gsi_p, gomp_ordered *ord_stmt,
 				  wi::abs (wi::to_wide (fd.loops[i].step)),
 				  UNSIGNED))
 	    {
-	      warning_at (OMP_CLAUSE_LOCATION (c), 0,
-			  "ignoring sink clause with offset that is not "
+	      warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp,
+			  "ignoring %<sink%> clause with offset that is not "
 			  "a multiple of the loop step");
 	      remove = true;
 	      goto next_ordered_clause;
diff --git a/gcc/omp-simd-clone.cc b/gcc/omp-simd-clone.cc
index 57b0793e1ad..3fbe4281252 100644
--- a/gcc/omp-simd-clone.cc
+++ b/gcc/omp-simd-clone.cc
@@ -387,13 +387,13 @@  simd_clone_clauses_extract (struct cgraph_node *node, tree clauses,
 		  step = fold_convert (ssizetype, step);
 		if (!tree_fits_shwi_p (step))
 		  {
-		    warning_at (OMP_CLAUSE_LOCATION (t), 0,
+		    warning_at (OMP_CLAUSE_LOCATION (t), OPT_Wopenmp,
 				"ignoring large linear step");
 		    return NULL;
 		  }
 		else if (integer_zerop (step))
 		  {
-		    warning_at (OMP_CLAUSE_LOCATION (t), 0,
+		    warning_at (OMP_CLAUSE_LOCATION (t), OPT_Wopenmp,
 				"ignoring zero linear step");
 		    return NULL;
 		  }
@@ -455,7 +455,7 @@  simd_clone_clauses_extract (struct cgraph_node *node, tree clauses,
  out:
   if (TYPE_ATOMIC (TREE_TYPE (TREE_TYPE (node->decl))))
     {
-      warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
+      warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wopenmp,
 		  "ignoring %<#pragma omp declare simd%> on function "
 		  "with %<_Atomic%> qualified return type");
       return NULL;
@@ -465,7 +465,7 @@  simd_clone_clauses_extract (struct cgraph_node *node, tree clauses,
     if (TYPE_ATOMIC (args[argno])
 	&& clone_info->args[argno].arg_type != SIMD_CLONE_ARG_TYPE_UNIFORM)
       {
-	warning_at (DECL_SOURCE_LOCATION (node->decl), 0,
+	warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wopenmp,
 		    "ignoring %<#pragma omp declare simd%> on function "
 		    "with %<_Atomic%> qualified non-%<uniform%> argument");
 	args.release ();