<br><br><div class="gmail_quote">On Tue, Jun 1, 2010 at 12:43 PM, Zhongxing Xu <span dir="ltr"><<a href="mailto:xuzhongxing@gmail.com">xuzhongxing@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br><br><div class="gmail_quote"><div class="im">On Tue, Jun 1, 2010 at 12:30 PM, Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com" target="_blank">kremenek@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Jordy,<br>
<br>
I feel that from an API perspective, "Fill" seems like a more natural abstraction for clients. It has the clear semantics of doing a batch binding of values to a chunk of memory and wiping out what was previously there. Given such clear semantics, it is up to the StoreManager to efficiently implement it.<br>
<br>
In the case of RegionStore, RegionStoreManager can implement "Fill" by setting a default binding and removing existing direct bindings. This keeps the implementation lightweight, but also makes the semantics correct. For example, if the the memory region previously had some bindings, some clients will want to know when those bindings go away (e.g., the Objective-C memory leak checker).<br>
<br>
BasicStore could also implement "Fill" very naturally for the bindings it supports without adding the notion of a "default" binding (which it doesn't have).<br>
<br>
'bindDefault' might be okay if all we want to use it for is setting initial values for a memory region, but that's it. I can see that API being misused, however, if clients trying using it outside of just the initialization of a chunk of memory. In this case, I would want to add an assertion checking that that there wasn't an existing default/direct binding when 'bindDefault' is called.<br>
</blockquote></div><div><br>This makes sense.<br><br>Another approach is to reuse InvalidateRegions(), and change it to InvalidateRegionsWithVal(). By default it can set default binding to symbolic. But we can also pass other values to it. That way we can remove bindDefault().<br>
</div></div></blockquote><div><br>But this could be too heavy. What the client need is a way to initialize a region with a default value.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote"><div>
</div><div><div></div><div class="h5"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
'Fill' also seems amendable to modeling memset and friends.<br>
<div><div></div><div><br>
On May 31, 2010, at 9:16 PM, Jordy Rose wrote:<br>
<br>
><br>
> My revised version (from earlier today, never mailed) used a method called<br>
> Fill(), and actually /was/ a fill -- as in, it wiped out any subregion<br>
> bindings and could be used to model memset(). It's heavier, but could be<br>
> used in more situations -- the problem I see with that is that it wouldn't<br>
> do /enough/ (wouldn't handle memset_pattern*(), for example, at least not<br>
> easily in RegionStore).<br>
><br>
> In terms of performance, bindDefault() is certainly lighter, and if the<br>
> contract is that it's only used for "default" filler values for regions,<br>
> then it's not exposing an internal RegionStore detail, just re-using the<br>
> name. (That is, FlatStore should also support such "default" filler<br>
> values.) It would then be incorrect behavior to call bindDefault() if there<br>
> are any direct bindings. (Properly, it would probably be incorrect if there<br>
> are any bindings to the region or any subregions, but that's a relatively<br>
> expensive check just for an assertion.)<br>
><br>
> So I could see bindDefault() being okay, as long as it's a semantic<br>
> "default value" and not a RegionStore term. Alternate terms: fill(er),<br>
> init(ial), defaultContents.<br>
><br>
><br>
> On Mon, 31 May 2010 21:05:26 -0700, Ted Kremenek <<a href="mailto:kremenek@apple.com" target="_blank">kremenek@apple.com</a>><br>
> wrote:<br>
>> Hi Zhongxing, Jordy,<br>
>><br>
>> Do you think that 'bindDefault' is the right API, or at least the right<br>
>> name? The notion of 'default' and 'direct' bindings is something<br>
> internal<br>
>> to the implementation of RegionStore. Is this something we want to<br>
> expose<br>
>> as part of the Store API that must be serviced by all StoreManagers? If<br>
>> so, what does a 'default' value mean to external clients? What are the<br>
>> semantics if an external client calls 'bindDefault' after doing a direct<br>
>> binding?<br>
>><br>
>> Ted<br>
>><br>
>> On May 31, 2010, at 8:04 PM, Zhongxing Xu wrote:<br>
>><br>
>>> Hi Jordy,<br>
>>><br>
>>> I applied most of your patch, except that I adopted 'bindDefault'<br>
>>> approach to set the default value, since it does not touch<br>
> GRExprEngine.<br>
>>> Thanks for working on this!<br>
>>><br>
>>> On Sun, May 30, 2010 at 3:46 PM, Jordy Rose <<a href="mailto:jediknil@belkadan.com" target="_blank">jediknil@belkadan.com</a>><br>
>>> wrote:<br>
>>><br>
>>> Binding a symbolic region whose type is a reference shows up when the<br>
>>> reference is an argument, like so:<br>
>>><br>
>>> char t3 (char& r) {<br>
>>> r = 'c';<br>
>>> if (r) return r;<br>
>>> return '0';<br>
>>> }<br>
>>><br>
>>> The reason for the SymbolicRegion section in canHaveDirectBinding(),<br>
>>> though, was originally more about having a way to set default values by<br>
>>> taking advantages of a fact about SymbolicRegions (if you're accessing<br>
>>> them<br>
>>> directly, it's either *p or a reference, or an explicit call to<br>
> Bind()),<br>
>>> not enforcing a rule.<br>
>>><br>
>>> For looking up super regions' direct bindings, I tried commenting out<br>
>>> that<br>
>>> entire section, but it makes the case you mentioned fail<br>
>>> (no-outofbounds.c). Looking at each of the inside IFs:<br>
>>> 1. SVN blame says this fixed a crash in misc-ps-region-store-x86_64.m.<br>
>>> 2. Same as your example, but with x not yet defined:<br>
>>> int x;<br>
>>> char *p = &x;<br>
>>> return p[0]; // expected-warning {{Undefined}}<br>
>>> 3. LazyCompoundVal is LazyCompoundVal...i.e. I don't fully understand<br>
>>> what<br>
>>> circumstances they're used in. On the other hand, if I understand<br>
>>> correctly, things with compound values should never have direct<br>
> bindings<br>
>>> /other/ than LazyCompoundVal.<br>
>>><br>
>>> It seems like if there's any chance of the feature being useful (even<br>
>>> UnknownVal vs UndefinedVal) this section has to stay. Between<br>
>>> no-outofbounds.c and the commit message about<br>
>>> misc-ps-region-store-x86_64.m<br>
>>> crashing; I didn't pry much deeper.<br>
>>><br>
>>><br>
>>> As for the calloc() part of the patch, it depends on how default values<br>
>>> should be set from outside RegionStore.cpp, which calloc() needs to be<br>
>>> properly modeled. (And malloc(), for that matter.) I came up with three<br>
>>> options:<br>
>>> 1. Add a new BindDefault() method to Store, make it a no-op in<br>
> BasicStore<br>
>>> and implement it for real in RegionStore.<br>
>>> 2. Add a new parameter to SetExtent(). After all, anything with an<br>
>>> explicit extent doesn't get the usual BindArray initialization, and so<br>
>>> it's<br>
>>> going to /need/ some kind of initialization. Downside: the rest of the<br>
>>> Extent code isn't related (though the only extents right now are malloc<br>
>>> regions and alloca regions, which could both use this).<br>
>>> 3. Define binding to a symbolic region as setting a default value.<br>
>>> Because<br>
>>> my fix for PR7218 already changed how lookups worked for arrays, this<br>
>>> didn't seem too far afield, but that's not really a great reason. This<br>
>>> involved the part about changing *p to use ElementRegions ahead of<br>
> time,<br>
>>> so<br>
>>> that the only SymbolicRegions that would make it to Bind() would be the<br>
>>> kind that could have default values (...and references).<br>
>>><br>
>>> I chose #3, but either of the other two would also work. #2 is actually<br>
>>> my<br>
>>> favorite, if we don't mind linking regions and default values<br>
>>> conceptually.<br>
>>><br>
>>> Guess I should have submitted this in two pieces. It's because I was<br>
>>> working on calloc() first that I didn't think of that ahead of time.<br>
>>> Let's<br>
>>> get PR7218 nailed down first, then decide how calloc() can set a<br>
> default<br>
>>> value from outside RegionStore.cpp.<br>
>>><br>
>>> Sorry...? And thanks for the review, and pointing me in the right<br>
>>> direction.<br>
>>> Jordy<br>
>>> (IRC: jediknil)<br>
>>><br>
>>><br>
>>> On Sat, 29 May 2010 14:55:08 +0800, Zhongxing Xu<br>
> <<a href="mailto:xuzhongxing@gmail.com" target="_blank">xuzhongxing@gmail.com</a>><br>
>>> wrote:<br>
>>>> I'm thinking about the whole logic below. Does it make sense to try<br>
> to<br>
>>> get<br>
>>>> the direct binding of the super region of an element region?<br>
>>>><br>
>>>> I can only think of one case:<br>
>>>><br>
>>>> int x = 1;<br>
>>>> char *y = &x;<br>
>>>> y[2];<br>
>>>><br>
>>>> But this case only triggers 'return UnknownVal();' in the last. What<br>
>>> cases<br>
>>>> does the 3 'if' above deal with?<br>
>>>><br>
>>>> RegionStore.cpp:1177<br>
>>>><br>
>>>> // Check if the immediate super region has a direct binding.<br>
>>>> if (const Optional<SVal> &V = getDirectBinding(B, superR)) {<br>
>>>> if (SymbolRef parentSym = V->getAsSymbol()) {<br>
>>>> return ValMgr.getDerivedRegionValueSymbolVal(parentSym, R);<br>
>>>> }<br>
>>>><br>
>>>> if (V->isUnknownOrUndef())<br>
>>>> return *V;<br>
>>>><br>
>>>> // Handle LazyCompoundVals for the immediate super region. Other<br>
>>> cases<br>
>>>> // are handled in 'RetrieveFieldOrElementCommon'.<br>
>>>> if (const nonloc::LazyCompoundVal *LCV =<br>
>>>> dyn_cast<nonloc::LazyCompoundVal>(V)) {<br>
>>>> R = MRMgr.getElementRegionWithSuper(R, LCV->getRegion());<br>
>>>> return RetrieveElement(LCV->getStore(), R);<br>
>>>> }<br>
>>>><br>
>>>> // Other cases: give up.<br>
>>>> return UnknownVal();<br>
>>>> }<br>
>>><br>
<br>
</div></div></blockquote></div></div></div><br>
</blockquote></div><br>