diff options
author | Martin Liska <mliska@suse.cz> | 2016-11-09 15:07:32 +0100 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2016-11-09 14:07:32 +0000 |
commit | 68c937083c9bea6f91357e60e39db22750908506 (patch) | |
tree | 6fa075f129fb6d4844864c444b14a69a8f3c35a4 /gcc/fold-const-call.c | |
parent | 6fa161dc80d26369400b891ad2435dbcc9aaf67f (diff) |
Fix folding of memcmp("a", "a", 2) (PR
* fold-const-call.c (fold_const_call): Fix the folding.
* gcc.dg/tree-ssa/builtins-folding-generic.c (main): Add new
test-case for memcmp.
* gcc.dg/tree-ssa/builtins-folding-gimple.c: Likewise.
From-SVN: r242000
Diffstat (limited to 'gcc/fold-const-call.c')
-rw-r--r-- | gcc/fold-const-call.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/gcc/fold-const-call.c b/gcc/fold-const-call.c index 1b3a755df34..38f9717f139 100644 --- a/gcc/fold-const-call.c +++ b/gcc/fold-const-call.c @@ -1506,7 +1506,7 @@ tree fold_const_call (combined_fn fn, tree type, tree arg0, tree arg1, tree arg2) { const char *p0, *p1; - size_t s2 = 0; + size_t s0, s1, s2 = 0; switch (fn) { case CFN_BUILT_IN_STRNCMP: @@ -1538,11 +1538,11 @@ fold_const_call (combined_fn fn, tree type, tree arg0, tree arg1, tree arg2) } case CFN_BUILT_IN_BCMP: case CFN_BUILT_IN_MEMCMP: - if ((p0 = c_getstr (arg0)) - && (p1 = c_getstr (arg1)) + if ((p0 = c_getstr (arg0, &s0)) + && (p1 = c_getstr (arg1, &s1)) && host_size_t_cst_p (arg2, &s2) - && s2 <= strlen (p0) - && s2 <= strlen (p1)) + && s2 <= s0 + && s2 <= s1) return build_cmp_result (type, memcmp (p0, p1, s2)); return NULL_TREE; |