re PR middle-end/92231 (ICE in gimple_fold_stmt_to_constant_1)
authorJakub Jelinek <jakub@redhat.com>
Thu, 31 Oct 2019 10:04:47 +0000 (11:04 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 31 Oct 2019 10:04:47 +0000 (11:04 +0100)
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.

From-SVN: r277660

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 bc1df777c49936400b884573489de7c838c74c86..8265f4ce365583bc83556340bdf49f5bfddeba97 100644 (file)
@@ -1,3 +1,15 @@
+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.
+
 2019-10-31  Andre Vieira  <andre.simoesdiasvieira@arm.com>
 
        * params.def (PARAM_VECT_EPILOGUES_NOMASK): Enable by default.
index 1b7e7edfa8c3c34bf1433dcb6be610bb521333db..dc3d2286aa1784e4ce73a2e5f97624865fe45a61 100644 (file)
@@ -6439,6 +6439,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 a20e2d496fefdc232adcdb9327dfbfd7568fb700..d5c1373863cf02e9f226251b0fc45e4e4cc58b60 100644 (file)
@@ -1,3 +1,9 @@
+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-30  Martin Liska  <mliska@suse.cz>
 
        PR lto/91393
index 0d781da5768fe056ecf62d9a6f9610945b192c42..3e37c37fa460d0ef6d207737857d44069d42fd3c 100644 (file)
@@ -305,7 +305,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 7f8acf8b52be5c4ec33dee367d76acb05ee1b7cc..925768189f70ec95444398ae899d3598a1125277 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-31  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/92231
+       * gcc.c-torture/compile/pr92231.c: New test.
+
 2019-10-31  Andre Vieira  <andre.simoesdiasvieira@arm.com>
 
        * gcc.dg/vect/vect-epilogues.c: New test.
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 3866804b99dbc1b57955d4db2c6d3261d9be18d5..741f7a2ce659ab6a0386d36a6565bb021a522043 100644 (file)
@@ -5805,7 +5805,8 @@ free_lang_data_in_decl (tree decl, class 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 18d6c0e0c21f14f54e3a0f9614bdfe0f5fd35536..81351548ecdf505b71bbe349489f69959abed08a 100644 (file)
@@ -6119,12 +6119,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
@@ -6133,7 +6133,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