diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 3887e33274a..6a91757641a 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -9,7 +9,6 @@ #include "llvm/iMemory.h" #include "llvm/SymbolTable.h" #include "llvm/Module.h" -#include "llvm/SlotCalculator.h" #include "Support/StringExtras.h" #include @@ -80,7 +79,25 @@ Constant *Constant::getNullValue(const Type *Ty) { case Type::PointerTyID: return ConstantPointerNull::get(cast(Ty)); + case Type::StructTyID: { + const StructType *ST = cast(Ty); + + const StructType::ElementTypes &ETs = ST->getElementTypes(); + std::vector Elements; + Elements.resize(ETs.size()); + for (unsigned i = 0, e = ETs.size(); i != e; ++i) + Elements[i] = Constant::getNullValue(ETs[i]); + return ConstantStruct::get(ST, Elements); + } + case Type::ArrayTyID: { + const ArrayType *AT = cast(Ty); + Constant *El = Constant::getNullValue(AT->getElementType()); + unsigned NumElements = AT->getNumElements(); + return ConstantArray::get(AT, std::vector(NumElements, El)); + } default: + // Function, Type, Label, or Opaque type? + assert(0 && "Cannot create a null constant of that type!"); return 0; } }