aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-01-14 10:37:58 +0000
committerJohn McCall <rjmccall@apple.com>2011-01-14 10:37:58 +0000
commit5576d9b0a389f6f1f89bdcd37194f4e992b1fbcb (patch)
tree627aa5f534256471bac07b84da7698c61cff65b7 /lib/CodeGen/CodeGenFunction.cpp
parentb8424370ff7ebb63db04b2398ddaa92e829582a4 (diff)
Support the zero-initialization of VLAs when that really means a zero
bit-pattern. Continue punting on zero-initializing VLAs with a nonzero pattern. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123439 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index 76698464c2..8575846162 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -543,15 +543,31 @@ CodeGenFunction::EmitNullInitialization(llvm::Value *DestPtr, QualType Ty) {
uint64_t Size = TypeInfo.first / 8;
unsigned Align = TypeInfo.second / 8;
- // Don't bother emitting a zero-byte memset.
- if (Size == 0)
- return;
+ llvm::Value *SizeVal;
+ bool vla;
- llvm::ConstantInt *SizeVal = llvm::ConstantInt::get(IntPtrTy, Size);
+ // Don't bother emitting a zero-byte memset.
+ if (Size == 0) {
+ // But note that getTypeInfo returns 0 for a VLA.
+ if (const VariableArrayType *vlaType =
+ dyn_cast_or_null<VariableArrayType>(
+ getContext().getAsArrayType(Ty))) {
+ SizeVal = GetVLASize(vlaType);
+ vla = true;
+ } else {
+ return;
+ }
+ } else {
+ SizeVal = llvm::ConstantInt::get(IntPtrTy, Size);
+ vla = false;
+ }
// If the type contains a pointer to data member we can't memset it to zero.
// Instead, create a null constant and copy it to the destination.
if (!CGM.getTypes().isZeroInitializable(Ty)) {
+ // FIXME: variable-size types!
+ if (vla) return;
+
llvm::Constant *NullConstant = CGM.EmitNullConstant(Ty);
llvm::GlobalVariable *NullVariable =
@@ -562,8 +578,6 @@ CodeGenFunction::EmitNullInitialization(llvm::Value *DestPtr, QualType Ty) {
llvm::Value *SrcPtr =
Builder.CreateBitCast(NullVariable, Builder.getInt8PtrTy());
- // FIXME: variable-size types?
-
// Get and call the appropriate llvm.memcpy overload.
Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, Align, false);
return;
@@ -572,8 +586,6 @@ CodeGenFunction::EmitNullInitialization(llvm::Value *DestPtr, QualType Ty) {
// Otherwise, just memset the whole thing to zero. This is legal
// because in LLVM, all default initializers (other than the ones we just
// handled above) are guaranteed to have a bit pattern of all zeros.
-
- // FIXME: Handle variable sized types.
Builder.CreateMemSet(DestPtr, Builder.getInt8(0), SizeVal, Align, false);
}