This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix ICE from sprintf/strlen integration work
- From: Jeff Law <law at redhat dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 27 Aug 2019 17:04:03 -0600
- Subject: Fix ICE from sprintf/strlen integration work
This showed up as an ICE when building the kernel on ppc64le after the
sprintf/strlen integration.
In simplest terms we can't size the ssa_ver_to_stridx array until after
we have initialized the loop optimizer and SCEV as they create new
SSA_NAMEs. Usually this isn't a problem, but it can be if we need more
names than are currently available on the freelist of SSA_NAMEs to recycle.
Bootstrapped and regression tested on ppc64le. Also verified the kernel
builds again.
Installing on the trunk,
jeff
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 39459d087b2..1d9d6cf0ff2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2019-08-27 Jeff Law <law@redhat.com>
+
+ * tree-ssa-strlen.c (printf_strlen_execute): Initialize
+ the loop optimizer and SCEV before sizing ssa_ver_to_stridx.
+
2019-08-27 Uroš Bizjak <ubizjak@gmail.com>
PR target/91528
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 37133de87f5..2560faf8526 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2019-08-27 Jeff Law <law@redhat.com>
+
+ * gcc.c-torture/compile/20190827-1.c: New test.
+
2019-08-27 Harald Anlauf <anlauf@gmx.de>
PR fortran/91496
diff --git a/gcc/testsuite/gcc.c-torture/compile/20190827-1.c b/gcc/testsuite/gcc.c-torture/compile/20190827-1.c
new file mode 100644
index 00000000000..f0956179b1d
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/20190827-1.c
@@ -0,0 +1,104 @@
+typedef unsigned char __u8;
+typedef __u8 u8;
+typedef u8 u_int8_t;
+typedef unsigned int gfp_t;
+
+struct list_head
+{
+ struct list_head *next, *prev;
+};
+extern int strcmp (const char *, const char *);
+enum
+{
+ NFPROTO_UNSPEC = 0,
+ NFPROTO_INET = 1,
+ NFPROTO_IPV4 = 2,
+ NFPROTO_ARP = 3,
+ NFPROTO_NETDEV = 5,
+ NFPROTO_BRIDGE = 7,
+ NFPROTO_IPV6 = 10,
+ NFPROTO_DECNET = 12,
+ NFPROTO_NUMPROTO,
+};
+
+struct xt_target
+{
+ struct list_head list;
+ const char name[29];
+ u_int8_t revision;
+};
+
+struct xt_af
+{
+ struct list_head target;
+};
+
+static struct xt_af *xt;
+
+struct xt_af * kcalloc (int, int, int);
+
+static int
+target_revfn (u8 af, const char *name, u8 revision, int *bestp)
+{
+ const struct xt_target *t;
+ int have_rev = 0;
+
+ for (t = (
+ {
+ void *__mptr = (void *)((&xt[af].target)->next);
+ ((typeof (*t) *) (__mptr -
+ __builtin_offsetof (typeof (*t), list)));}
+ ); &t->list != (&xt[af].target); t = (
+ {
+ void *__mptr =
+ (void *)((t)->list.next);
+ ((typeof (*(t)) *) (__mptr -
+ __builtin_offsetof
+ (typeof
+ (*(t)),
+ list)));}
+ ))
+ {
+ if (strcmp (t->name, name) == 0)
+ {
+ if (t->revision > *bestp)
+ *bestp = t->revision;
+ if (t->revision == revision)
+ have_rev = 1;
+ }
+ }
+
+ if (af != NFPROTO_UNSPEC && !have_rev)
+ return target_revfn (NFPROTO_UNSPEC, name, revision, bestp);
+
+ return have_rev;
+}
+
+int
+xt_find_revision (u8 af, const char *name, u8 revision, int target, int *err)
+{
+ int have_rev, best = -1;
+
+ have_rev = target_revfn (af, name, revision, &best);
+
+
+ if (best == -1)
+ {
+ *err = -2;
+ return 0;
+ }
+
+}
+
+
+static int __attribute__ ((__section__ (".init.text")))
+ __attribute__ ((__cold__)) xt_init (void)
+{
+ xt =
+ kcalloc (NFPROTO_NUMPROTO, sizeof (struct xt_af),
+ (((gfp_t) (0x400u | 0x800u)) | ((gfp_t) 0x40u) |
+ ((gfp_t) 0x80u)));
+}
+
+int init_module (void) __attribute__ ((__copy__ (xt_init)))
+ __attribute__ ((alias ("xt_init")));;
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
index 5c5b83833c8..d38352a0c4c 100644
--- a/gcc/tree-ssa-strlen.c
+++ b/gcc/tree-ssa-strlen.c
@@ -4850,13 +4850,6 @@ printf_strlen_execute (function *fun, bool warn_only)
{
strlen_optimize = !warn_only;
- gcc_assert (!strlen_to_stridx);
- if (warn_stringop_overflow || warn_stringop_truncation)
- strlen_to_stridx = new hash_map<tree, stridx_strlenloc> ();
-
- ssa_ver_to_stridx.safe_grow_cleared (num_ssa_names);
- max_stridx = 1;
-
calculate_dominance_info (CDI_DOMINATORS);
bool use_scev = optimize > 0 && flag_printf_return_value;
@@ -4866,6 +4859,15 @@ printf_strlen_execute (function *fun, bool warn_only)
scev_initialize ();
}
+ gcc_assert (!strlen_to_stridx);
+ if (warn_stringop_overflow || warn_stringop_truncation)
+ strlen_to_stridx = new hash_map<tree, stridx_strlenloc> ();
+
+ /* This has to happen after initializing the loop optimizer
+ and initializing SCEV as they create new SSA_NAMEs. */
+ ssa_ver_to_stridx.safe_grow_cleared (num_ssa_names);
+ max_stridx = 1;
+
/* String length optimization is implemented as a walk of the dominator
tree and a forward walk of statements within each block. */
strlen_dom_walker walker (CDI_DOMINATORS);