<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
m3-libs/m3core/src/fingerprint/Poly.i3<br><br> Int32 = [-16_7fffffff-1 .. 16_7fffffff];<br> T = ARRAY [0..1] OF Int32;<br><br>m3-libs/m3core/src/fingerprint/Poly.m3<br><br><br>PROCEDURE Sum (READONLY p, q: T) : T =<br> VAR r : T;<br> BEGIN<br> r[0] := Word.Xor (p[0], q[0]); line 48<br> r[1] := Word.Xor (p[1], q[1]);<br> RETURN r;<br> END Sum;<br><br><br><br> -----LINE 48 -----<br> load v.5 0 Addr Addr<br> load_indirect 0 Int.32 Int.64<br> load v.6 0 Addr Addr<br> load_indirect 0 Int.32 Int.64<br> xor Word.64<br>...<br> check_range Int.64 -2147483648 2147483647 1<br><br><br>if((((INT64)(((UINT64)(((UINT64)(((INT64)(*((INT32*)(p_L_7))))))<br>^((UINT64)(((INT64)(*((INT32*)(q_L_8))))))))))<br><((INT64)(M3_INT64(-2147483648))))<br><br>||<br><br>(((INT64)(M3_INT64(2147483647)))<br><<br>((INT64)(((UINT64)(((UINT64)(((INT64)(*((INT32*)(p_L_7))))))^((UINT64)(((INT64)(*((INT32*)(q_L_8))))))))))))M_Poly_L_4_CRASH(1537);<br><br><br>Poly.mc.c:325: warning: comparison is always false due to limited range of data type<br><br><br><br>or, like:<br><br><br><br>typedef long long INT64;<br>typedef unsigned long long UINT64;<br>typedef int INT32;<br>#define MAXINT32 2147483647<br>#define MININT32 (-2147483648)<br>void ReportFault(void);<br><br><br>#define AssignINT64ToINT32(a, b) \<br>if (((INT64)(b)) < MININT32 || ((INT64)(b)) > MAXINT32) ReportFault(); \<br> a = (INT32)(INT64)(b); \<br><br>INT32 Sum(INT32 p, INT32 q)<br>{<br> INT32 r;<br> AssignINT64ToINT32(r, ((UINT64)(INT64)*(INT32*)&p) ^ ((UINT64)(INT64)*(INT32*)&q));<br> // or this<br> AssignINT64ToINT32(r, ((UINT64)(INT64)p) ^ ((UINT64)(INT64)q));<br> // or heck even this<br> AssignINT64ToINT32(r, p ^ q);<br> return r;<br>}<br><br><br>the operands get widened from 32bits to 64bits, operation done,<br>then range checked, and assigned back to 32bits.<br><br><br>The range check is redundant.<br>It is subtle. 32bit operands sign extended to 64bits will succeed the range check.<br>The upper bits will all be set or clear.<br>If you xor them, the upper bits will still be either all set or all clear, which succeeds the range check.<br><br><br>The C compiler notices it and warns.<br><br><br>I'd like to avoid warnings.<br><br><br>I think the frontend could catch this, easily enough.<br><br><br>Thoughts?<br><br>I'm just about in position to fix this in the C backend.<br>But it'd be cool if the frontend did some cheap analysis always.<br><br><br><br> - Jay </div></body>
</html>