]> granicus.if.org Git - clang/commitdiff
CodeGen: Hoist check from recursive function to its only callsite.
authorBenjamin Kramer <benny.kra@googlemail.com>
Mon, 27 Aug 2012 22:07:02 +0000 (22:07 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Mon, 27 Aug 2012 22:07:02 +0000 (22:07 +0000)
Suggested by Roman Divacky.

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

lib/CodeGen/CGDecl.cpp

index 8543ca8eef46d35148d36310e0f70d1e43450310..35d1a623a833b5084ee87aae998306281290d71c 100644 (file)
@@ -704,9 +704,8 @@ static bool canEmitInitWithFewStoresAfterMemset(llvm::Constant *Init,
 /// stores that would be required.
 static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc,
                                          bool isVolatile, CGBuilderTy &Builder) {
-  // Zero doesn't require a store.
-  if (Init->isNullValue() || isa<llvm::UndefValue>(Init))
-    return;
+  assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) &&
+         "called emitStoresForInitAfterMemset for zero or undef value.");
 
   if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
       isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
@@ -1062,7 +1061,8 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
                 CGM.getTargetData().getTypeAllocSize(constant->getType()))) {
     Builder.CreateMemSet(Loc, llvm::ConstantInt::get(Int8Ty, 0), SizeVal,
                          alignment.getQuantity(), isVolatile);
-    if (!constant->isNullValue()) {
+    // Zero and undef don't require a stores.
+    if (!constant->isNullValue() && !isa<llvm::UndefValue>(constant)) {
       Loc = Builder.CreateBitCast(Loc, constant->getType()->getPointerTo());
       emitStoresForInitAfterMemset(constant, Loc, isVolatile, Builder);
     }