Refactoring MemRegion's hierarchy

Hi @clang,

I just stumbled over an annoying quirk in MemRegion's hierarchy. A CodeTextRegion is derived from TypedRegion but conditionlessly asserts on calls to getValueType. That doesn't seems right. The easiest way to fix it is to introduce a TypedValueRegion derived from TypedRegion and move the abstract getValueType to that new class. Then CodeTextRegion derives from TypedRegion and all other classes from TypedValueRegion. Alternatively we can rename TypedRegion to TypedLocationRegion and derive TypedRegion from that class.
The other way to fix that is to introduce an artificial "code text value" type. Such a type doesn't have a syntactically counterpart in C++. But maybe it might be helpful somewhere else. I know this sounds somewhat strange. Better ignore that idea.
Either way we should fix the CodeTextRegion pitfall. I'd go with the first apporach if noone has objections.

Best regards
Olaf Krzikalla

Hi @clang,

I just stumbled over an annoying quirk in MemRegion's hierarchy. A
CodeTextRegion is derived from TypedRegion but conditionlessly asserts
on calls to getValueType. That doesn't seems right. The easiest way to
fix it is to introduce a TypedValueRegion derived from TypedRegion and
move the abstract getValueType to that new class. Then CodeTextRegion
derives from TypedRegion and all other classes from TypedValueRegion.
Alternatively we can rename TypedRegion to TypedLocationRegion and
derive TypedRegion from that class.

Another option is to introduce LocationRegion to be a common predecessor to TypedRegion and CodeTextRegion. (I think this is the same as your second suggestion but with a shorter name.)

Anna.

I think adding a new region is a good direction. I’m not a fan of LocationRegion or TypedLocationRegion because all regions represent locations, so the name seems content free to me.

Added a new TypedValueRegion, and having the current subclasses of TypedRegion other than CodeTextRegion subclass that sounds good to me.

I choosed that path. So I had to change TypedRegion to TypedValueRegion
whereever used. If that had caused trouble I should have noticed.
But all seems OK -> patch attached.
One note: I've moved BlockDataRegionKind out of the TYPED_REGION value range since BlockDataRegion is not a TypedRegion. Thatswhy I had to remove an early return in CStringChecker.cpp too.

Best regards
Olaf Krzikalla

typedvalueregion.patch (31.9 KB)

Looks great! Committed in r137498.