public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] analyzer: handle arrays of unknown size in access diagrams [PR113222]
@ 2024-01-04 14:27 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2024-01-04 14:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: David Malcolm

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Successful run of analyzer integration tests on x86_64-pc-linux-gnu.
Pushed to trunk as r14-6917-gdb5b01d282a0e3.

gcc/analyzer/ChangeLog:
	PR analyzer/113222
	* access-diagram.cc (valid_region_spatial_item::add_boundaries):
	Handle TYPE_DOMAIN being null.
	(valid_region_spatial_item::add_array_elements_to_table):
	Likewise.

gcc/testsuite/ChangeLog:
	PR analyzer/113222
	* gcc.dg/analyzer/out-of-bounds-diagram-pr113222.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/analyzer/access-diagram.cc                |  4 +--
 .../analyzer/out-of-bounds-diagram-pr113222.c | 26 +++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-pr113222.c

diff --git a/gcc/analyzer/access-diagram.cc b/gcc/analyzer/access-diagram.cc
index fb8c0282e751..45d218dfb74f 100644
--- a/gcc/analyzer/access-diagram.cc
+++ b/gcc/analyzer/access-diagram.cc
@@ -1334,7 +1334,7 @@ public:
 	    logger->log ("showing first and final element in array type");
 	  region_model_manager *mgr = m_op.m_model.get_manager ();
 	  tree domain = TYPE_DOMAIN (base_type);
-	  if (TYPE_MIN_VALUE (domain) && TYPE_MAX_VALUE (domain))
+	  if (domain && TYPE_MIN_VALUE (domain) && TYPE_MAX_VALUE (domain))
 	    {
 	      const svalue *min_idx_sval
 		= mgr->get_or_create_constant_svalue (TYPE_MIN_VALUE (domain));
@@ -1364,7 +1364,7 @@ public:
     gcc_assert (m_boundaries != nullptr);
 
     tree domain = TYPE_DOMAIN (base_type);
-    if (!(TYPE_MIN_VALUE (domain) && TYPE_MAX_VALUE (domain)))
+    if (!(domain && TYPE_MIN_VALUE (domain) && TYPE_MAX_VALUE (domain)))
       return;
 
     const int table_y = 0;
diff --git a/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-pr113222.c b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-pr113222.c
new file mode 100644
index 000000000000..444676669ac3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/out-of-bounds-diagram-pr113222.c
@@ -0,0 +1,26 @@
+/* Verify that we don't ICE when generating an out-of-bounds diagram
+   when the size of an array is unknown.  */
+
+/* { dg-do compile } */
+/* { dg-additional-options "-fdiagnostics-text-art-charset=unicode" } */
+
+#include <stdint.h>
+
+struct sched_class
+{
+  int64_t f;
+};
+extern struct sched_class __end_sched_classes[];
+
+int
+test ()
+{
+  const struct sched_class* class = ((__end_sched_classes - 1));
+  return class->f; /* { dg-warning "buffer under-read" } */
+}
+
+/* We don't care about the content of the diagram, just that we don't
+   ICE creating it.  */
+
+/* { dg-allow-blank-lines-in-output 1 } */
+/* { dg-prune-output ".*" } */
-- 
2.26.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-04 14:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-04 14:27 [pushed] analyzer: handle arrays of unknown size in access diagrams [PR113222] David Malcolm

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).