diff mbox series

Do not use tree_to_wide_ref that point to a temporary (PR c++/90587).

Message ID e4f2bf68-39db-3321-a4c6-8c1bebb30f76@suse.cz
State New
Headers show
Series Do not use tree_to_wide_ref that point to a temporary (PR c++/90587). | expand

Commit Message

Martin Liška May 23, 2019, 10:51 a.m. UTC
Hi.

The PR is about use-after-scope issue where:
wi::tree_to_wide_ref andw = wi::to_wide (val) & wi::to_wide (boundary);

The RHS1 and RHS2 will become out-of-scope after operator& returns a reference.
andw.val then points to one of RHS1 or RHS2. So that we end up with an use-after-scope.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

gcc/ChangeLog:

2019-05-23  Martin Liska  <mliska@suse.cz>

	PR c++/90587.
	* tree-ssa-uninit.c (value_sat_pred_p): The result of &
	operation points to a temporary (pointed via tree_to_wide_ref)
	that is out of scope after the &.
---
 gcc/tree-ssa-uninit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Richard Biener May 23, 2019, 11:20 a.m. UTC | #1
On Thu, May 23, 2019 at 12:51 PM Martin Liška <mliska@suse.cz> wrote:
>
> Hi.
>
> The PR is about use-after-scope issue where:
> wi::tree_to_wide_ref andw = wi::to_wide (val) & wi::to_wide (boundary);
>
> The RHS1 and RHS2 will become out-of-scope after operator& returns a reference.
> andw.val then points to one of RHS1 or RHS2. So that we end up with an use-after-scope.
>
> Patch can bootstrap on x86_64-linux-gnu and survives regression tests.
>
> Ready to be installed?

OK.

Richard.

> Thanks,
> Martin
>
> gcc/ChangeLog:
>
> 2019-05-23  Martin Liska  <mliska@suse.cz>
>
>         PR c++/90587.
>         * tree-ssa-uninit.c (value_sat_pred_p): The result of &
>         operation points to a temporary (pointed via tree_to_wide_ref)
>         that is out of scope after the &.
> ---
>  gcc/tree-ssa-uninit.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
>
diff mbox series

Patch

diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index bc07afe32c8..fe8f8f0bc28 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -1058,7 +1058,7 @@  value_sat_pred_p (tree val, tree boundary, enum tree_code cmpc,
   if (cmpc != BIT_AND_EXPR)
     return is_value_included_in (val, boundary, cmpc);
 
-  wi::tree_to_wide_ref andw = wi::to_wide (val) & wi::to_wide (boundary);
+  wide_int andw = wi::to_wide (val) & wi::to_wide (boundary);
   if (exact_p)
     return andw == wi::to_wide (val);
   else