]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/92231 (ICE in gimple_fold_stmt_to_constant_1)
authorJakub Jelinek <jakub@redhat.com>
Fri, 8 Nov 2019 18:58:14 +0000 (19:58 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 8 Nov 2019 18:58:14 +0000 (19:58 +0100)
Backported from mainline
2019-10-31  Jakub Jelinek  <jakub@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-lang.c (handle_const_attribute): Don't call fndecl_built_in_p
on *node that is not FUNCTION_DECL.

* gcc.c-torture/compile/pr92231.c: New test.

From-SVN: r277986

gcc/ChangeLog
gcc/gimple-fold.c
gcc/lto/ChangeLog
gcc/lto/lto-lang.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr92231.c [new file with mode: 0644]
gcc/tree.c
gcc/tree.h

index 96a32d7681aed0a7b349a9b483bc7c997bd899d9..de09391a66a5fac9ae9a3fd6270bed4df57d750d 100644 (file)
@@ -3,6 +3,16 @@
        Backported from mainline
        2019-10-31  Jakub Jelinek  <jakub@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.
+
        PR c++/90947
        * tree.h (type_initializer_zero_p): Remove.
        * tree.c (type_initializer_zero_p): Remove.
index f30818042ee24531b82eb38d23fd4b1eba431d2c..d00f1e2b035e749145795296cd4613df9bc126a1 100644 (file)
@@ -6557,6 +6557,7 @@ gimple_fold_stmt_to_constant_1 (gimple *stmt, tree (*valueize) (tree),
 
        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)))
index c78f9c92a8628533bd38f29067ec006d5ac15616..e381db79f1703d01195894372230dab2cdbe2c8d 100644 (file)
@@ -1,3 +1,12 @@
+2019-11-08  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2019-10-31  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/92231
+       * lto-lang.c (handle_const_attribute): Don't call fndecl_built_in_p
+       on *node that is not FUNCTION_DECL.
+
 2019-10-26  Jan Hubicka  <hubicka@ucw.cz>
 
        Backport from mainline
index 5a35d4794c244c42d2d57e197f68abf409e526c1..4ef228fcb458c16542b7d40e29094b8cf568bb5e 100644 (file)
@@ -303,7 +303,8 @@ handle_const_attribute (tree *node, tree ARG_UNUSED (name),
                        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);
index 89f8907e413e745ed333808e0a071a857aa9690b..cd15635f2a7417a416deb0612416b0c1ef08a1c5 100644 (file)
@@ -1,6 +1,11 @@
 2019-11-08  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-10-31  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/92231
+       * gcc.c-torture/compile/pr92231.c: New test.
+
        2019-10-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/92015
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr92231.c b/gcc/testsuite/gcc.c-torture/compile/pr92231.c
new file mode 100644 (file)
index 0000000..1813add
--- /dev/null
@@ -0,0 +1,9 @@
+/* PR middle-end/92231 */
+
+extern int bar (void);
+
+int
+foo (void)
+{
+  return (&bar + 4096) ();
+}
index 374131c74eaa4323486cb5099feb174125693ba7..1549bde91473c883675e7f65dde0c281704abf46 100644 (file)
@@ -5777,7 +5777,8 @@ free_lang_data_in_decl (tree decl, struct free_lang_data_d *fld)
       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);
index d650511c66f8f9e83645900f11bddc8d9bd6aeb4..43dabd1a3bfa3380ad965b43dc532fe0c55e6730 100644 (file)
@@ -5946,12 +5946,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
@@ -5960,7 +5960,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