[cfe-commits] r154849 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/const-eval.c

Richard Smith richard at metafoo.co.uk
Mon Apr 16 12:48:18 PDT 2012


On Mon, Apr 16, 2012 at 12:23 PM, Eli Friedman <eli.friedman at gmail.com>wrote:

> Author: efriedma
> Date: Mon Apr 16 14:23:57 2012
> New Revision: 154849
>
> URL: http://llvm.org/viewvc/llvm-project?rev=154849&view=rev
> Log:
> Per Richard's comments on r154794, add the checks necessary to handle
> constant-folding relational comparisons safely in case the user is using
> -fwrapv or equivalent.
>
>
> Modified:
>    cfe/trunk/lib/AST/ExprConstant.cpp
>    cfe/trunk/test/Sema/const-eval.c
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=154849&r1=154848&r2=154849&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Apr 16 14:23:57 2012
> @@ -5090,8 +5090,6 @@
>
>       // The comparison here must be unsigned, and performed with the same
>       // width as the pointer.
> -      // FIXME: Knowing the base is the same for the LHS and RHS isn't
> enough
> -      // for relational operators.
>       unsigned PtrSize = Info.Ctx.getTypeSize(LHSTy);
>       uint64_t CompareLHS = LHSOffset.getQuantity();
>       uint64_t CompareRHS = RHSOffset.getQuantity();
> @@ -5100,6 +5098,19 @@
>       CompareLHS &= Mask;
>       CompareRHS &= Mask;
>
> +      // If there is a base and this is a relational operator, we can only
> +      // compare pointers within the object in question; otherwise, the
> result
> +      // depends on where the object is located in memory.
> +      if (!LHSValue.Base.isNull() && E->isRelationalOp()) {
> +        QualType BaseTy = getType(LHSValue.Base);
> +        if (BaseTy->isIncompleteType())
> +          return Error(E);
>

Can we treat incomplete types as having size 0? AFAICS this is legal in
C++11:

struct S a;
constexpr bool b = &a < &a;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120416/ecc1984b/attachment.html>


More information about the cfe-commits mailing list