<div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
@@ -378,25 +381,22 @@<br>
return loc::MemRegionVal(ER);<br>
}<br>
<br>
-std::pair<const GRState*, SVal><br>
-RegionStoreManager::CastRegion(const GRState* St, SVal VoidPtr,<br>
- QualType CastToTy, Stmt* CastE) {<br>
- if (const AllocaRegion* AR =<br>
- dyn_cast<AllocaRegion>(cast<loc::MemRegionVal>(VoidPtr).getRegion())) {<br>
-<br>
- // Create a new region to attach type information to it.<br>
- const AnonTypedRegion* TR = MRMgr.getAnonTypedRegion(CastToTy, AR);<br>
-<br>
- // Get the pointer to the first element.<br>
- nonloc::ConcreteInt Idx(getBasicVals().getZeroWithPtrWidth(false));<br>
- const ElementRegion* ER = MRMgr.getElementRegion(Idx, TR);<br>
-<br>
- // Add a RegionView to base region.<br>
- return std::make_pair(AddRegionView(St, TR, AR), loc::MemRegionVal(ER));<br>
+StoreManager::CastResult<br>
+RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R,<br>
+ QualType CastToTy) {<br>
+<br>
+ // Return the same region if the region types are compatible.<br>
+ if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {<br>
+ ASTContext& Ctx = StateMgr.getContext();<br>
+ QualType Ta = Ctx.getCanonicalType(TR->getLValueType(Ctx));<br>
+ QualType Tb = Ctx.getCanonicalType(CastToTy);<br>
+<br>
+ if (Ta == Tb)<br>
+ return CastResult(state, R);<br>
}<br>
-<br>
- // Default case.<br>
- return std::make_pair(St, UnknownVal());<br>
+<br>
+ const MemRegion* ViewR = MRMgr.getAnonTypedRegion(CastToTy, R);<br>
+ return CastResult(AddRegionView(state, ViewR, R), ViewR);<br>
}<br>
</blockquote><div><br>Hi Ted,<br><br>Here we still wish to return an ElementRegion instead of a raw AnonTypedRegion. Consider this code:<br><br>char* p = alloca(10); // after this expression, p is expected to be a pointer to the first element of the array.<br>
p[0] = 'a';<br><br>p is expected to have ElementRegion location value in RegionStoreManager::getLValueElement(). <br></div></div><br>