<br><br><div class="gmail_quote">On Fri, Nov 14, 2008 at 8:51 AM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com">kremenek@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div bgcolor="#FFFFFF"><div><div></div><div class="Wj3C7c"><div><span>On Nov 13, 2008, at 3:27 PM, Zhongxing Xu <<a href="mailto:xuzhongxing@gmail.com" target="_blank">xuzhongxing@gmail.com</a>> wrote:</span><br></div>
<div><br></div><div></div><blockquote type="cite"><div><br><br><div class="gmail_quote">On Thu, Nov 13, 2008 at 11:03 PM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com" target="_blank"></a><a href="mailto:kremenek@apple.com" target="_blank">kremenek@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div><div></div><div><br><div><div>On Nov 13, 2008, at 1:15 AM, Zhongxing Xu wrote:</div><br><blockquote type="cite"><span style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;">Author: zhongxingxu<br>

Date: Thu Nov 13 03:15:14 2008<br>New Revision: 59238<br><br>URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project?rev=59238&view=rev" target="_blank"></a><a href="http://llvm.org/viewvc/llvm-project?rev=59238&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=59238&view=rev</a><br>

Log:<br>Array index might be unsigned. We have to generate a temporary signed value for<br>it to be evaluated by APSInt::operators.<br><br>Modified:<br>   cfe/trunk/lib/Analysis/RegionStore.cpp<br><br>Modified: cfe/trunk/lib/Analysis/RegionStore.cpp<br>

URL:<span> </span><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=59238&r1=59237&r2=59238&view=diff" target="_blank"></a><a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=59238&r1=59237&r2=59238&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=59238&r1=59237&r2=59238&view=diff</a><br>

<br>==============================================================================<br>--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)<br>+++ cfe/trunk/lib/Analysis/RegionStore.cpp Thu Nov 13 03:15:14 2008<br>@@ -197,6 +197,18 @@<br>

  // Only handle integer indices for now.<br>  if ((CI1 = dyn_cast<nonloc::ConcreteInt>(&Idx)) &&<br>      (CI2 = dyn_cast<nonloc::ConcreteInt>(&Offset))) {<br>+<br>+    // Temporary SVal to hold a potential signed APSInt.<br>

+    SVal SignedInt;<br>+<br>+    // Index might be unsigned. We have to convert it to signed.<br>+    if (CI2->getValue().isUnsigned()) {<br>+      llvm::APSInt SI = CI2->getValue();<br>+      SI.setIsSigned(true);<br>

+      SignedInt = nonloc::ConcreteInt(getBasicVals().getValue(SI));<br>+      CI2 = cast<nonloc::ConcreteInt>(&SignedInt);<br>+    }<br>+</span></blockquote><br></div></div></div><div>Hi Zhongxing,</div><div><br>

</div><div>I'm not saying this isn't needed, but is there a particular justification for the signed -> unsigned conversion?  (I actually don't know by just looking at your patch).  It seems like things like this should go in GRExprEngine, not the Store.</div>

<div></div></div></blockquote><div><br>Consistent signedness is required by llvm::APSInt. So we should find a place to handle this. May be we should ensure all ConcreteInt be signed in GRExprEngine? <br></div></div></div>
</blockquote><br></div></div><div>One question I have is whether or not this conversion is specified in the C standard.  I would like to have a clean way of handling pointer arithmetic and integer overflow (which affects array indexing) and that probably should be handled in GRExprEngine.  GRExprEngine of course could delegate specific micro-operations to Store/ConstraintManager/etc as we already do now for various things.</div>
</div>
</blockquote></div><br>The standard does not specify any information about this conversion. The compiler interprets E1[E2] as *(E1+E2). The sign does not affect the way that the machine does 'add' (or 'sub'). (The sign only affects some operations, c.f. LLVM instructions)<br>
<br>This should not affect us as long as the bits of APSInt is the same as the target pointer. But APSInt operators require the operands have the same signs. So I choose to let them be both signed.<br>