+/*checks for the case expr2 == sizeof buf1 and buf1 is a fixed array*/
+static bool sizeofBufComp(constraintExpr buf1, constraintExpr expr2)
+{
+ constraintTerm ct;
+ exprNode e, t;
+ sRef s1, s2;
+ /*@access constraintExpr@*/
+
+ if ((expr2->kind != term) && (buf1->kind != term) )
+ return FALSE;
+
+
+ ct = constraintExprData_termGetTerm(expr2->data);
+
+ if (!constraintTerm_isExprNode(ct) )
+ return FALSE;
+
+ e = constraintTerm_getExprNode(ct);
+
+ if (e->kind != XPR_SIZEOF)
+ return FALSE;
+
+ t = exprData_getSingle (e->edata);
+ s1 = exprNode_getSref (t);
+
+ s2 = constraintTerm_getsRef(constraintExprData_termGetTerm(buf1->data) );
+
+ /*@i223@*/ /*this may be the wronge thing to test for */
+ if (sRef_similarRelaxed(s1, s2) || sRef_sameName (s1, s2) )
+ {
+ /*@i22*/ /* get rid of this test of now */
+ /* if (ctype_isFixedArray (sRef_getType (s2) ) ) */
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/* look for the special case of
+ maxSet(buf) >= sizeof(buf) - 1
+*/
+
+/*@i223@*/ /*need to add some type checking */
+static bool sizeOfMaxSet( /*@observer@*/ /*@temp@*/ constraint c)
+{
+ constraintExpr l, r, buf1, buf2, con;
+
+ DPRINTF(( message("sizeOfMaxSet: checking %s ", constraint_print(c) )
+ ));
+
+ l = c->lexpr;
+ r = c->expr;
+
+ if (!((c->ar == EQ) || (c->ar == GTE) || (c->ar == LTE) ) )
+ return FALSE;
+
+ /*check if the constraintExpr is MaxSet(buf) */
+ if (l->kind == unaryExpr)
+ {
+ if (constraintExprData_unaryExprGetOp(l->data) == MAXSET)
+ {
+ buf1 = constraintExprData_unaryExprGetExpr(l->data);
+ }
+ else
+ return FALSE;
+ }
+ else
+ return FALSE;
+
+
+ if (r->kind != binaryexpr)
+ return FALSE;
+
+ buf2 = constraintExprData_binaryExprGetExpr1(r->data);
+ con = constraintExprData_binaryExprGetExpr2(r->data);
+
+ if (constraintExprData_binaryExprGetOp(r->data) == BINARYOP_MINUS)
+ {
+ if (constraintExpr_canGetValue(con) )
+ {
+ long i;
+
+ i = constraintExpr_getValue(con);
+ if (i != 1)
+ {
+ return FALSE;
+ }
+ }
+ else
+ return FALSE;
+ }
+
+ if (constraintExprData_binaryExprGetOp(r->data) == BINARYOP_PLUS)
+ {
+ if (constraintExpr_canGetValue(con) )
+ {
+ long i;
+
+ i = constraintExpr_getValue(con);
+ if (i != -1)
+ {
+ return FALSE;
+ }
+ }
+ else
+ return FALSE;
+ }
+
+ if (sizeofBufComp(buf1, buf2))
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+
+
+}
+/*@noaccess constraintExpr@*/
+
+/* We look for constraint which are tautologies */
+
+bool constraint_isAlwaysTrue (/*@observer@*/ /*@temp@*/ constraint c)
+{
+ constraintExpr l, r;
+ bool rHasConstant;
+ int rConstant;
+
+ l = c->lexpr;
+ r = c->expr;
+
+ DPRINTF(( message("constraint_IsAlwaysTrue:examining %s", constraint_print(c) ) ));
+
+ if (sizeOfMaxSet(c) )
+ return TRUE;
+
+ if (constraintExpr_canGetValue(l) && constraintExpr_canGetValue(r) )
+ {
+ int cmp;
+ cmp = constraintExpr_compare (l, r);
+ switch (c->ar)
+ {
+ case EQ:
+ return (cmp == 0);
+ case GT:
+ return (cmp > 0);
+ case GTE:
+ return (cmp >= 0);
+ case LTE:
+ return (cmp <= 0);
+ case LT:
+ return (cmp < 0);
+
+ default:
+ BADEXIT;
+ /*@notreached@*/
+ break;
+ }
+ }
+
+ if (constraintExpr_similar (l,r) )
+ {
+ switch (c->ar)
+ {
+ case EQ:
+ case GTE:
+ case LTE:
+ return TRUE;
+
+ case GT:
+ case LT:
+ break;
+ default:
+ BADEXIT;
+ /*@notreached@*/
+ break;
+ }
+ }
+
+ l = constraintExpr_copy (c->lexpr);
+ r = constraintExpr_copy (c->expr);
+
+ r = constraintExpr_propagateConstants (r, &rHasConstant, &rConstant);
+
+ if (constraintExpr_similar (l,r) && (rHasConstant ) )
+ {
+ DPRINTF(( message("constraint_IsAlwaysTrue: after removing constants %s and %s are similar", constraintExpr_unparse(l), constraintExpr_unparse(r) ) ));
+ DPRINTF(( message("constraint_IsAlwaysTrue: rconstant is %d", rConstant ) ));
+
+ constraintExpr_free(l);
+ constraintExpr_free(r);
+
+ switch (c->ar)
+ {
+ case EQ:
+ return (rConstant == 0);
+ case LT:
+ return (rConstant > 0);
+ case LTE:
+ return (rConstant >= 0);
+ case GTE:
+ return (rConstant <= 0);
+ case GT:
+ return (rConstant < 0);
+
+ default:
+ BADEXIT;
+ /*@notreached@*/
+ break;
+ }
+ }
+ else
+ {
+ constraintExpr_free(l);
+ constraintExpr_free(r);
+ DPRINTF(( message("Constraint %s is not always true", constraint_print(c) ) ));
+ return FALSE;
+ }
+
+ BADEXIT;
+}
+
+static bool rangeCheck (arithType ar1, /*@observer@*/ constraintExpr expr1, arithType ar2, /*@observer@*/ constraintExpr expr2)