aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-02-14 10:25:01 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2019-02-14 10:25:01 +0100
commit3c545f7491b642339fbdd451caaf5a4efae18a61 (patch)
tree890d82b0f064d5477e15d64235b678226fba962c /gcc/fold-const.c
parent8936f5310aba723f2fbc2b0106e74fd307e4c347 (diff)
downloadgcc-3c545f7491b642339fbdd451caaf5a4efae18a61.zip
gcc-3c545f7491b642339fbdd451caaf5a4efae18a61.tar.gz
gcc-3c545f7491b642339fbdd451caaf5a4efae18a61.tar.bz2
re PR tree-optimization/89314 (ICE in wide_int_to_tree_1, at tree.c:1561)
PR tree-optimization/89314 * fold-const.c (fold_binary_loc): Cast strlen argument to const char * before dereferencing it. Formatting fixes. * gcc.dg/pr89314.c: New test. From-SVN: r268868
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 640a6ec..fcc1c45 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10740,20 +10740,24 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
strlen(ptr) != 0 => *ptr != 0
Other cases should reduce to one of these two (or a constant)
due to the return value of strlen being unsigned. */
- if (TREE_CODE (arg0) == CALL_EXPR
- && integer_zerop (arg1))
+ if (TREE_CODE (arg0) == CALL_EXPR && integer_zerop (arg1))
{
tree fndecl = get_callee_fndecl (arg0);
if (fndecl
&& fndecl_built_in_p (fndecl, BUILT_IN_STRLEN)
&& call_expr_nargs (arg0) == 1
- && TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (arg0, 0))) == POINTER_TYPE)
+ && (TREE_CODE (TREE_TYPE (CALL_EXPR_ARG (arg0, 0)))
+ == POINTER_TYPE))
{
- tree iref = build_fold_indirect_ref_loc (loc,
- CALL_EXPR_ARG (arg0, 0));
+ tree ptrtype
+ = build_pointer_type (build_qualified_type (char_type_node,
+ TYPE_QUAL_CONST));
+ tree ptr = fold_convert_loc (loc, ptrtype,
+ CALL_EXPR_ARG (arg0, 0));
+ tree iref = build_fold_indirect_ref_loc (loc, ptr);
return fold_build2_loc (loc, code, type, iref,
- build_int_cst (TREE_TYPE (iref), 0));
+ build_int_cst (TREE_TYPE (iref), 0));
}
}