tree-optimization/97830 - fix compare of incomplete type size in VN
authorRichard Biener <rguenther@suse.de>
Mon, 16 Nov 2020 07:40:47 +0000 (08:40 +0100)
committerRichard Biener <rguenther@suse.de>
Mon, 16 Nov 2020 08:33:04 +0000 (09:33 +0100)
This avoids passing NULL to expressions_equal_p.

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 [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

diff --git a/gcc/testsuite/gcc.dg/pr97830.c b/gcc/testsuite/gcc.dg/pr97830.c
new file mode 100644 (file)
index 0000000..3729a65
--- /dev/null
@@ -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);
+    }
+  }
+}
index 4d78054b1e00a78afc71779d6ef27660d72f1a5f..81990fcbd34687917020b24bd235a485d1377704 100644 (file)
@@ -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)