From 770fe3a36400fb03d0936cff86ffb76a136d5674 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Sun, 4 Nov 2018 19:46:08 +0000 Subject: [PATCH] re PR tree-optimization/87672 (81512c36 causes ICE in bootstrap stage 3 using "-D_FORTIFY_SOURCE=2" (invalid operand in unary operation, incorrect sharing of tree nodes, verify_gimple failed)) gcc: 2018-11-04 Bernd Edlinger PR tree-optimization/87672 * gimple-fold.c (gimple_fold_builtin_stxcpy_chk): Gimplify. * tree-ssa-strlen.c (handle_builtin_strcat): Adjust object size. testsuite: 2018-11-04 Bernd Edlinger PR tree-optimization/87672 * gcc.dg/pr87672.c: New test. From-SVN: r265777 --- gcc/ChangeLog | 6 ++++++ gcc/gimple-fold.c | 1 + gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr87672.c | 11 +++++++++++ gcc/tree-ssa-strlen.c | 11 +++++++++-- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr87672.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4b9ce0f..a7f3afd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-11-04 Bernd Edlinger + + PR tree-optimization/87672 + * gimple-fold.c (gimple_fold_builtin_stxcpy_chk): Gimplify. + * tree-ssa-strlen.c (handle_builtin_strcat): Adjust object size. + 2018-11-04 Uros Bizjak PR middle-end/58372 diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 7d2bd1c..5468b60 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -2715,6 +2715,7 @@ gimple_fold_builtin_stxcpy_chk (gimple_stmt_iterator *gsi, return false; gimple_seq stmts = NULL; + len = force_gimple_operand (len, &stmts, true, NULL_TREE); len = gimple_convert (&stmts, loc, size_type_node, len); len = gimple_build (&stmts, loc, PLUS_EXPR, size_type_node, len, build_int_cst (size_type_node, 1)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9bb5eb0..79a7859 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-11-04 Bernd Edlinger + + PR tree-optimization/87672 + * gcc.dg/pr87672.c: New test. + 2018-11-04 Uros Bizjak PR middle-end/58372 diff --git a/gcc/testsuite/gcc.dg/pr87672.c b/gcc/testsuite/gcc.dg/pr87672.c new file mode 100644 index 0000000..0b64e5d --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr87672.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +char buf[40]; +void test (int x) +{ + __builtin_strcpy (buf, "test"); + __builtin___strcat_chk (buf, "postfix" + x, sizeof (buf)); +} + +/* { dg-final { scan-tree-dump "memcpy_chk.*, 36\\)" "optimized" } } */ diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index d508d36..669c315 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -2605,12 +2605,19 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi) if (endptr) dst = fold_convert_loc (loc, TREE_TYPE (dst), unshare_expr (endptr)); else - dst = fold_build2_loc (loc, POINTER_PLUS_EXPR, - TREE_TYPE (dst), unshare_expr (dst), + dst = fold_build2_loc (loc, POINTER_PLUS_EXPR, TREE_TYPE (dst), dst, fold_convert_loc (loc, sizetype, unshare_expr (dstlen))); dst = force_gimple_operand_gsi (gsi, dst, true, NULL_TREE, true, GSI_SAME_STMT); + if (objsz) + { + objsz = fold_build2_loc (loc, MINUS_EXPR, TREE_TYPE (objsz), objsz, + fold_convert_loc (loc, TREE_TYPE (objsz), + unshare_expr (dstlen))); + objsz = force_gimple_operand_gsi (gsi, objsz, true, NULL_TREE, true, + GSI_SAME_STMT); + } if (dump_file && (dump_flags & TDF_DETAILS) != 0) { fprintf (dump_file, "Optimizing: "); -- 2.7.4