public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7782] analyzer: fix ICE adding note to disabled diagnostic [PR104997]
@ 2022-03-23 12:35 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-03-23 12:35 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:160b095fc9ded4eaa2bf4d49bd97319f4aabff0a

commit r12-7782-g160b095fc9ded4eaa2bf4d49bd97319f4aabff0a
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Wed Mar 23 08:32:17 2022 -0400

    analyzer: fix ICE adding note to disabled diagnostic [PR104997]
    
    gcc/analyzer/ChangeLog:
            PR analyzer/104997
            * diagnostic-manager.cc (diagnostic_manager::add_diagnostic):
            Convert return type from "void" to "bool", reporting success vs
            failure to caller, for both overloads.
            * diagnostic-manager.h (diagnostic_manager::add_diagnostic):
            Likewise.
            * engine.cc (impl_region_model_context::warn): Propagate return
            value from diagnostic_manager::add_diagnostic.
    
    gcc/testsuite/ChangeLog:
            PR analyzer/104997
            * gcc.dg/analyzer/write-to-string-literal-4-disabled.c: New test,
            adapted from write-to-string-literal-4.c.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/diagnostic-manager.cc                 | 18 +++++++++-----
 gcc/analyzer/diagnostic-manager.h                  |  4 ++--
 gcc/analyzer/engine.cc                             |  9 +++----
 .../analyzer/write-to-string-literal-4-disabled.c  | 28 ++++++++++++++++++++++
 4 files changed, 45 insertions(+), 14 deletions(-)

diff --git a/gcc/analyzer/diagnostic-manager.cc b/gcc/analyzer/diagnostic-manager.cc
index d5e5b6926cc..bf7c8fc5147 100644
--- a/gcc/analyzer/diagnostic-manager.cc
+++ b/gcc/analyzer/diagnostic-manager.cc
@@ -874,9 +874,11 @@ diagnostic_manager::diagnostic_manager (logger *logger, engine *eng,
 {
 }
 
-/* Queue pending_diagnostic D at ENODE for later emission.  */
+/* Queue pending_diagnostic D at ENODE for later emission.
+   Return true/false signifying if the diagnostic was actually added.
+   Take ownership of D (or delete it).  */
 
-void
+bool
 diagnostic_manager::add_diagnostic (const state_machine *sm,
 				    exploded_node *enode,
 				    const supernode *snode, const gimple *stmt,
@@ -907,7 +909,7 @@ diagnostic_manager::add_diagnostic (const state_machine *sm,
 				d->get_kind ());
 	  delete d;
 	  m_num_disabled_diagnostics++;
-	  return;
+	  return false;
 	}
     }
 
@@ -920,18 +922,22 @@ diagnostic_manager::add_diagnostic (const state_machine *sm,
     log ("adding saved diagnostic %i at SN %i to EN %i: %qs",
 	 sd->get_index (),
 	 snode->m_index, enode->m_index, d->get_kind ());
+  return true;
 }
 
-/* Queue pending_diagnostic D at ENODE for later emission.  */
+/* Queue pending_diagnostic D at ENODE for later emission.
+   Return true/false signifying if the diagnostic was actually added.
+   Take ownership of D (or delete it).  */
 
-void
+bool
 diagnostic_manager::add_diagnostic (exploded_node *enode,
 				    const supernode *snode, const gimple *stmt,
 				    stmt_finder *finder,
 				    pending_diagnostic *d)
 {
   gcc_assert (enode);
-  add_diagnostic (NULL, enode, snode, stmt, finder, NULL_TREE, NULL, 0, d);
+  return add_diagnostic (NULL, enode, snode, stmt, finder, NULL_TREE,
+			 NULL, 0, d);
 }
 
 /* Add PN to the most recent saved_diagnostic.  */
diff --git a/gcc/analyzer/diagnostic-manager.h b/gcc/analyzer/diagnostic-manager.h
index 34abf56d11f..fc5dc043c78 100644
--- a/gcc/analyzer/diagnostic-manager.h
+++ b/gcc/analyzer/diagnostic-manager.h
@@ -107,7 +107,7 @@ public:
 
   json::object *to_json () const;
 
-  void add_diagnostic (const state_machine *sm,
+  bool add_diagnostic (const state_machine *sm,
 		       exploded_node *enode,
 		       const supernode *snode, const gimple *stmt,
 		       stmt_finder *finder,
@@ -116,7 +116,7 @@ public:
 		       state_machine::state_t state,
 		       pending_diagnostic *d);
 
-  void add_diagnostic (exploded_node *enode,
+  bool add_diagnostic (exploded_node *enode,
 		       const supernode *snode, const gimple *stmt,
 		       stmt_finder *finder,
 		       pending_diagnostic *d);
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index f911ed4ac39..caa8796b494 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -129,12 +129,9 @@ impl_region_model_context::warn (pending_diagnostic *d)
       return false;
     }
   if (m_eg)
-    {
-      m_eg->get_diagnostic_manager ().add_diagnostic
-	(m_enode_for_diag, m_enode_for_diag->get_supernode (),
-	 m_stmt, m_stmt_finder, d);
-      return true;
-    }
+    return m_eg->get_diagnostic_manager ().add_diagnostic
+      (m_enode_for_diag, m_enode_for_diag->get_supernode (),
+       m_stmt, m_stmt_finder, d);
   else
     {
       delete d;
diff --git a/gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-4-disabled.c b/gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-4-disabled.c
new file mode 100644
index 00000000000..fa21af13341
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/write-to-string-literal-4-disabled.c
@@ -0,0 +1,28 @@
+/* Verify that we can disable warnings that have notes added to them via
+   region_model_context_decorator::add_note.  */
+
+/* { dg-additional-options "-Wno-analyzer-write-to-string-literal" } */
+
+typedef __SIZE_TYPE__ size_t;
+
+int getrandom (void *__buffer, size_t __length, /* { dg-bogus "parameter 1 of 'getrandom' marked with attribute 'access \\(write_only, 1, 2\\)'" } */
+	       unsigned int __flags)
+  __attribute__ ((access (__write_only__, 1, 2)));
+
+#define GRND_RANDOM 0x02
+
+void test (int flag)
+{
+  char *buf;
+
+  if (flag)
+    buf = __builtin_malloc (1024);
+  else
+    buf = (char *)""; /* { dg-bogus "here" } */
+
+  if (getrandom(buf, 16, GRND_RANDOM)) /* { dg-bogus "write to string literal" } */
+    __builtin_printf("%s\n", buf);
+
+  if (flag)
+    __builtin_free (buf);
+}


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

only message in thread, other threads:[~2022-03-23 12:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-23 12:35 [gcc r12-7782] analyzer: fix ICE adding note to disabled diagnostic [PR104997] 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).