diff options
author | Jakub Jelinek <jakub@redhat.com> | 2005-08-29 10:40:48 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2005-08-29 10:40:48 +0200 |
commit | f28d3046d26b66851e570b4c851a0d856f545926 (patch) | |
tree | 3b05ddc14a41f4ae6ef2054dd356f6df933d296e /gcc/builtins.c | |
parent | 37261a5c97f0844da609767d0e5f4dfb748dc6e3 (diff) | |
download | gcc-f28d3046d26b66851e570b4c851a0d856f545926.zip gcc-f28d3046d26b66851e570b4c851a0d856f545926.tar.gz gcc-f28d3046d26b66851e570b4c851a0d856f545926.tar.bz2 |
re PR middle-end/23484 (__builtin___memcpy_chk miscompilation)
PR middle-end/23484
* builtins.c (fold_builtin_memory_chk, fold_builtin_stxcpy_chk,
fold_builtin_strncpy_chk, fold_builtin_snprintf_chk): If len is
not constant, but maxlen is, don't set len to maxlen, rather
set maxlen to len if len is a constant.
* gcc.c-torture/execute/builtins/pr23484-chk.c: New test.
* gcc.c-torture/execute/builtins/pr23484-chk-lib.c: New file.
From-SVN: r103594
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 19d2028..16dfc05 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -10208,10 +10208,11 @@ fold_builtin_memory_chk (tree fndecl, tree arglist, tree maxlen, bool ignore, } return 0; } - len = maxlen; } + else + maxlen = len; - if (tree_int_cst_lt (size, len)) + if (tree_int_cst_lt (size, maxlen)) return 0; } @@ -10313,10 +10314,11 @@ fold_builtin_stxcpy_chk (tree fndecl, tree arglist, tree maxlen, bool ignore, return fold_convert (TREE_TYPE (TREE_TYPE (fndecl)), build_function_call_expr (fn, arglist)); } - len = maxlen; } - - if (! tree_int_cst_lt (len, size)) + else + maxlen = len; + + if (! tree_int_cst_lt (maxlen, size)) return 0; } @@ -10361,10 +10363,11 @@ fold_builtin_strncpy_chk (tree arglist, tree maxlen) if SIZE is >= MAXLEN, never convert to __ocs_fail (). */ if (maxlen == NULL_TREE || ! host_integerp (maxlen, 1)) return 0; - len = maxlen; } + else + maxlen = len; - if (tree_int_cst_lt (size, len)) + if (tree_int_cst_lt (size, maxlen)) return 0; } @@ -10630,10 +10633,11 @@ fold_builtin_snprintf_chk (tree arglist, tree maxlen, if SIZE is >= MAXLEN, never convert to __ocs_fail (). */ if (maxlen == NULL_TREE || ! host_integerp (maxlen, 1)) return 0; - len = maxlen; } + else + maxlen = len; - if (tree_int_cst_lt (size, len)) + if (tree_int_cst_lt (size, maxlen)) return 0; } |