]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: fix ICE seen with -fsanitize=undefined [PR114899]
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 15 May 2024 22:40:56 +0000 (18:40 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 15 May 2024 22:40:56 +0000 (18:40 -0400)
gcc/analyzer/ChangeLog:
PR analyzer/114899
* access-diagram.cc
(written_svalue_spatial_item::get_label_string): Bulletproof
against SSA_NAME_VAR being null.

gcc/testsuite/ChangeLog:
PR analyzer/114899
* c-c++-common/analyzer/out-of-bounds-diagram-pr114899.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/analyzer/access-diagram.cc
gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-pr114899.c [new file with mode: 0644]

index 500480b6832835e161f2f80902e37a7199ce9a34..8d7461fe381d626c9c321bb48ab671452cc44d44 100644 (file)
@@ -1632,7 +1632,8 @@ protected:
     if (rep_tree)
       {
        if (TREE_CODE (rep_tree) == SSA_NAME)
-         rep_tree = SSA_NAME_VAR (rep_tree);
+         if (tree var = SSA_NAME_VAR (rep_tree))
+           rep_tree = var;
        switch (TREE_CODE (rep_tree))
          {
          default:
diff --git a/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-pr114899.c b/gcc/testsuite/c-c++-common/analyzer/out-of-bounds-diagram-pr114899.c
new file mode 100644 (file)
index 0000000..14ba540
--- /dev/null
@@ -0,0 +1,15 @@
+/* Verify we don't ICE generating out-of-bounds diagram.  */
+
+/* { dg-additional-options " -fsanitize=undefined -fdiagnostics-text-art-charset=unicode" } */
+
+int * a() {
+  int *b = (int *)__builtin_malloc(sizeof(int));
+  int *c = b - 1;
+  ++*c;
+  return b;
+}
+
+/* We don't care about the exact diagram, just that we don't ICE.  */
+
+/* { dg-allow-blank-lines-in-output 1 } */
+/* { dg-prune-output ".*" } */