[cfe-dev] Symbolic Extents

Jordy Rose jediknil at belkadan.com
Thu Jul 1 15:42:25 PDT 2010


> +SVal DeclRegion::getExtent(ValueManager& ValMgr) const {
> +  ASTContext& Ctx = ValMgr.getContext();
> +  QualType T = getDesugaredValueType(Ctx);
> +
> +  // FIXME: Handle variable-length arrays.
> +  if (isa<VariableArrayType>(T))
> +    return UnknownVal();
> +
> +  CharUnits Size = Ctx.getTypeSizeInChars(T);
> +  // Ignore extents for non-indexable types like functions and void.
> +  // As a side effect, this supports the "zero-length array" idiom,
where
> the
> +  // last element of a struct is declared as an array of length 0, then
> used to
> +  // refer to extra memory allocated along with the struct.
> +  if (Size.isZero())
> +    return UnknownVal();
> 
> Should a Decl with size 0 have an unknown extent?

Hm. Looking at it again I realized we don't actually have to /deal/ with
non-indexable types like functions and void, since you can't have a
DeclRegion whose type is one of those. So maybe the only zero-extent decls
are zero-length arrays. In which case the UnknownVal() should be pushed
down to FieldRegion.

Other fixes done (extents on SubRegions only, and SymbolExtent liveness),
so I'll check it in once this is resolved!



More information about the cfe-dev mailing list