From 2d8ba44101028f4be534a20a0d2146695e1dc4fd Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Tue, 27 Aug 2019 17:03:45 -0600 Subject: [PATCH] tree-ssa-strlen.c (printf_strlen_execute): Initialize the loop optimizer and SCEV before sizing ssa_ver_to_stridx. * tree-ssa-strlen.c (printf_strlen_execute): Initialize the loop optimizer and SCEV before sizing ssa_ver_to_stridx. * gcc.c-torture/compile/20190827-1.c: New test. From-SVN: r274975 --- gcc/ChangeLog | 5 + gcc/testsuite/ChangeLog | 4 + .../gcc.c-torture/compile/20190827-1.c | 104 ++++++++++++++++++ gcc/tree-ssa-strlen.c | 16 +-- 4 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/20190827-1.c 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 + + * tree-ssa-strlen.c (printf_strlen_execute): Initialize + the loop optimizer and SCEV before sizing ssa_ver_to_stridx. + 2019-08-27 Uroš Bizjak 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 + + * gcc.c-torture/compile/20190827-1.c: New test. + 2019-08-27 Harald Anlauf 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 (); - - 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 (); + + /* 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); -- 2.30.2