Size-type inconsistency (signedness) causes confusion and even bugs.
For example when signed compared to unsigned the result might not
be expected.
Summary of this commit:
Related APIs changes:
- getDynamicExtent() returns signed version of extent;
- Add getDynamicElementCountWithOffset() for offset version of element count;
- getElementExtent() could be 0, add defensive checking for getDynamicElementCount, if element is of zero-length, try ConstantArrayType::getSize() as element count;
Related checker changes:
- ArrayBoundCheckerV2: add testcase for signed <-> unsigned comparison from type-inconsistency results by getDynamicExtent()
- ExprInspection: use more general API to report more results
I think checking the nullness of getAs() is more elegant than using a separate isUndef() check.
On a longer term / as a separate improvement, I'd also think about allowing UndefinedVal as the argument of the assert()-like functions, because the evalBinOp -> assert combination is very common in checkers and IIRC in most checkers the branch of UndefinedVal will produce the same result as UnknownVal.