]> granicus.if.org Git - clang/commitdiff
don't bother emitting a zero byte memset at all. We used to get them
authorChris Lattner <sabre@nondot.org>
Tue, 21 Apr 2009 17:59:23 +0000 (17:59 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 21 Apr 2009 17:59:23 +0000 (17:59 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69687 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.cpp

index 45c7d0aa27a1f593a663b0c8ea1bb6c47e86765d..082beb8de8544a72c0fa6415f17d3dcdc2e5396c 100644 (file)
@@ -396,8 +396,7 @@ unsigned CodeGenFunction::GetIDForAddrOfLabel(const LabelStmt *L) {
   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);
   if (DestPtr->getType() != BP)
     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.
   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.
   const llvm::Type *IntPtr = llvm::IntegerType::get(LLVMPointerWidth);