diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-11-24 09:34:13 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-11-24 09:34:13 +0100 |
commit | 51feb980c997f8046fa1a679a27828bcca2d3754 (patch) | |
tree | 859451408331735c0092b2e45e4f12b829b4cfc4 /gcc | |
parent | 489154e71b1b64e05f4b002289480a20976d2588 (diff) | |
download | gcc-51feb980c997f8046fa1a679a27828bcca2d3754.zip gcc-51feb980c997f8046fa1a679a27828bcca2d3754.tar.gz gcc-51feb980c997f8046fa1a679a27828bcca2d3754.tar.bz2 |
tree-object-size.c (pass_through_call): Use gimple_call_return_flags ERF_RETURN*ARG* for builtins other than...
* tree-object-size.c (pass_through_call): Use gimple_call_return_flags
ERF_RETURN*ARG* for builtins other than BUILT_IN_ASSUME_ALIGNED,
check for the latter with gimple_call_builtin_p. Do not handle
BUILT_IN_STPNCPY_CHK which is not a pass through call.
* gcc.dg/builtin-object-size-18.c: New test.
From-SVN: r255133
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/builtin-object-size-18.c | 15 | ||||
-rw-r--r-- | gcc/tree-object-size.c | 37 |
4 files changed, 36 insertions, 27 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1cbc290..787e545 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-11-24 Jakub Jelinek <jakub@redhat.com> + + * tree-object-size.c (pass_through_call): Use gimple_call_return_flags + ERF_RETURN*ARG* for builtins other than BUILT_IN_ASSUME_ALIGNED, + check for the latter with gimple_call_builtin_p. Do not handle + BUILT_IN_STPNCPY_CHK which is not a pass through call. + 2017-11-24 Christophe Lyon <christophe.lyon@linaro.org> * config/arm/arm_neon.h: Fix pragma GCC push_options before diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 943f5fe..480a5c6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-11-24 Jakub Jelinek <jakub@redhat.com> + + * gcc.dg/builtin-object-size-18.c: New test. + 2017-11-23 Julia Koval <julia.koval@intel.com> gcc.target/i386/avx512f-vpexpandb-1.c: New test. diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-18.c b/gcc/testsuite/gcc.dg/builtin-object-size-18.c new file mode 100644 index 0000000..e065393 --- /dev/null +++ b/gcc/testsuite/gcc.dg/builtin-object-size-18.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* __stpncpy_chk could return buf up to buf + 64, so + the minimum object size might be far smaller than 64. */ +/* { dg-final { scan-tree-dump-not "return 64;" "optimized" } } */ + +typedef __SIZE_TYPE__ size_t; + +size_t +foo (const char *p, size_t s, size_t t) +{ + char buf[64]; + char *q = __builtin___stpncpy_chk (buf, p, s, t); + return __builtin_object_size (q, 2); +} diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c index d45f50d..14cb435 100644 --- a/gcc/tree-object-size.c +++ b/gcc/tree-object-size.c @@ -464,34 +464,17 @@ alloc_object_size (const gcall *call, int object_size_type) static tree pass_through_call (const gcall *call) { - tree callee = gimple_call_fndecl (call); + unsigned rf = gimple_call_return_flags (call); + if (rf & ERF_RETURNS_ARG) + { + unsigned argnum = rf & ERF_RETURN_ARG_MASK; + if (argnum < gimple_call_num_args (call)) + return gimple_call_arg (call, argnum); + } - if (callee - && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_NORMAL) - switch (DECL_FUNCTION_CODE (callee)) - { - case BUILT_IN_MEMCPY: - case BUILT_IN_MEMMOVE: - case BUILT_IN_MEMSET: - case BUILT_IN_STRCPY: - case BUILT_IN_STRNCPY: - case BUILT_IN_STRCAT: - case BUILT_IN_STRNCAT: - case BUILT_IN_MEMCPY_CHK: - case BUILT_IN_MEMMOVE_CHK: - case BUILT_IN_MEMSET_CHK: - case BUILT_IN_STRCPY_CHK: - case BUILT_IN_STRNCPY_CHK: - case BUILT_IN_STPNCPY_CHK: - case BUILT_IN_STRCAT_CHK: - case BUILT_IN_STRNCAT_CHK: - case BUILT_IN_ASSUME_ALIGNED: - if (gimple_call_num_args (call) >= 1) - return gimple_call_arg (call, 0); - break; - default: - break; - } + /* __builtin_assume_aligned is intentionally not marked RET1. */ + if (gimple_call_builtin_p (call, BUILT_IN_ASSUME_ALIGNED)) + return gimple_call_arg (call, 0); return NULL_TREE; } |