public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3096] analyzer: fix ICE with NULL change.m_expr [PR101875]
@ 2021-08-23 18:12 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2021-08-23 18:12 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3d654ca3f421ff9646470d312097602037176352
commit r12-3096-g3d654ca3f421ff9646470d312097602037176352
Author: David Malcolm <dmalcolm@redhat.com>
Date: Mon Aug 23 14:11:58 2021 -0400
analyzer: fix ICE with NULL change.m_expr [PR101875]
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.
Diff:
---
gcc/analyzer/sm-file.cc | 18 ++++++++++++++----
gcc/testsuite/gcc.dg/analyzer/pr101875.c | 16 ++++++++++++++++
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc
index 6a17019448e..0c8cdf0b720 100644
--- a/gcc/analyzer/sm-file.cc
+++ b/gcc/analyzer/sm-file.cc
@@ -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
index 00000000000..5988b8ea9ab
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr101875.c
@@ -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" } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-23 18:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 18:12 [gcc r12-3096] analyzer: fix ICE with NULL change.m_expr [PR101875] 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).