+ int sizefrom = ctype_getSize (tfrom);
+ int sizeto = ctype_getSize (tto);
+
+ DPRINTF (("constraintExpr_div: %s", constraintExpr_unparse (e)));
+ DPRINTF (("Types: %s / %s",
+ ctype_unparse (tfrom),
+ ctype_unparse (tto)));
+
+ if (sizefrom == -1) {
+ llbug (message ("constraintExpr_div: type size unknown: %s", ctype_unparse (tfrom)));
+ }
+
+ if (sizeto == -1) {
+ llbug (message ("constraintExpr_div: type size unknown: %s", ctype_unparse (tto)));
+ }
+
+ if (sizeto == sizefrom)
+ {
+ ; /* Sizes match, a-ok */
+ }
+ else
+ {
+ float scale = (float) sizefrom / (float) sizeto;
+ constraintTerm ct;
+ long val;
+ float fnewval;
+ long newval;
+
+ llassert (e->kind == term);
+ ct = constraintExprData_termGetTerm (e->data);
+ llassert (constraintTerm_canGetValue (ct));
+ val = constraintTerm_getValue (ct);
+
+ DPRINTF (("Scaling constraints by: %ld * %f", val, scale));
+
+ // If scale * val is not an integer, give a warning
+ fnewval = val * scale;
+ newval = (long) fnewval;
+
+ DPRINTF (("Values: %f / %ld", fnewval, newval));
+ if ((fnewval - (float) newval) > FLT_EPSILON)
+ {
+ voptgenerror (FLG_ALLOCMISMATCH,
+ message ("Allocated memory is converted to type %s of (size %d), "
+ "which is not divisible into original allocation of space for %d elements of type %s (size %d)",
+ ctype_unparse (tto), sizeto,
+ val, ctype_unparse (tfrom), sizefrom),
+ loc);
+ }
+
+ constraintTerm_setValue (ct, newval);
+ }
+
+ DPRINTF (("After div: %s", constraintExpr_unparse (e)));