]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: fix ICE with NULL change.m_expr [PR101875]
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 23 Aug 2021 18:11:58 +0000 (14:11 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Mon, 23 Aug 2021 18:11:58 +0000 (14:11 -0400)
gcc/analyzer/ChangeLog:
PR analyzer/101875
* sm-file.cc (file_diagnostic::describe_state_change): Handle
change.m_expr being NULL.

gcc/testsuite/ChangeLog:
PR analyzer/101875
* gcc.dg/analyzer/pr101875.c: New test.

gcc/analyzer/sm-file.cc
gcc/testsuite/gcc.dg/analyzer/pr101875.c [new file with mode: 0644]

index 6a17019448e41d640f5874a5bec6e5ffd7c7ab5a..0c8cdf0b720ab3df3cd6920b5ed702c1f21ff7e6 100644 (file)
@@ -125,11 +125,21 @@ public:
       return label_text::borrow ("opened here");
     if (change.m_old_state == m_sm.m_unchecked
        && change.m_new_state == m_sm.m_nonnull)
-      return change.formatted_print ("assuming %qE is non-NULL",
-                                    change.m_expr);
+      {
+       if (change.m_expr)
+         return change.formatted_print ("assuming %qE is non-NULL",
+                                        change.m_expr);
+       else
+         return change.formatted_print ("assuming FILE * is non-NULL");
+      }
     if (change.m_new_state == m_sm.m_null)
-      return change.formatted_print ("assuming %qE is NULL",
-                                    change.m_expr);
+      {
+       if (change.m_expr)
+         return change.formatted_print ("assuming %qE is NULL",
+                                        change.m_expr);
+       else
+         return change.formatted_print ("assuming FILE * is NULL");
+      }
     return label_text ();
   }
 
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr101875.c b/gcc/testsuite/gcc.dg/analyzer/pr101875.c
new file mode 100644 (file)
index 0000000..5988b8e
--- /dev/null
@@ -0,0 +1,16 @@
+char *
+fopen (const char *restrict, const char *restrict);
+
+void
+err (void);
+
+void
+k2 (void)
+{
+  char *setfiles[1];
+  int i;
+
+  setfiles[i] = fopen("", ""); /* { dg-warning "use of uninitialized value 'i'" } */
+  if (!setfiles[i]) /* { dg-warning "use of uninitialized value 'i'" } */
+    err ();
+} /* { dg-warning "leak of FILE" } */