This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix __builtin_expect folding (PR c/38700)
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Jakub Jelinek" <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 3 Jan 2009 01:21:53 +0100
- Subject: Re: [PATCH] Fix __builtin_expect folding (PR c/38700)
- References: <20090102234930.GI25055@tyan-ft48-01.lab.bos.redhat.com>
On Sat, Jan 3, 2009 at 12:49 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> DECL_WEAK can only be used with VAR_DECL, FUNCTION_DECL, TYPE_DECL
> and TRANSLATION_UNIT_DECL, the latter 2 IMHO can't occur inside of
> ADDR_EXPR. DECL_P also matches LABEL_DECL, PARM_DECL etc.
>
> Fixed thusly, bootstrapped/regtested on x86_64-linux. Ok for trunk?
Ok.
Thanks,
Richard.
> 2009-01-03 Jakub Jelinek <jakub@redhat.com>
>
> PR c/38700
> * builtins.c (fold_builtin_expect): Only check DECL_WEAK for VAR_DECLs
> and FUNCTION_DECLs.
>
> * gcc.dg/pr38700.c: New test.
>
> --- gcc/builtins.c.jj 2008-12-27 10:12:25.000000000 +0100
> +++ gcc/builtins.c 2009-01-02 16:06:03.000000000 +0100
> @@ -1,6 +1,6 @@
> /* Expand builtin functions.
> Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
> - 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
> + 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
> Free Software Foundation, Inc.
>
> This file is part of GCC.
> @@ -7324,7 +7324,9 @@ fold_builtin_expect (tree arg0, tree arg
> }
> while (TREE_CODE (inner) == COMPONENT_REF
> || TREE_CODE (inner) == ARRAY_REF);
> - if (DECL_P (inner) && DECL_WEAK (inner))
> + if ((TREE_CODE (inner) == VAR_DECL
> + || TREE_CODE (inner) == FUNCTION_DECL)
> + && DECL_WEAK (inner))
> return NULL_TREE;
> }
>
> --- gcc/testsuite/gcc.dg/pr38700.c.jj 2009-01-02 16:05:19.000000000 +0100
> +++ gcc/testsuite/gcc.dg/pr38700.c 2009-01-02 16:05:05.000000000 +0100
> @@ -0,0 +1,11 @@
> +/* PR c/38700 */
> +/* { dg-do compile } */
> +/* { dg-options "-O0" } */
> +
> +int
> +foo ()
> +{
> + __SIZE_TYPE__ s = __builtin_expect ((__SIZE_TYPE__)&&L, 0);
> +L:
> + return 0;
> +}
>
> Jakub
>