diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-03-16 19:15:03 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-03-16 19:15:03 +0000 |
| commit | 777448f6491b6b82e2c39f11d353e39c24dd20e2 (patch) | |
| tree | 32f82c98107a2ac5b7c09456880639b89d2fe445 /lib/Bitcode/Writer/BitcodeWriter.cpp | |
| parent | f1078062916004238c70550585fe1a2e8b32a62f (diff) | |
| download | external_llvm-777448f6491b6b82e2c39f11d353e39c24dd20e2.zip external_llvm-777448f6491b6b82e2c39f11d353e39c24dd20e2.tar.gz external_llvm-777448f6491b6b82e2c39f11d353e39c24dd20e2.tar.bz2 | |
improve support for uniontype and ConstantUnion, patch by Tim Northover!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98656 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Writer/BitcodeWriter.cpp')
| -rw-r--r-- | lib/Bitcode/Writer/BitcodeWriter.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/Bitcode/Writer/BitcodeWriter.cpp b/lib/Bitcode/Writer/BitcodeWriter.cpp index 82e73b5..3ab2726 100644 --- a/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -808,11 +808,25 @@ static void WriteConstants(unsigned FirstVal, unsigned LastVal, else if (isCStr7) AbbrevToUse = CString7Abbrev; } else if (isa<ConstantArray>(C) || isa<ConstantStruct>(V) || - isa<ConstantUnion>(C) || isa<ConstantVector>(V)) { + isa<ConstantVector>(V)) { Code = bitc::CST_CODE_AGGREGATE; for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) Record.push_back(VE.getValueID(C->getOperand(i))); AbbrevToUse = AggregateAbbrev; + } else if (isa<ConstantUnion>(C)) { + Code = bitc::CST_CODE_AGGREGATE; + + // Unions only have one entry but we must send type along with it. + const Type *EntryKind = C->getOperand(0)->getType(); + + const UnionType *UnTy = cast<UnionType>(C->getType()); + int UnionIndex = UnTy->getElementTypeIndex(EntryKind); + assert(UnionIndex != -1 && "Constant union contains invalid entry"); + + Record.push_back(UnionIndex); + Record.push_back(VE.getValueID(C->getOperand(0))); + + AbbrevToUse = AggregateAbbrev; } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { switch (CE->getOpcode()) { default: |
