public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-1183] tree-object-size: Don't let error_mark_node escape for ADDR_EXPR [PR105736]
Date: Tue, 21 Jun 2022 07:37:10 +0000 (GMT)	[thread overview]
Message-ID: <20220621073710.90FE7383DBA0@sourceware.org> (raw)

https://gcc.gnu.org/g:70454c50b4592fe6876ecca13268264e395e058f

commit r13-1183-g70454c50b4592fe6876ecca13268264e395e058f
Author: Siddhesh Poyarekar <siddhesh@gotplt.org>
Date:   Tue Jun 21 12:15:07 2022 +0530

    tree-object-size: Don't let error_mark_node escape for ADDR_EXPR [PR105736]
    
    The addr_expr computation does not check for error_mark_node before
    returning the size expression.  This used to work in the constant case
    because the conversion to uhwi would end up causing it to return
    size_unknown, but that won't work for the dynamic case.
    
    Modify the control flow to explicitly return size_unknown if the offset
    computation returns an error_mark_node.
    
    gcc/ChangeLog:
    
            PR tree-optimization/105736
            * tree-object-size.cc (addr_object_size): Return size_unknown
            when object offset computation returns an error.
    
    gcc/testsuite/ChangeLog:
    
            PR tree-optimization/105736
            * gcc.dg/builtin-dynamic-object-size-0.c (TV4): New struct.
            (val3): New variable.
            (test_pr105736): New test.
            (main): Call it.
    
    Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org>

Diff:
---
 gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c | 18 ++++++++++++++++++
 gcc/tree-object-size.cc                              | 20 +++++++++++---------
 2 files changed, 29 insertions(+), 9 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 b5b0b3a677c..01a280b2d7b 100644
--- a/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
+++ b/gcc/testsuite/gcc.dg/builtin-dynamic-object-size-0.c
@@ -479,6 +479,20 @@ test_loop (int *obj, size_t sz, size_t start, size_t end, int incr)
   return __builtin_dynamic_object_size (ptr, 0);
 }
 
+/* Other tests.  */
+
+struct TV4
+{
+  __attribute__((vector_size (sizeof (int) * 4))) int v;
+};
+
+struct TV4 val3;
+int *
+test_pr105736 (struct TV4 *a)
+{
+  return &a->v[0];
+}
+
 unsigned nfails = 0;
 
 #define FAIL() ({ \
@@ -633,6 +647,10 @@ main (int argc, char **argv)
     FAIL ();
   if (test_loop (arr, 42, 20, 52, 1) != 0)
     FAIL ();
+  /* pr105736.  */
+  int *t = test_pr105736 (&val3);
+  if (__builtin_dynamic_object_size (t, 0) != -1)
+    FAIL ();
 
   if (nfails > 0)
     __builtin_abort ();
diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc
index 5ca87ae3504..12bc0868b77 100644
--- a/gcc/tree-object-size.cc
+++ b/gcc/tree-object-size.cc
@@ -695,19 +695,21 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
 	var_size = pt_var_size;
       bytes = compute_object_offset (TREE_OPERAND (ptr, 0), var);
       if (bytes != error_mark_node)
-	bytes = size_for_offset (var_size, bytes);
-      if (var != pt_var
-	  && pt_var_size
-	  && TREE_CODE (pt_var) == MEM_REF
-	  && bytes != error_mark_node)
 	{
-	  tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0), pt_var);
-	  if (bytes2 != error_mark_node)
+	  bytes = size_for_offset (var_size, bytes);
+	  if (var != pt_var && pt_var_size && TREE_CODE (pt_var) == MEM_REF)
 	    {
-	      bytes2 = size_for_offset (pt_var_size, bytes2);
-	      bytes = size_binop (MIN_EXPR, bytes, bytes2);
+	      tree bytes2 = compute_object_offset (TREE_OPERAND (ptr, 0),
+						   pt_var);
+	      if (bytes2 != error_mark_node)
+		{
+		  bytes2 = size_for_offset (pt_var_size, bytes2);
+		  bytes = size_binop (MIN_EXPR, bytes, bytes2);
+		}
 	    }
 	}
+      else
+	bytes = size_unknown (object_size_type);
 
       wholebytes
 	= object_size_type & OST_SUBOBJECT ? var_size : pt_var_wholesize;


                 reply	other threads:[~2022-06-21  7:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220621073710.90FE7383DBA0@sourceware.org \
    --to=siddhesh@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).