don't bother emitting a zero byte memset at all. We used to get them

in cases like this:

typedef struct {
  short instance;
  char name[0];
} ATTR_LIST_ENTRY2;

void test() {
  ATTR_LIST_ENTRY2 X = (ATTR_LIST_ENTRY2) { .instance = 7, };
}  

While it is safe to emit them, it is pretty silly.

llvm-svn: 69687
This commit is contained in:
Chris Lattner 2009-04-21 17:59:23 +00:00
parent 30fb341f4f
commit b534f6a601
1 changed files with 5 additions and 2 deletions

View File

@ -396,8 +396,7 @@ unsigned CodeGenFunction::GetIDForAddrOfLabel(const LabelStmt *L) {
return LabelIDs.insert(std::make_pair(L, LabelIDs.size())).first->second; return LabelIDs.insert(std::make_pair(L, LabelIDs.size())).first->second;
} }
void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) {
{
const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty);
if (DestPtr->getType() != BP) if (DestPtr->getType() != BP)
DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp"); DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp");
@ -405,6 +404,10 @@ void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty)
// Get size and alignment info for this aggregate. // Get size and alignment info for this aggregate.
std::pair<uint64_t, unsigned> TypeInfo = getContext().getTypeInfo(Ty); std::pair<uint64_t, unsigned> TypeInfo = getContext().getTypeInfo(Ty);
// Don't bother emitting a zero-byte memset.
if (TypeInfo.first == 0)
return;
// FIXME: Handle variable sized types. // FIXME: Handle variable sized types.
const llvm::Type *IntPtr = llvm::IntegerType::get(LLVMPointerWidth); const llvm::Type *IntPtr = llvm::IntegerType::get(LLVMPointerWidth);