diff options
author | Dan Gohman <gohman@apple.com> | 2010-02-10 06:13:07 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-02-10 06:13:07 +0000 |
commit | a84ffedafc102013a935817f30485a47d3dc2383 (patch) | |
tree | d65734872fd9a7c43f55e3ae07626cbeb1e1b2d2 /lib | |
parent | e7962c9897cf3ac5fc731702d5e5d8963fc5c723 (diff) |
Canonicalize sizeof and alignof on pointer types to a canonical
pointer type.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95769 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index a97396e124..5c117d8a18 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -361,6 +361,15 @@ static Constant *getFoldedSizeOf(const Type *Ty, const Type *DestTy, } } + // Pointer size doesn't depend on the pointee type, so canonicalize them + // to an arbitrary pointee. + if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) + if (!PTy->getElementType()->isInteger(1)) + return + getFoldedSizeOf(PointerType::get(IntegerType::get(PTy->getContext(), 1), + PTy->getAddressSpace()), + DestTy, true); + // If there's no interesting folding happening, bail so that we don't create // a constant that looks like it needs folding but really doesn't. if (!Folded) @@ -417,6 +426,16 @@ static Constant *getFoldedAlignOf(const Type *Ty, const Type *DestTy, return MemberAlign; } + // Pointer alignment doesn't depend on the pointee type, so canonicalize them + // to an arbitrary pointee. + if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) + if (!PTy->getElementType()->isInteger(1)) + return + getFoldedAlignOf(PointerType::get(IntegerType::get(PTy->getContext(), + 1), + PTy->getAddressSpace()), + DestTy, true); + // If there's no interesting folding happening, bail so that we don't create // a constant that looks like it needs folding but really doesn't. if (!Folded) |