analyzer: fix ICE comparing COMPLEX_CSTs [PR97668]

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.
This commit is contained in:
David Malcolm 2020-11-05 09:54:58 -05:00
parent ea937e7d87
commit 54cbdb528d
3 changed files with 57 additions and 0 deletions

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

View File

@ -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;
}

View File

@ -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