aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@gotplt.org>2022-03-16 16:10:51 +0530
committerSiddhesh Poyarekar <siddhesh@gotplt.org>2022-03-16 16:10:51 +0530
commit818e305ea692ebc6578fb40881887d45382f876b (patch)
tree6d0218fb04a76aa34bbd0e3d7505b68860eb177c
parent952155629ca1a4dfe7c7b26e53d118a9b853ed4a (diff)
downloadgcc-818e305ea692ebc6578fb40881887d45382f876b.zip
gcc-818e305ea692ebc6578fb40881887d45382f876b.tar.gz
gcc-818e305ea692ebc6578fb40881887d45382f876b.tar.bz2
tree-optimization/104942: Retain sizetype conversions till the end
Retain the sizetype alloc_object_size to guarantee the assertion in size_for_offset and to avoid adding a conversion there. nop conversions are eliminated at the end anyway in dynamic object size computation. gcc/ChangeLog: PR tree-optimization/104942 * tree-object-size.cc (alloc_object_size): Remove STRIP_NOPS. gcc/testsuite/ChangeLog: PR tree-optimization/104942 * gcc.dg/builtin-dynamic-object-size-0.c (alloc_func_long, test_builtin_malloc_long): New functions. (main): Use it. Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
-rw-r--r--gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c22
-rw-r--r--gcc/tree-object-size.cc5
2 files changed, 23 insertions, 4 deletions
diff --git a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
index dd8dc99..2fca0a9 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -8,6 +8,15 @@ void *
__attribute__ ((alloc_size (1)))
__attribute__ ((__nothrow__ , __leaf__))
__attribute__ ((noinline))
+alloc_func_long (long sz)
+{
+ return __builtin_malloc (sz);
+}
+
+void *
+__attribute__ ((alloc_size (1)))
+__attribute__ ((__nothrow__ , __leaf__))
+__attribute__ ((noinline))
alloc_func (size_t sz)
{
return __builtin_malloc (sz);
@@ -145,6 +154,16 @@ test_builtin_malloc_condphi5 (size_t sz, int cond, char *c)
return ret;
}
+long
+__attribute__ ((noinline))
+test_builtin_malloc_long (long sz, long off)
+{
+ char *a = alloc_func_long (sz);
+ char *dest = a + off;
+ long ret = __builtin_dynamic_object_size (dest, 0);
+ return ret;
+}
+
/* Calloc-like allocator. */
size_t
@@ -419,6 +438,9 @@ main (int argc, char **argv)
FAIL ();
if (test_builtin_malloc_condphi5 (128, 0, argv[0]) != -1)
FAIL ();
+ long x = 42;
+ if (test_builtin_malloc_long (x, 0) != x)
+ FAIL ();
if (test_calloc (2048, 4) != 2048 * 4)
FAIL ();
if (test_builtin_calloc (2048, 8) != 2048 * 8)
diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc
index 8be0df6..9728f79 100644
--- a/gcc/tree-object-size.cc
+++ b/gcc/tree-object-size.cc
@@ -784,10 +784,7 @@ alloc_object_size (const gcall *call, int object_size_type)
else if (arg1 >= 0)
bytes = fold_convert (sizetype, gimple_call_arg (call, arg1));
- if (bytes)
- return STRIP_NOPS (bytes);
-
- return size_unknown (object_size_type);
+ return bytes ? bytes : size_unknown (object_size_type);
}