diff mbox

Do not call const_binop on MEM_EXPR

Message ID 22223617.bBxoQhLBDc@polaris
State New
Headers show

Commit Message

Eric Botcazou Jan. 22, 2015, 2:36 p.m. UTC
Hi,

const_binop is now invoked on MEM_EXPR, which doesn't make much sense given 
the assertion at the end:

  /* Make sure type and arg0 have the same saturating flag.  */
  gcc_checking_assert (TYPE_SATURATING (type)
		       == TYPE_SATURATING (TREE_TYPE (arg1)));

Tested on x86_64-suse-linux, OK for the mainline?


2015-01-22  Eric Botcazou  <ebotcazou@adacore.com>

	* fold-const.c (fold_binary_loc): Do not call const_binop on MEM_REF.

Comments

Richard Biener Jan. 22, 2015, 3:57 p.m. UTC | #1
On Thu, Jan 22, 2015 at 3:36 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> const_binop is now invoked on MEM_EXPR, which doesn't make much sense given
> the assertion at the end:
>
>   /* Make sure type and arg0 have the same saturating flag.  */
>   gcc_checking_assert (TYPE_SATURATING (type)
>                        == TYPE_SATURATING (TREE_TYPE (arg1)));
>
> Tested on x86_64-suse-linux, OK for the mainline?

I'd prefer a

   if (TREE_CODE_CLASS (code) != tcc_binary)
    return NULL_TREE;

before the above assert.  That matches what the code did before my reorg.

Ok with that change.

Thanks,
Richard.

>
> 2015-01-22  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * fold-const.c (fold_binary_loc): Do not call const_binop on MEM_REF.
>
>
> --
> Eric Botcazou
diff mbox

Patch

Index: fold-const.c
===================================================================
--- fold-const.c	(revision 219928)
+++ fold-const.c	(working copy)
@@ -9884,7 +9884,7 @@  fold_binary_loc (location_t loc,
 
   /* Note that TREE_CONSTANT isn't enough: static var addresses are
      constant but we can't do arithmetic on them.  */
-  if (CONSTANT_CLASS_P (arg0) && CONSTANT_CLASS_P (arg1))
+  if (code != MEM_REF && CONSTANT_CLASS_P (arg0) && CONSTANT_CLASS_P (arg1))
     {
       tem = const_binop (code, type, arg0, arg1);
       if (tem != NULL_TREE)