From: Siddhesh Poyarekar <siddhesh@gotplt.org>
To: gcc-patches@gcc.gnu.org
Cc: jakub@redhat.com
Subject: [PATCH] tree-optimization/104941: Actually assign the conversion result
Date: Wed, 16 Mar 2022 20:24:24 +0530 [thread overview]
Message-ID: <20220316145424.1807869-1-siddhesh@gotplt.org> (raw)
Assign the result of fold_convert to offset.
gcc/ChangeLog:
PR tree-optimization/104941
* tree-object-size.cc (size_for_offset): Assign result of
fold_convert to OFFSET.
gcc/testsuite/ChangeLog:
PR tree-optimization/104941
* gcc.dg/builtin-dynamic-object-size-0.c (S1, S2): New structs.
(test_alloc_nested_structs, g): New functions.
(main): Call test_alloc_nested_structs.
Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
---
Testing:
- x86_64 bootstrap build and check
- i686 build and check
.../gcc.dg/builtin-dynamic-object-size-0.c | 34 +++++++++++++++++++
gcc/tree-object-size.cc | 2 +-
2 files changed, 35 insertions(+), 1 deletion(-)
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 2fca0a9c5b4..e5dc23a908d 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -323,6 +323,34 @@ test_substring (size_t sz, size_t off)
return __builtin_dynamic_object_size (&str[off], 0);
}
+struct S2
+{
+ char arr[7];
+};
+
+struct S1
+{
+ int pad;
+ struct S2 s2;
+};
+
+static long
+g (struct S1 *s1)
+{
+ struct S2 *s2 = &s1->s2;
+ return __builtin_dynamic_object_size (s2->arr, 0);
+}
+
+long
+__attribute__ ((noinline))
+test_alloc_nested_structs (int x)
+{
+ struct S1 *s1 = __builtin_malloc (x);
+ return g (s1);
+}
+
+/* POINTER_PLUS expressions. */
+
size_t
__attribute__ ((noinline))
test_substring_ptrplus (size_t sz, size_t off)
@@ -342,6 +370,8 @@ test_substring_ptrplus2 (size_t sz, size_t off, size_t off2)
return __builtin_dynamic_object_size (ptr + off2, 0);
}
+/* Function parameters. */
+
size_t
__attribute__ ((access (__read_write__, 1, 2)))
__attribute__ ((noinline))
@@ -382,6 +412,8 @@ test_parmsz_unknown (void *obj, void *unknown, size_t sz, int cond)
return __builtin_dynamic_object_size (cond ? obj : unknown, 0);
}
+/* Loops. */
+
size_t
__attribute__ ((noinline))
__attribute__ ((access (__read_write__, 1, 2)))
@@ -491,6 +523,8 @@ main (int argc, char **argv)
FAIL ();
if (test_dynarray_cond (1) != 8)
FAIL ();
+ if (test_alloc_nested_structs (42) != 42 - sizeof (int))
+ FAIL ();
if (test_deploop (128, 4) != 128)
FAIL ();
if (test_deploop (128, 129) != 32)
diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc
index 9728f79da75..e23e80cb726 100644
--- a/gcc/tree-object-size.cc
+++ b/gcc/tree-object-size.cc
@@ -372,7 +372,7 @@ size_for_offset (tree sz, tree offset, tree wholesize = NULL_TREE)
/* Safe to convert now, since a valid net offset should be non-negative. */
if (!types_compatible_p (TREE_TYPE (offset), sizetype))
- fold_convert (sizetype, offset);
+ offset = fold_convert (sizetype, offset);
if (TREE_CODE (offset) == INTEGER_CST)
{
--
2.35.1
next reply other threads:[~2022-03-16 14:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-16 14:54 Siddhesh Poyarekar [this message]
2022-03-16 15:04 ` Jakub Jelinek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220316145424.1807869-1-siddhesh@gotplt.org \
--to=siddhesh@gotplt.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).