This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix fold_binary_loc BIT_IOR_EXPR folding (PR sanitizer/80349)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 25 Apr 2017 18:09:20 +0200
- Subject: Re: [PATCH] Fix fold_binary_loc BIT_IOR_EXPR folding (PR sanitizer/80349)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EEDFD70723
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EEDFD70723
- References: <20170425160525.GU4255@redhat.com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Apr 25, 2017 at 06:05:25PM +0200, Marek Polacek wrote:
> Here we are crashing because fold_binary_loc produced a BIT_IOR_EXPR with
> incompatible operands. Fixed by adding the missing conversion, similarly
> to <https://gcc.gnu.org/ml/gcc-patches/2017-04/msg00551.html>.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk? And 7.1?
>
> 2017-04-25 Marek Polacek <polacek@redhat.com>
>
> PR sanitizer/80349
> * fold-const.c (fold_binary_loc) <case BIT_IOR_EXPR>: Convert arg0's
> first argument to type.
>
> * g++.dg/ubsan/pr80349-2.C: New test.
>
> diff --git gcc/fold-const.c gcc/fold-const.c
> index f0b8e7a..ce4b2df 100644
> --- gcc/fold-const.c
> +++ gcc/fold-const.c
> @@ -9898,8 +9898,10 @@ fold_binary_loc (location_t loc,
>
> /* If (C1|C2) == ~0 then (X&C1)|C2 becomes X|C2. */
> if (msk.and_not (c1 | c2) == 0)
> - return fold_build2_loc (loc, BIT_IOR_EXPR, type,
> - TREE_OPERAND (arg0, 0), arg1);
> + {
> + tem = fold_convert_loc (loc, type, TREE_OPERAND (arg0, 0));
> + return fold_build2_loc (loc, BIT_IOR_EXPR, type, tem, arg1);
Shouldn't this use op1 instead of arg1, just in case op1 is a NOP_EXPR
of INTEGER_CST or similar unfolded tree?
Jakub