public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Fix up VEC_INIT_EXPR gimplification after r12-7069
@ 2023-05-02 15:19 Jakub Jelinek
  2023-05-02 18:36 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-05-02 15:19 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches, Patrick Palka

Hi!

During patch backporting, I've noticed that while most cp_walk_tree calls
with cp_fold_r callback callers were changed from &pset to cp_fold_data
&data, the VEC_INIT_EXPR gimplifications has not, so it still passes just
address of a hash_set<tree> and so if during the folding we ever touch
data->flags, we use uninitialized data there.

The following patch changes it to do the same thing as cp_fold_function
because the VEC_INIT_EXPR gimplifications will happen on function bodies
only.

Ok for trunk if it passes bootstrap/regtest?

2023-05-02  Jakub Jelinek  <jakub@redhat.com>

	* cp-gimplify.cc (cp_fold_data): Move definition earlier.
	(cp_gimplify_expr): Pass address of ff_genericize | ff_mce_false
	constructed data rather than &pset to cp_walk_tree with cp_fold_r.

--- gcc/cp/cp-gimplify.cc.jj	2023-03-16 22:01:02.295090975 +0100
+++ gcc/cp/cp-gimplify.cc	2023-05-02 17:05:03.079652427 +0200
@@ -57,6 +57,13 @@ enum fold_flags {
 
 using fold_flags_t = int;
 
+struct cp_fold_data
+{
+  hash_set<tree> pset;
+  fold_flags_t flags;
+  cp_fold_data (fold_flags_t flags): flags (flags) {}
+};
+
 /* Forward declarations.  */
 
 static tree cp_genericize_r (tree *, int *, void *);
@@ -505,8 +512,8 @@ cp_gimplify_expr (tree *expr_p, gimple_s
 	*expr_p = expand_vec_init_expr (NULL_TREE, *expr_p,
 					tf_warning_or_error);
 
-	hash_set<tree> pset;
-	cp_walk_tree (expr_p, cp_fold_r, &pset, NULL);
+	cp_fold_data data (ff_genericize | ff_mce_false);
+	cp_walk_tree (expr_p, cp_fold_r, &data, NULL);
 	cp_genericize_tree (expr_p, false);
 	copy_if_shared (expr_p);
 	ret = GS_OK;
@@ -1029,13 +1036,6 @@ struct cp_genericize_data
      in fold-const, we need to perform this before transformation to
      GIMPLE-form.  */
 
-struct cp_fold_data
-{
-  hash_set<tree> pset;
-  fold_flags_t flags;
-  cp_fold_data (fold_flags_t flags): flags (flags) {}
-};
-
 static tree
 cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_)
 {

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c++: Fix up VEC_INIT_EXPR gimplification after r12-7069
  2023-05-02 15:19 [PATCH] c++: Fix up VEC_INIT_EXPR gimplification after r12-7069 Jakub Jelinek
@ 2023-05-02 18:36 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-05-02 18:36 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Patrick Palka

On 5/2/23 11:19, Jakub Jelinek wrote:
> Hi!
> 
> During patch backporting, I've noticed that while most cp_walk_tree calls
> with cp_fold_r callback callers were changed from &pset to cp_fold_data
> &data, the VEC_INIT_EXPR gimplifications has not, so it still passes just
> address of a hash_set<tree> and so if during the folding we ever touch
> data->flags, we use uninitialized data there.
> 
> The following patch changes it to do the same thing as cp_fold_function
> because the VEC_INIT_EXPR gimplifications will happen on function bodies
> only.
> 
> Ok for trunk if it passes bootstrap/regtest?

OK.

> 2023-05-02  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* cp-gimplify.cc (cp_fold_data): Move definition earlier.
> 	(cp_gimplify_expr): Pass address of ff_genericize | ff_mce_false
> 	constructed data rather than &pset to cp_walk_tree with cp_fold_r.
> 
> --- gcc/cp/cp-gimplify.cc.jj	2023-03-16 22:01:02.295090975 +0100
> +++ gcc/cp/cp-gimplify.cc	2023-05-02 17:05:03.079652427 +0200
> @@ -57,6 +57,13 @@ enum fold_flags {
>   
>   using fold_flags_t = int;
>   
> +struct cp_fold_data
> +{
> +  hash_set<tree> pset;
> +  fold_flags_t flags;
> +  cp_fold_data (fold_flags_t flags): flags (flags) {}
> +};
> +
>   /* Forward declarations.  */
>   
>   static tree cp_genericize_r (tree *, int *, void *);
> @@ -505,8 +512,8 @@ cp_gimplify_expr (tree *expr_p, gimple_s
>   	*expr_p = expand_vec_init_expr (NULL_TREE, *expr_p,
>   					tf_warning_or_error);
>   
> -	hash_set<tree> pset;
> -	cp_walk_tree (expr_p, cp_fold_r, &pset, NULL);
> +	cp_fold_data data (ff_genericize | ff_mce_false);
> +	cp_walk_tree (expr_p, cp_fold_r, &data, NULL);
>   	cp_genericize_tree (expr_p, false);
>   	copy_if_shared (expr_p);
>   	ret = GS_OK;
> @@ -1029,13 +1036,6 @@ struct cp_genericize_data
>        in fold-const, we need to perform this before transformation to
>        GIMPLE-form.  */
>   
> -struct cp_fold_data
> -{
> -  hash_set<tree> pset;
> -  fold_flags_t flags;
> -  cp_fold_data (fold_flags_t flags): flags (flags) {}
> -};
> -
>   static tree
>   cp_fold_r (tree *stmt_p, int *walk_subtrees, void *data_)
>   {
> 
> 	Jakub
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-02 18:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-02 15:19 [PATCH] c++: Fix up VEC_INIT_EXPR gimplification after r12-7069 Jakub Jelinek
2023-05-02 18:36 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).