diff mbox series

expr: Workaround profiledbootstrap uninit false positive [PR103899]

Message ID 20220106083840.GV2646553@tucnak
State New
Headers show
Series expr: Workaround profiledbootstrap uninit false positive [PR103899] | expand

Commit Message

Jakub Jelinek Jan. 6, 2022, 8:38 a.m. UTC
Hi!

The threader changes resulted in a false positive warning during
profiledbootstrap:
In file included from ../../gcc/expr.c:26:
../../gcc/tree.h: In function ‘rtx_def* expand_expr_real_1(tree, rtx, machine_mode, expand_modifier, rtx_def**, bool)’:
../../gcc/tree.h:244:56: error: ‘context’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  244 | #define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code)
      |                                                        ^~~~
../../gcc/expr.c:10343:8: note: ‘context’ was declared here
10343 |   tree context;
      |        ^~~~~~~
While it will be nice to improve the uninit pass to handle it if possible
(I do not want to close the PR until that is done), doing profiledbootstrap
is a common thing to do, so a workaround is handy, especially as in this
case when the workaround seems to be the right thing to do, as it moves
a variable declaration to the only place where it is set and used and avoids
the weird and for uninit asking
  tree context;
...
  if (exp)
    context = ...;
  gcc_assert (!exp
              || use (context)
              || use_some_more (context));

Bootstrapped/regtested on x86_64-linux and i686-linux with normal bootstrap
and on aarch64-linux and powerpc64le-linux with profiledbootstrap, ok for
trunk?

2022-01-06  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/103899
	* expr.c (expand_expr_real_1): Add a workaround for bogus uninit
	warning by moving context variable to the only spot where it is used
	and moving gcc_assert into if body.


	Jakub

Comments

Richard Biener Jan. 6, 2022, 10:53 a.m. UTC | #1
On January 6, 2022 9:38:40 AM GMT+01:00, Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org> wrote:
>Hi!
>
>The threader changes resulted in a false positive warning during
>profiledbootstrap:
>In file included from ../../gcc/expr.c:26:
>../../gcc/tree.h: In function ‘rtx_def* expand_expr_real_1(tree, rtx, machine_mode, expand_modifier, rtx_def**, bool)’:
>../../gcc/tree.h:244:56: error: ‘context’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
>  244 | #define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code)
>      |                                                        ^~~~
>../../gcc/expr.c:10343:8: note: ‘context’ was declared here
>10343 |   tree context;
>      |        ^~~~~~~
>While it will be nice to improve the uninit pass to handle it if possible
>(I do not want to close the PR until that is done), doing profiledbootstrap
>is a common thing to do, so a workaround is handy, especially as in this
>case when the workaround seems to be the right thing to do, as it moves
>a variable declaration to the only place where it is set and used and avoids
>the weird and for uninit asking
>  tree context;
>...
>  if (exp)
>    context = ...;
>  gcc_assert (!exp
>              || use (context)
>              || use_some_more (context));
>
>Bootstrapped/regtested on x86_64-linux and i686-linux with normal bootstrap
>and on aarch64-linux and powerpc64le-linux with profiledbootstrap, ok for
>trunk?

Ok. 

Richard. 

>2022-01-06  Jakub Jelinek  <jakub@redhat.com>
>
>	PR tree-optimization/103899
>	* expr.c (expand_expr_real_1): Add a workaround for bogus uninit
>	warning by moving context variable to the only spot where it is used
>	and moving gcc_assert into if body.
>
>--- gcc/expr.c.jj	2022-01-03 10:40:41.203164211 +0100
>+++ gcc/expr.c	2022-01-05 14:47:47.684660031 +0100
>@@ -10340,7 +10340,6 @@ expand_expr_real_1 (tree exp, rtx target
>   enum tree_code code = TREE_CODE (exp);
>   rtx subtarget, original_target;
>   int ignore;
>-  tree context;
>   bool reduce_bit_field;
>   location_t loc = EXPR_LOCATION (exp);
>   struct separate_ops ops;
>@@ -10579,14 +10578,16 @@ expand_expr_real_1 (tree exp, rtx target
>       /* Variables inherited from containing functions should have
> 	 been lowered by this point.  */
>       if (exp)
>-	context = decl_function_context (exp);
>-      gcc_assert (!exp
>-		  || SCOPE_FILE_SCOPE_P (context)
>-		  || context == current_function_decl
>-		  || TREE_STATIC (exp)
>-		  || DECL_EXTERNAL (exp)
>-		  /* ??? C++ creates functions that are not TREE_STATIC.  */
>-		  || TREE_CODE (exp) == FUNCTION_DECL);
>+	{
>+	  tree context = decl_function_context (exp);
>+	  gcc_assert (SCOPE_FILE_SCOPE_P (context)
>+		      || context == current_function_decl
>+		      || TREE_STATIC (exp)
>+		      || DECL_EXTERNAL (exp)
>+		      /* ??? C++ creates functions that are not
>+			 TREE_STATIC.  */
>+		      || TREE_CODE (exp) == FUNCTION_DECL);
>+	}
> 
>       /* This is the case of an array whose size is to be determined
> 	 from its initializer, while the initializer is still being parsed.
>
>	Jakub
>
diff mbox series

Patch

--- gcc/expr.c.jj	2022-01-03 10:40:41.203164211 +0100
+++ gcc/expr.c	2022-01-05 14:47:47.684660031 +0100
@@ -10340,7 +10340,6 @@  expand_expr_real_1 (tree exp, rtx target
   enum tree_code code = TREE_CODE (exp);
   rtx subtarget, original_target;
   int ignore;
-  tree context;
   bool reduce_bit_field;
   location_t loc = EXPR_LOCATION (exp);
   struct separate_ops ops;
@@ -10579,14 +10578,16 @@  expand_expr_real_1 (tree exp, rtx target
       /* Variables inherited from containing functions should have
 	 been lowered by this point.  */
       if (exp)
-	context = decl_function_context (exp);
-      gcc_assert (!exp
-		  || SCOPE_FILE_SCOPE_P (context)
-		  || context == current_function_decl
-		  || TREE_STATIC (exp)
-		  || DECL_EXTERNAL (exp)
-		  /* ??? C++ creates functions that are not TREE_STATIC.  */
-		  || TREE_CODE (exp) == FUNCTION_DECL);
+	{
+	  tree context = decl_function_context (exp);
+	  gcc_assert (SCOPE_FILE_SCOPE_P (context)
+		      || context == current_function_decl
+		      || TREE_STATIC (exp)
+		      || DECL_EXTERNAL (exp)
+		      /* ??? C++ creates functions that are not
+			 TREE_STATIC.  */
+		      || TREE_CODE (exp) == FUNCTION_DECL);
+	}
 
       /* This is the case of an array whose size is to be determined
 	 from its initializer, while the initializer is still being parsed.