[cfe-commits] [PATCH] getLValueElement
Zhongxing Xu
xuzhongxing at gmail.com
Thu Oct 23 17:52:38 PDT 2008
On Fri, Oct 24, 2008 at 8:09 AM, Ted Kremenek <kremenek at apple.com> wrote:
>
> On Oct 22, 2008, at 9:21 PM, Zhongxing Xu wrote:
>
> New patch attached.
>
> On Thu, Oct 23, 2008 at 9:28 AM, Ted Kremenek <kremenek at apple.com> wrote:
>
>>
>> On Oct 22, 2008, at 6:26 PM, Zhongxing Xu wrote:
>>
>>
>>> This assertion will always be true. Did you mean assert(false && "...")?
>>>
>>> No, I just don't want the program to crash when things happen, but also
>>> put reminder there.
>>>
>>> Then it's not really an assertion. Just use a comment.
>>>
>>> OK. I'll make it a comment. But I do see others doing this in Clang.
>>>
>>
>> Those places are probably miswritten assertions. When you spot them feel
>> free to bring it to everyone's attention or submit a patch.
>>
>> Thanks Zhongxing!
>>
>
> <element2.patch>
>
>
> +SVal RegionStoreManager::ArrayToPointer(SVal Array) {
> + const MemRegion* ArrayR = cast<loc::MemRegionVal>(&Array)->getRegion();
> +
> + const VarDecl* D = cast<VarRegion>(ArrayR)->getDecl();
> +
> + const ConstantArrayType* CAT =
> + cast<ConstantArrayType>(D->getType().getTypePtr());
>
> Won't this cast<> fail for VLAs?
>
I fix with this:
+SVal RegionStoreManager::ArrayToPointer(SVal Array) {
+ const MemRegion* ArrayR = cast<loc::MemRegionVal>(&Array)->getRegion();
+
+ const VarDecl* D = cast<VarRegion>(ArrayR)->getDecl();
+
+ if (const ConstantArrayType* CAT =
+ dyn_cast<ConstantArrayType>(D->getType().getTypePtr())) {
+
+ BasicValueFactory& BasicVals = StateMgr.getBasicVals();
+
+ nonloc::ConcreteInt Idx(BasicVals.getValue(0,
CAT->getSize().getBitWidth(),
+ false));
+
+ ElementRegion* ER = MRMgr.getElementRegion(Idx, ArrayR);
+
+ return loc::MemRegionVal(ER);
+ }
+
+ return Array;
+}
I am sure we'll iterate on this when we decide to handle VLAs.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20081024/50d35f3d/attachment.html>
More information about the cfe-commits
mailing list