[committed] analyzer: fix ICE handling void-type (PR 93373)

Message ID 20200131222921.13229-1-dmalcolm@redhat.com
State New
Headers show
Series
  • [committed] analyzer: fix ICE handling void-type (PR 93373)
Related show

Commit Message

David Malcolm Jan. 31, 2020, 10:29 p.m.
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to master as r10-6385-g09bea5845a50189b093e7fa8d5b840da702197d4.

gcc/analyzer/ChangeLog:
	PR analyzer/93373
	* region-model.cc (ASSERT_COMPAT_TYPES): Convert to...
	(assert_compat_types): ...this, and bail when either type is NULL,
	or when VOID_TYPE_P (dst_type).
	(region_model::get_lvalue): Update for above conversion.
	(region_model::get_rvalue): Likewise.

gcc/testsuite/ChangeLog:
	PR analyzer/93373
	* gcc.dg/analyzer/torture/pr93373.c: New test.
---
 gcc/analyzer/region-model.cc                    | 12 ++++++++----
 gcc/testsuite/gcc.dg/analyzer/torture/pr93373.c |  3 +++
 2 files changed, 11 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/torture/pr93373.c

-- 
2.21.0

Patch

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index d43aef3a4d7..eb6d8f3cf3a 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -4701,8 +4701,12 @@  region_model::get_lvalue_1 (path_var pv, region_model_context *ctxt)
 
 /* Assert that SRC_TYPE can be converted to DST_TYPE as a no-op.  */
 
-#define ASSERT_COMPAT_TYPES(SRC_TYPE, DST_TYPE) \
-  gcc_checking_assert (useless_type_conversion_p ((SRC_TYPE), (DST_TYPE)))
+static void
+assert_compat_types (tree src_type, tree dst_type)
+{
+  if (src_type && dst_type && !VOID_TYPE_P (dst_type))
+    gcc_checking_assert (useless_type_conversion_p (src_type, dst_type));
+}
 
 /* Get the id of the region for PV within this region_model,
    emitting any diagnostics to CTXT.  */
@@ -4714,7 +4718,7 @@  region_model::get_lvalue (path_var pv, region_model_context *ctxt)
     return region_id::null ();
 
   region_id result_rid = get_lvalue_1 (pv, ctxt);
-  ASSERT_COMPAT_TYPES (get_region (result_rid)->get_type (),
+  assert_compat_types (get_region (result_rid)->get_type (),
 		       TREE_TYPE (pv.m_tree));
   return result_rid;
 }
@@ -4795,7 +4799,7 @@  region_model::get_rvalue (path_var pv, region_model_context *ctxt)
     return svalue_id::null ();
   svalue_id result_sid = get_rvalue_1 (pv, ctxt);
 
-  ASSERT_COMPAT_TYPES (get_svalue (result_sid)->get_type (),
+  assert_compat_types (get_svalue (result_sid)->get_type (),
 		       TREE_TYPE (pv.m_tree));
 
   return result_sid;
diff --git a/gcc/testsuite/gcc.dg/analyzer/torture/pr93373.c b/gcc/testsuite/gcc.dg/analyzer/torture/pr93373.c
new file mode 100644
index 00000000000..c205ee13465
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/torture/pr93373.c
@@ -0,0 +1,3 @@ 
+/* { dg-do compile }
+   { dg-require-effective-target alloca } */
+#include "../../Warray-bounds-41.c"