]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-object-size: use size_for_offset in more cases
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Tue, 17 Sep 2024 22:32:52 +0000 (18:32 -0400)
committerSiddhesh Poyarekar <siddhesh@gotplt.org>
Wed, 16 Oct 2024 21:43:12 +0000 (17:43 -0400)
When wholesize != size, there is a reasonable opportunity for static
object sizes also to be computed using size_for_offset, so use that.

gcc/ChangeLog:

* tree-object-size.cc (plus_stmt_object_size): Call
SIZE_FOR_OFFSET for some negative offset cases.

gcc/testsuite/ChangeLog:

* gcc.dg/builtin-object-size-3.c (test9): Adjust test.
* gcc.dg/builtin-object-size-4.c (test8): Likewise.

Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>
gcc/testsuite/gcc.dg/builtin-object-size-3.c
gcc/testsuite/gcc.dg/builtin-object-size-4.c
gcc/tree-object-size.cc

index 3f58da3d500cdb4a20c6a5cf4f0ab2b3712c2305..ec2c62c96401316799167afea8bbfaf014eb7def 100644 (file)
@@ -574,7 +574,7 @@ test9 (unsigned cond)
   if (__builtin_object_size (&p[-4], 2) != (cond ? 6 : 10))
     FAIL ();
 #else
-  if (__builtin_object_size (&p[-4], 2) != 0)
+  if (__builtin_object_size (&p[-4], 2) != 6)
     FAIL ();
 #endif
 
@@ -585,7 +585,7 @@ test9 (unsigned cond)
   if (__builtin_object_size (p, 2) != ((cond ? 2 : 6) + cond))
     FAIL ();
 #else
-  if (__builtin_object_size (p, 2) != 0)
+  if (__builtin_object_size (p, 2) != 2)
     FAIL ();
 #endif
 
@@ -598,7 +598,7 @@ test9 (unsigned cond)
       != sizeof (y) - __builtin_offsetof (struct A, c) - 8 + cond)
     FAIL ();
 #else
-  if (__builtin_object_size (p, 2) != 0)
+  if (__builtin_object_size (p, 2) != sizeof (y) - __builtin_offsetof (struct A, c) - 8)
     FAIL ();
 #endif
 }
index b3eb36efb744d18ec62bf256b24a5625d0340869..7bcd24c415071fb4fdb2dbc36bf0ef6d34438658 100644 (file)
@@ -482,7 +482,7 @@ test8 (unsigned cond)
   if (__builtin_object_size (&p[-4], 3) != (cond ? 6 : 10))
     FAIL ();
 #else
-  if (__builtin_object_size (&p[-4], 3) != 0)
+  if (__builtin_object_size (&p[-4], 3) != 6)
     FAIL ();
 #endif
 
@@ -493,7 +493,7 @@ test8 (unsigned cond)
   if (__builtin_object_size (p, 3) != ((cond ? 2 : 6) + cond))
     FAIL ();
 #else
-  if (__builtin_object_size (p, 3) != 0)
+  if (__builtin_object_size (p, 3) != 2)
     FAIL ();
 #endif
 
@@ -505,7 +505,7 @@ test8 (unsigned cond)
   if (__builtin_object_size (p, 3) != sizeof (y.c) - 8 + cond)
     FAIL ();
 #else
-  if (__builtin_object_size (p, 3) != 0)
+  if (__builtin_object_size (p, 3) != sizeof (y.c) - 8)
     FAIL ();
 #endif
 }
index 6544730e1539e8326c114e242f79c18061679efb..78faae7ad0d34b16c01fcba88e87c4a2607fdcdd 100644 (file)
@@ -1527,6 +1527,7 @@ plus_stmt_object_size (struct object_size_info *osi, tree var, gimple *stmt)
       if (size_unknown_p (bytes, 0))
        ;
       else if ((object_size_type & OST_DYNAMIC)
+              || bytes != wholesize
               || compare_tree_int (op1, offset_limit) <= 0)
        bytes = size_for_offset (bytes, op1, wholesize);
       /* In the static case, with a negative offset, the best estimate for