analyzer: fix ICE comparing COMPLEX_CSTs [PR97668]
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 5 Nov 2020 14:54:58 +0000 (09:54 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Thu, 5 Nov 2020 14:54:58 +0000 (09:54 -0500)
gcc/analyzer/ChangeLog:
PR analyzer/97668
* svalue.cc (cmp_cst): Handle COMPLEX_CST.

gcc/testsuite/ChangeLog:
PR analyzer/97668
* gcc.dg/analyzer/pr97668.c: New test.
* gfortran.dg/analyzer/pr97668.f: New test.

gcc/analyzer/svalue.cc
gcc/testsuite/gcc.dg/analyzer/pr97668.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/analyzer/pr97668.f [new file with mode: 0644]

index 18d9c376f5e3bef06ce0a2a8cb45e6e6465cfbdc..e9304522b8e91ebc69e1b20854c0b64bf71f440e 100644 (file)
@@ -291,6 +291,10 @@ cmp_cst (const_tree cst1, const_tree cst2)
       return memcmp (TREE_REAL_CST_PTR (cst1),
                     TREE_REAL_CST_PTR (cst2),
                     sizeof (real_value));
+    case COMPLEX_CST:
+      if (int cmp_real = cmp_cst (TREE_REALPART (cst1), TREE_REALPART (cst2)))
+       return cmp_real;
+      return cmp_cst (TREE_IMAGPART (cst1), TREE_IMAGPART (cst2));
     case VECTOR_CST:
       if (int cmp_log2_npatterns
            = ((int)VECTOR_CST_LOG2_NPATTERNS (cst1)
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr97668.c b/gcc/testsuite/gcc.dg/analyzer/pr97668.c
new file mode 100644 (file)
index 0000000..6ec8164
--- /dev/null
@@ -0,0 +1,27 @@
+/* { dg-additional-options "-O1" } */
+
+void
+wb (_Complex double jh)
+{
+  _Complex double af = 0.0;
+
+  do
+    {
+      af += jh;
+    }
+  while (af != 0.0);
+}
+
+_Complex double
+o6 (void)
+{
+  _Complex double ba = 0.0;
+
+  for (;;)
+    {
+      wb (ba);
+      ba = 1.0;
+    }
+
+  return ba;
+}
diff --git a/gcc/testsuite/gfortran.dg/analyzer/pr97668.f b/gcc/testsuite/gfortran.dg/analyzer/pr97668.f
new file mode 100644 (file)
index 0000000..568c891
--- /dev/null
@@ -0,0 +1,26 @@
+c { dg-additional-options "-std=legacy" }
+
+      SUBROUTINE PPADD (A, C, BH)
+
+      COMPLEX DD, FP, FPP, R1, R2
+      DIMENSION A(*), C(*), BH(*)
+
+      DO 136 IG=IS,1
+         FP = (0.,0.)
+         FPP = (0.,0.)
+
+         DO 121 J=1,1
+            DD = 1./2
+            FP = DD
+            FPP = DD+1
+ 121     CONTINUE
+
+         R2 = -FP
+         IF (ABS(R1)-ABS(R2)) 129,129,133
+ 129     R1 = R2/FPP
+ 133     IT = IT+1
+
+ 136  CONTINUE
+
+      RETURN
+      END