summaryrefslogtreecommitdiffstats
path: root/clang/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
commit23c29fea92a130313bd389f23a696165eae4a36b (patch)
treeeb365d076c07900ff896e24907685ec3fb80dcc0 /clang/lib/CodeGen/CGObjC.cpp
parent932e5b5d52be4f901bf5370ee6d98349ee209643 (diff)
downloadbcm5719-llvm-23c29fea92a130313bd389f23a696165eae4a36b.tar.gz
bcm5719-llvm-23c29fea92a130313bd389f23a696165eae4a36b.zip
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. llvm-svn: 133827
Diffstat (limited to 'clang/lib/CodeGen/CGObjC.cpp')
-rw-r--r--clang/lib/CodeGen/CGObjC.cpp25
1 files changed, 12 insertions, 13 deletions
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 50e8d320dd5..9107e9859e5 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/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,
OpenPOWER on IntegriCloud