diff options
author | Jeff Law <law@gcc.gnu.org> | 2018-12-05 16:10:08 -0700 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2018-12-05 16:10:08 -0700 |
commit | 665db3aeb48f0f0970bb0e01f37f9fd9fb013ea4 (patch) | |
tree | 2c210ca46a2a9c1f9f7c1d5eb1b25887d17f511f /gcc/calls.c | |
parent | c43137e800bb9ca2ecda0a6b6189e0eb5c22f0d7 (diff) | |
download | gcc-665db3aeb48f0f0970bb0e01f37f9fd9fb013ea4.zip gcc-665db3aeb48f0f0970bb0e01f37f9fd9fb013ea4.tar.gz gcc-665db3aeb48f0f0970bb0e01f37f9fd9fb013ea4.tar.bz2 |
re PR c/87028 (false positive -Wstringop-truncation strncpy with global variable source string)
PR c/87028
* calls.c (get_attr_nonstring_decl): Avoid setting *REF to
SSA_NAME_VAR.
* gcc/gimple-low.c (lower_stmt): Fold builtin calls here.
* gimplify (maybe_fold_stmt): Avoid folding builtin calls.
PR c/87028
* c-c++-common/Wstringop-truncation.c: Remove xfails.
* gcc.dg/Wstringop-truncation-5.c: New test.
* gcc.dg/strcmpopt_1.c: Adjust.
* gcc.dg/tree-ssa/pr79697.c: Same.
From-SVN: r266833
Diffstat (limited to 'gcc/calls.c')
-rw-r--r-- | gcc/calls.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/gcc/calls.c b/gcc/calls.c index 8978d3b..98c6377 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -1503,6 +1503,7 @@ tree get_attr_nonstring_decl (tree expr, tree *ref) { tree decl = expr; + tree var = NULL_TREE; if (TREE_CODE (decl) == SSA_NAME) { gimple *def = SSA_NAME_DEF_STMT (decl); @@ -1515,17 +1516,25 @@ get_attr_nonstring_decl (tree expr, tree *ref) || code == VAR_DECL) decl = gimple_assign_rhs1 (def); } - else if (tree var = SSA_NAME_VAR (decl)) - decl = var; + else + var = SSA_NAME_VAR (decl); } if (TREE_CODE (decl) == ADDR_EXPR) decl = TREE_OPERAND (decl, 0); + /* To simplify calling code, store the referenced DECL regardless of + the attribute determined below, but avoid storing the SSA_NAME_VAR + obtained above (it's not useful for dataflow purposes). */ if (ref) *ref = decl; - if (TREE_CODE (decl) == ARRAY_REF) + /* Use the SSA_NAME_VAR that was determined above to see if it's + declared nonstring. Otherwise drill down into the referenced + DECL. */ + if (var) + decl = var; + else if (TREE_CODE (decl) == ARRAY_REF) decl = TREE_OPERAND (decl, 0); else if (TREE_CODE (decl) == COMPONENT_REF) decl = TREE_OPERAND (decl, 1); |