aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGObjC.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-06-24 21:55:10 +0000
committerJohn McCall <rjmccall@apple.com>2011-06-24 21:55:10 +0000
commitbc8d40d85f3fa1e34569834916f18fecaa635152 (patch)
tree47e76a7172c2f2244ee4bbe5fe71fc0bf65e63d3 /lib/CodeGen/CGObjC.cpp
parent89f19e43730a2895cd81159d375c71c91872b8c2 (diff)
Change the IR-generation of VLAs so that we capture bounds,
not sizes; so that we use well-typed allocas; and so that we properly recurse through the full set of variably-modified types. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133827 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGObjC.cpp')
-rw-r--r--lib/CodeGen/CGObjC.cpp25
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index 50e8d320dd..9107e9859e 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -1894,9 +1894,10 @@ namespace {
// If it's a VLA, we have to load the stored size. Note that
// this is the size of the VLA in bytes, not its size in elements.
- llvm::Value *vlaSizeInBytes = 0;
+ llvm::Value *numVLAElements = 0;
if (isa<VariableArrayType>(arrayType)) {
- vlaSizeInBytes = CGF.GetVLASize(cast<VariableArrayType>(arrayType));
+ numVLAElements =
+ CGF.getVLASize(cast<VariableArrayType>(arrayType)).first;
// Walk into all VLAs. This doesn't require changes to addr,
// which has type T* where T is the first non-VLA element type.
@@ -1907,7 +1908,7 @@ namespace {
// If we only have VLA components, 'addr' requires no adjustment.
if (!arrayType) {
baseType = elementType;
- return divideVLASizeByBaseType(CGF, vlaSizeInBytes, baseType);
+ return numVLAElements;
}
} while (isa<VariableArrayType>(arrayType));
@@ -1947,22 +1948,20 @@ namespace {
assert(arrayType && "LLVM and Clang types are out-of-synch");
}
+ baseType = arrayType->getElementType();
+
// Create the actual GEP.
addr = CGF.Builder.CreateInBoundsGEP(addr, gepIndices.begin(),
gepIndices.end(), "array.begin");
- baseType = arrayType->getElementType();
-
- // If we had an VLA dimensions, we need to use the captured size.
- if (vlaSizeInBytes)
- return divideVLASizeByBaseType(CGF, vlaSizeInBytes, baseType);
+ llvm::Value *numElements
+ = llvm::ConstantInt::get(CGF.IntPtrTy, countFromCLAs);
- // Otherwise, use countFromCLAs.
- assert(countFromCLAs == (uint64_t)
- (Ctx.getTypeSizeInChars(origArrayType).getQuantity() /
- Ctx.getTypeSizeInChars(baseType).getQuantity()));
+ // If we had any VLA dimensions, factor them in.
+ if (numVLAElements)
+ numElements = CGF.Builder.CreateNUWMul(numVLAElements, numElements);
- return llvm::ConstantInt::get(CGF.IntPtrTy, countFromCLAs);
+ return numElements;
}
static llvm::Value *divideVLASizeByBaseType(CodeGenFunction &CGF,