On October 31, 2019 8:26:47 AM GMT+01:00, Jakub Jelinek <ja...@redhat.com> 
wrote:
>Hi!
>
>The https://gcc.gnu.org/ml/gcc-patches/2018-08/msg01645.html patch
>in the form it was committed as r263880 and later tweaks essentially
>replaced DECL_BUILT_IN with fndecl_built_in_p (or the further class
>and/or function code checks with it), but most importantly while
>it was perhaps intended earlier, fndecl_built_in_p doesn't include a
>non-NULL or TREE_CODE (node) == FUNCTION_DECL check.
>In the patch, some changes were 1 for 1, DECL_BUILT_IN replaced with
>fndecl_built_in_p, or there were is_builtin_fn (which included the
>FUNCTION_DECL check) replaced with FUNCTION_DECL check +
>fndecl_built_in_p.
>Another kind of changes were FUNCTION_DECL check + DECL_BUILT_IN being
>replaced with just fndecl_built_in_p.  Most of them were after
>get_callee_fndecl or similar functions, which might be ok (that
>function
>and similar return NULL if not found or a FUNCTION_DECL, but for
>error_mark_node passed to it they actually return error_mark_node;
>shouldn't
>we change that to just NULL_TREE too?).  But in the following spots I
>don't
>see anything that would guarantee it is a FUNCTION_DECL.  As the
>testcase
>shows, in the gimple-fold.c case it can be e.g. a MEM_REF instead, I'm
>surprised it isn't e.g. a VAR_DECL in the free_lang_data case or lto
>case.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>

OK. 

Richard. 

>2019-10-31  Jakub Jelinek  <ja...@redhat.com>
>
>       PR middle-end/92231
>       * tree.h (fndecl_built_in_p): Use fndecl_built_in_p instead of
>       DECL_BUILT_IN in comment.  Remove redundant ()s around return
>       argument.
>       * tree.c (free_lang_data_in_decl): Check if var is FUNCTION_DECL
>       before calling fndecl_built_in_p.
>       * gimple-fold.c (gimple_fold_stmt_to_constant_1): Check if
>       TREE_OPERAND (fn, 0) is a FUNCTION_DECL before calling
>       fndecl_built_in_p on it.
>lto/
>       * lto-lang.c (handle_const_attribute): Don't call fndecl_built_in_p
>       on *node that is not FUNCTION_DECL.
>testsuite/
>       * gcc.c-torture/compile/pr92231.c: New test.
>
>--- gcc/tree.h.jj      2019-10-30 10:49:31.044107888 +0100
>+++ gcc/tree.h 2019-10-30 15:53:45.795389000 +0100
>@@ -6125,12 +6125,12 @@ type_has_mode_precision_p (const_tree t)
> 
>    Note that it is different from the DECL_IS_BUILTIN accessor.  For
>    instance, user declared prototypes of C library functions are not
>-   DECL_IS_BUILTIN but may be DECL_BUILT_IN.  */
>+   DECL_IS_BUILTIN but may be fndecl_built_in_p.  */
> 
> inline bool
> fndecl_built_in_p (const_tree node)
> {
>-  return (DECL_BUILT_IN_CLASS (node) != NOT_BUILT_IN);
>+  return DECL_BUILT_IN_CLASS (node) != NOT_BUILT_IN;
> }
> 
> /* Return true if a FUNCTION_DECL NODE is a GCC built-in function
>@@ -6139,7 +6139,7 @@ fndecl_built_in_p (const_tree node)
> inline bool
> fndecl_built_in_p (const_tree node, built_in_class klass)
> {
>-  return (fndecl_built_in_p (node) && DECL_BUILT_IN_CLASS (node) ==
>klass);
>+  return fndecl_built_in_p (node) && DECL_BUILT_IN_CLASS (node) ==
>klass;
> }
> 
> /* Return true if a FUNCTION_DECL NODE is a GCC built-in function
>--- gcc/tree.c.jj      2019-10-30 13:16:45.071247769 +0100
>+++ gcc/tree.c 2019-10-30 15:09:00.418332790 +0100
>@@ -5805,7 +5805,8 @@ free_lang_data_in_decl (tree decl, class
>       while (*nextp)
>       {
>         tree var = *nextp;
>-        if (fndecl_built_in_p (var))
>+        if (TREE_CODE (var) == FUNCTION_DECL
>+            && fndecl_built_in_p (var))
>           *nextp = TREE_CHAIN (var);
>         else
>           nextp = &TREE_CHAIN (var);
>--- gcc/gimple-fold.c.jj       2019-10-30 10:49:36.171029125 +0100
>+++ gcc/gimple-fold.c  2019-10-30 15:01:48.192933760 +0100
>@@ -6439,6 +6439,7 @@ gimple_fold_stmt_to_constant_1 (gimple *
> 
>       fn = (*valueize) (gimple_call_fn (stmt));
>       if (TREE_CODE (fn) == ADDR_EXPR
>+          && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL
>           && fndecl_built_in_p (TREE_OPERAND (fn, 0))
>           && gimple_builtin_call_types_compatible_p (stmt,
>                                                      TREE_OPERAND (fn, 0)))
>--- gcc/lto/lto-lang.c.jj      2019-10-04 21:39:52.301012246 +0200
>+++ gcc/lto/lto-lang.c 2019-10-30 15:12:35.599046537 +0100
>@@ -305,7 +305,8 @@ handle_const_attribute (tree *node, tree
>                       tree ARG_UNUSED (args), int ARG_UNUSED (flags),
>                       bool * ARG_UNUSED (no_add_attrs))
> {
>-  if (!fndecl_built_in_p (*node))
>+  if (TREE_CODE (*node) != FUNCTION_DECL
>+      || !fndecl_built_in_p (*node))
>inform (UNKNOWN_LOCATION, "%s:%s: %E: %E", __FILE__, __func__, *node,
>name);
> 
>   tree type = TREE_TYPE (*node);
>--- gcc/testsuite/gcc.c-torture/compile/pr92231.c.jj   2019-10-30
>15:52:00.464994680 +0100
>+++ gcc/testsuite/gcc.c-torture/compile/pr92231.c      2019-10-30
>15:51:40.506298935 +0100
>@@ -0,0 +1,9 @@
>+/* PR middle-end/92231 */
>+
>+extern int bar (void);
>+
>+int
>+foo (void)
>+{
>+  return (&bar + 4096) ();
>+}
>
>       Jakub

Reply via email to