public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/97830 - fix compare of incomplete type size in VN
@ 2020-11-16  8:33 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2020-11-16  8:33 UTC (permalink / raw)
  To: gcc-patches

This avoids passing NULL to expressions_equal_p.

Bootstrap & regtest running on x86_64-unknown-linux-gnu.

2020-11-16  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/97830
	* tree-ssa-sccvn.c (vn_reference_eq): Check for incomplete
	types before comparing TYPE_SIZE.

	* gcc.dg/pr97830.c: New testcase.
---
 gcc/testsuite/gcc.dg/pr97830.c | 24 ++++++++++++++++++++++++
 gcc/tree-ssa-sccvn.c           |  5 ++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr97830.c

diff --git a/gcc/testsuite/gcc.dg/pr97830.c b/gcc/testsuite/gcc.dg/pr97830.c
new file mode 100644
index 00000000000..3729a65aec2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97830.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+typedef enum { LangC } cLanguage;
+typedef enum { FunctionOneArg, FunctionStandard } cFunctionType;
+void *CCTK_CallFunction_function;
+cLanguage CCTK_CallFunction_fdata_0;
+cFunctionType CCTK_CallFunction_fdata_1;
+void CCTK_CallFunction_data() {
+  void (*standardfunc)();
+  int (*oneargfunc)();
+  switch (CCTK_CallFunction_fdata_1) {
+  case FunctionOneArg:
+    oneargfunc = CCTK_CallFunction_function;
+    oneargfunc(CCTK_CallFunction_data);
+    break;
+  case FunctionStandard:
+    switch (CCTK_CallFunction_fdata_0) {
+    case LangC:
+      standardfunc = CCTK_CallFunction_function;
+      standardfunc(CCTK_CallFunction_data);
+    }
+  }
+}
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index c1e49ff7c1b..e0a75636352 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -702,7 +702,10 @@ vn_reference_eq (const_vn_reference_t const vr1, const_vn_reference_t const vr2)
   if (vr1->operands == vr2->operands)
     return true;
 
-  if (!expressions_equal_p (TYPE_SIZE (vr1->type), TYPE_SIZE (vr2->type)))
+  if (COMPLETE_TYPE_P (vr1->type) != COMPLETE_TYPE_P (vr2->type)
+      || (COMPLETE_TYPE_P (vr1->type)
+	  && !expressions_equal_p (TYPE_SIZE (vr1->type),
+				   TYPE_SIZE (vr2->type))))
     return false;
 
   if (INTEGRAL_TYPE_P (vr1->type)
-- 
2.26.2

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

only message in thread, other threads:[~2020-11-16  8:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16  8:33 [PATCH] tree-optimization/97830 - fix compare of incomplete type size in VN Richard Biener

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).