[cfe-commits] r52049 - in /cfe/trunk: lib/CodeGen/CGExprConstant.cpp test/CodeGen/struct-init.c
Eli Friedman
eli.friedman at gmail.com
Fri Jun 6 11:49:25 PDT 2008
On Fri, Jun 6, 2008 at 9:41 AM, Nuno Lopes <nunoplopes at sapo.pt> wrote:
> Author: nlopes
> Date: Fri Jun 6 11:41:08 2008
> New Revision: 52049
>
> URL: http://llvm.org/viewvc/llvm-project?rev=52049&view=rev
> Log:
> implement constant expr. sub ptr ptr
>
> Added:
> cfe/trunk/test/CodeGen/struct-init.c
> Modified:
> cfe/trunk/lib/CodeGen/CGExprConstant.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprConstant.cpp?rev=52049&r1=52048&r2=52049&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGExprConstant.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp Fri Jun 6 11:41:08 2008
> @@ -447,9 +447,19 @@
> // int - int
> return llvm::ConstantExpr::getSub(LHS, RHS);
> }
> -
> - assert(0 && "Unhandled bin sub case!");
> - return 0;
> +
> + assert(isa<llvm::PointerType>(LHS->getType()));
> +
> + const llvm::Type *ResultType = ConvertType(E->getType());
> + const QualType Type = E->getLHS()->getType();
> + const QualType ElementType = Type->getAsPointerType()->getPointeeType();
> +
> + LHS = llvm::ConstantExpr::getPtrToInt(LHS, ResultType);
> + RHS = llvm::ConstantExpr::getPtrToInt(RHS, ResultType);
> +
> + llvm::Constant *sub = llvm::ConstantExpr::getSub(LHS, RHS);
> + llvm::Constant *size = EmitSizeAlignOf(ElementType, E->getType(), true);
> + return llvm::ConstantExpr::getSDiv(sub, size);
> }
>
> llvm::Constant *VisitBinShl(const BinaryOperator *E) {
>
> Added: cfe/trunk/test/CodeGen/struct-init.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/struct-init.c?rev=52049&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/CodeGen/struct-init.c (added)
> +++ cfe/trunk/test/CodeGen/struct-init.c Fri Jun 6 11:41:08 2008
> @@ -0,0 +1,13 @@
> +// RUN: clang %s -emit-llvm
> +
> +typedef struct _zend_ini_entry zend_ini_entry;
> +struct _zend_ini_entry {
> + void *mh_arg1;
> +};
> +
> +char a;
> +
> +const zend_ini_entry ini_entries[] = {
> + { ((char*)&((zend_ini_entry*)0)->mh_arg1 - (char*)(void*)0)},
> + { ((long long*)&a - (long long*)(void*)2)},
> +};
clang doesn't currently accept this testcase as valid... I suppose I
ought to fix that.
-Eli
More information about the cfe-commits
mailing list