diff options
-rw-r--r-- | lib/CodeGen/CGDecl.cpp | 17 | ||||
-rw-r--r-- | test/CodeGen/init.c | 2 |
2 files changed, 12 insertions, 7 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index be6638e0e5..8543ca8eef 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -719,10 +719,11 @@ static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc, dyn_cast<llvm::ConstantDataSequential>(Init)) { for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) { llvm::Constant *Elt = CDS->getElementAsConstant(i); - - // Get a pointer to the element and emit it. - emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), - isVolatile, Builder); + + // If necessary, get a pointer to the element and emit it. + if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt)) + emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), + isVolatile, Builder); } return; } @@ -732,9 +733,11 @@ static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc, for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) { llvm::Constant *Elt = cast<llvm::Constant>(Init->getOperand(i)); - // Get a pointer to the element and emit it. - emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), - isVolatile, Builder); + + // If necessary, get a pointer to the element and emit it. + if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt)) + emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), + isVolatile, Builder); } } diff --git a/test/CodeGen/init.c b/test/CodeGen/init.c index 426233d8df..259d34d595 100644 --- a/test/CodeGen/init.c +++ b/test/CodeGen/init.c @@ -69,6 +69,8 @@ char test8(int X) { // CHECK: store i8 97 // CHECK: store i8 98 // CHECK: store i8 99 +// CHECK-NOT: getelementptr +// CHECK: load } void bar(void*); |