diff mbox

[1/2] Fix new -Wparentheses warnings encountered during bootstrap

Message ID alpine.DEB.2.20.11.1603311654260.1308@idea
State New
Headers show

Commit Message

Patrick Palka March 31, 2016, 8:57 p.m. UTC
On Thu, 31 Mar 2016, Patrick Palka wrote:

> This patch fixes the new -Wparentheses warnings (implemented by the
> subsequent patch) that are encountered during bootstrap:
> 
> /home/patrick/code/gcc/gcc/omp-low.c: In function ‘void scan_sharing_clauses(tree, omp_context*, bool)’:
> /home/patrick/code/gcc/gcc/omp-low.c:2381:6: error: suggest explicit braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>    if (scan_array_reductions)
>       ^
> /home/patrick/code/gcc/gcc/gimplify.c: In function ‘gimple* gimplify_omp_ordered(tree, gimple_seq)’:
> /home/patrick/code/gcc/gcc/gimplify.c:9880:6: error: suggest explicit braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>    if (gimplify_omp_ctxp)
>       ^
> In file included from /home/patrick/code/gcc/gcc/cp/optimize.c:25:0:
> /home/patrick/code/gcc/gcc/cp/optimize.c: In function ‘void populate_clone_array(tree, tree_node**)’:
> /home/patrick/code/gcc/gcc/cp/cp-tree.h:2529:6: error: suggest explicit braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>    if (TREE_CODE (FN) == FUNCTION_DECL   \
>       ^
> /home/patrick/code/gcc/gcc/cp/optimize.c:222:3: note: in expansion of macro ‘FOR_EACH_CLONE’
>    FOR_EACH_CLONE (clone, fn)
>    ^~~~~~~~~~~~~~
> /home/patrick/code/gcc/gcc/fortran/openmp.c: In function ‘gfc_omp_udr* gfc_find_omp_udr(gfc_namespace*, const char*, gfc_typespec*)’:
> /home/patrick/code/gcc/gcc/fortran/openmp.c:177:10: error: suggest explicit braces to avoid ambiguous ‘else’ [-Werror=parentheses]
>        if (st != NULL)
>           ^
> 
> In each case I think the warning is harmless since the indentation of
> the code in question corresponds to how the "else" is actually parsed
> so I fixed each case simply by enclosing the entire body of the outer
> "if" in braces.
> 
> The FOR_EACH_CLONE change resolves the cp/optimize.c warning.  It
> adjusts the layout of the macro from
> 
>   if (p)
>     for (...)
> 
> to
> 
>   if (!p)
>     ;
>   else for (...)
> 
> so that an "else" encountered in the body of the for-statement can no
> longer possibly bind to the outer "if (p)" conditional.
> 
> Is this OK to commit after bootstrap + regtesting?
> 
> gcc/cp/ChangeLog:
> 
> 	PR c/70436
> 	* cp-tree.h (FOR_EACH_CLONE): Restructure macro to avoid
> 	potentially generating a future -Wparentheses warning in its
> 	callers.
> 
> gcc/fortran/ChangeLog:
> 
> 	PR c/70436
> 	* openmp.c (gfc_find_omp_udr): Add explicit braces to resolve a
> 	future -Wparentheses warning.
> 
> gcc/ChangeLog:
> 
> 	PR c/70436
> 	* gimplify.c (gimplify_omp_ordered): Add explicit braces to
> 	resolve a future -Wparentheses warning.
> 	* omp-low.c (scan_sharing_clauses): Likewise.
> 
> gcc/testsuite/ChangeLog:
> 
> 	PR c/70436
> 	* g++.dg/plugin/pragma_plugin.c (handle_pragma_sayhello): Add
> 	explicit braces to resolve a future -Wparentheses warning.

Here's a diff -w of the same patch:

---
 gcc/cp/cp-tree.h                            | 7 ++++---
 gcc/fortran/openmp.c                        | 2 ++
 gcc/gimplify.c                              | 2 ++
 gcc/omp-low.c                               | 2 ++
 gcc/testsuite/g++.dg/plugin/pragma_plugin.c | 2 ++
 5 files changed, 12 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index b7b770f..65f5693 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -2526,10 +2526,11 @@  struct GTY(()) lang_decl {
 
   */
 #define FOR_EACH_CLONE(CLONE, FN)			\
-  if (TREE_CODE (FN) == FUNCTION_DECL			\
+  if (!(TREE_CODE (FN) == FUNCTION_DECL			\
 	&& (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (FN)	\
-	  || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN)))	\
-     for (CLONE = DECL_CHAIN (FN);			\
+	    || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (FN))))\
+    ;							\
+  else for (CLONE = DECL_CHAIN (FN);			\
 	    CLONE && DECL_CLONED_FUNCTION_P (CLONE);	\
 	    CLONE = DECL_CHAIN (CLONE))
 
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index a6c39cd..0dd1a92 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -175,6 +175,7 @@  gfc_find_omp_udr (gfc_namespace *ns, const char *name, gfc_typespec *ts)
 
       st = gfc_find_symtree (ns->omp_udr_root, name);
       if (st != NULL)
+	{
 	  for (omp_udr = st->n.omp_udr; omp_udr; omp_udr = omp_udr->next)
 	    if (ts == NULL)
 	      return omp_udr;
@@ -193,6 +194,7 @@  gfc_find_omp_udr (gfc_namespace *ns, const char *name, gfc_typespec *ts)
 		  }
 		return omp_udr;
 	      }
+	}
 
       /* Don't escape an interface block.  */
       if (ns && !ns->has_import_set
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 26b5a10..1c824fa 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -9878,6 +9878,7 @@  gimplify_omp_ordered (tree expr, gimple_seq body)
   tree sink_c = NULL_TREE;
 
   if (gimplify_omp_ctxp)
+    {
       for (c = OMP_ORDERED_CLAUSES (expr); c; c = OMP_CLAUSE_CHAIN (c))
 	if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
 	    && gimplify_omp_ctxp->loop_iter_var.is_empty ()
@@ -9936,6 +9937,7 @@  gimplify_omp_ordered (tree expr, gimple_seq body)
 	    else
 	      source_c = c;
 	  }
+    }
   if (source_c && sink_c)
     {
       error_at (OMP_CLAUSE_LOCATION (source_c),
diff --git a/gcc/omp-low.c b/gcc/omp-low.c
index 3fd6eb3..df328f9 100644
--- a/gcc/omp-low.c
+++ b/gcc/omp-low.c
@@ -2379,6 +2379,7 @@  scan_sharing_clauses (tree clauses, omp_context *ctx,
   gcc_checking_assert (!scan_array_reductions
 		       || !is_gimple_omp_oacc (ctx->stmt));
   if (scan_array_reductions)
+    {
       for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
 	if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
 	    && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
@@ -2393,6 +2394,7 @@  scan_sharing_clauses (tree clauses, omp_context *ctx,
 		 && OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c))
 	  scan_omp (&OMP_CLAUSE_LINEAR_GIMPLE_SEQ (c), ctx);
     }
+}
 
 /* Create a new name for omp child function.  Returns an identifier.  If
    IS_CILK_FOR is true then the suffix for the child function is
diff --git a/gcc/testsuite/g++.dg/plugin/pragma_plugin.c b/gcc/testsuite/g++.dg/plugin/pragma_plugin.c
index 940c302..6794c95 100644
--- a/gcc/testsuite/g++.dg/plugin/pragma_plugin.c
+++ b/gcc/testsuite/g++.dg/plugin/pragma_plugin.c
@@ -32,6 +32,7 @@  handle_pragma_sayhello (cpp_reader *dummy)
       return;
     }
   if (TREE_STRING_LENGTH (message) > 1)
+    {
       if (cfun)
         warning (OPT_Wpragmas, 
 	        "%<pragma GCCPLUGIN sayhello%> from function %qE: %s",
@@ -41,6 +42,7 @@  handle_pragma_sayhello (cpp_reader *dummy)
 	    "%<pragma GCCPLUGIN sayhello%> outside of function: %s",
 	    TREE_STRING_POINTER (message));
     }
+}
 
 /* Plugin callback called during pragma registration */