[cfe-commits] r53235 - /cfe/trunk/lib/AST/ExprConstant.cpp
Eli Friedman
eli.friedman at gmail.com
Tue Jul 8 09:29:54 PDT 2008
On Tue, Jul 8, 2008 at 8:35 AM, Anders Carlsson <andersca at mac.com> wrote:
> + uint64_t Offset = ResultLValue.getLValueOffset();
> + if (E->getOpcode() == BinaryOperator::Add)
> + Offset += AdditionalOffset.getZExtValue();
> + else
> + Offset -= AdditionalOffset.getZExtValue();
We probably don't want to succeed here for undefined pointer arithmetic.
> @@ -277,6 +348,41 @@
> return APValue(Result);
> }
>
> +APValue IntExprEvaluator::VisitSizeOfAlignOfTypeExpr
> + (const SizeOfAlignOfTypeExpr *E)
> +{
> + llvm::APSInt Result(32);
> +
> + // Return the result in the right width.
> + Result.zextOrTrunc(static_cast<uint32_t>(Ctx.getTypeSize(E->getType())));
> +
> + // sizeof(void) and __alignof__(void) = 1 as a gcc extension.
> + if (E->getArgumentType()->isVoidType()) {
> + Result = 1;
> + Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
> + return APValue(Result);
> + }
> +
> + // alignof always evaluates to a constant, sizeof does if arg is not VLA.
> + if (E->isSizeOf() && !E->getArgumentType()->isConstantSizeType())
> + return APValue();
> +
> + // Get information about the size or align.
> + if (E->getArgumentType()->isFunctionType()) {
> + // GCC extension: sizeof(function) = 1.
> + Result = E->isSizeOf() ? 1 : 4;
> + } else {
> + unsigned CharSize = Ctx.Target.getCharWidth();
> + if (E->isSizeOf())
> + Result = Ctx.getTypeSize(E->getArgumentType()) / CharSize;
> + else
> + Result = Ctx.getTypeAlign(E->getArgumentType()) / CharSize;
> + }
> +
> + Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
> + return APValue(Result);
> +}
> +
> }
It would be nice to avoid code duplication with the sizeof operator.
-Eli
More information about the cfe-commits
mailing list