public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7667] tree-optimization/104942: Retain sizetype conversions till the end
@ 2022-03-16 10:41 Siddhesh Poyarekar
0 siblings, 0 replies; only message in thread
From: Siddhesh Poyarekar @ 2022-03-16 10:41 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:818e305ea692ebc6578fb40881887d45382f876b
commit r12-7667-g818e305ea692ebc6578fb40881887d45382f876b
Author: Siddhesh Poyarekar <siddhesh@gotplt.org>
Date: Wed Mar 16 16:10:51 2022 +0530
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>
Diff:
---
.../gcc.dg/builtin-dynamic-object-size-0.c | 22 ++++++++++++++++++++++
gcc/tree-object-size.cc | 5 +----
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 dd8dc99a580..2fca0a9c5b4 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -4,6 +4,15 @@
typedef __SIZE_TYPE__ size_t;
#define abort __builtin_abort
+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__))
@@ -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 8be0df6ba40..9728f79da75 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);
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-03-16 10:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16 10:41 [gcc r12-7667] tree-optimization/104942: Retain sizetype conversions till the end Siddhesh Poyarekar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).