diff options
author | Mark Seaborn <mseaborn@chromium.org> | 2013-06-26 08:42:14 -0700 |
---|---|---|
committer | Mark Seaborn <mseaborn@chromium.org> | 2013-06-26 08:42:14 -0700 |
commit | e635564fe07f78c19fd6022aa105f620e7cad60a (patch) | |
tree | 6f1e0279dbac4f14ca787645663db02babffae61 /lib | |
parent | 3a69b22c3d95634002f80e1e491616942e0407d7 (diff) |
PNaCl wire format: Remove magic number and hash from encoding of 'switch'
The magic number is no longer needed now that the reader for the old
switch representation has been removed (in
https://codereview.chromium.org/17764003), so we can remove this
baggage.
Also add a missing record size check to the reader.
BUG=https://code.google.com/p/nativeclient/issues/detail?id=3507
TEST=hello_world.pexe includes a switch statement; also PNaCl toolchain trybots
Review URL: https://codereview.chromium.org/17777005
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp | 98 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp | 3 |
2 files changed, 46 insertions, 55 deletions
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp index 0fe72704e0..57dcea8953 100644 --- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp +++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp @@ -2128,63 +2128,57 @@ bool NaClBitcodeReader::ParseFunctionBody(Function *F) { break; } case naclbitc::FUNC_CODE_INST_SWITCH: { // SWITCH: [opty, op0, op1, ...] - // Check magic - if ((Record[0] >> 16) == SWITCH_INST_MAGIC) { - // New SwitchInst format with case ranges. - - Type *OpTy = getTypeByID(Record[1]); - unsigned ValueBitWidth = cast<IntegerType>(OpTy)->getBitWidth(); - - Value *Cond = getValue(Record, 2, NextValueNo, OpTy); - BasicBlock *Default = getBasicBlock(Record[3]); - if (OpTy == 0 || Cond == 0 || Default == 0) - return Error("Invalid SWITCH record"); - - unsigned NumCases = Record[4]; - - SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases); - InstructionList.push_back(SI); - - unsigned CurIdx = 5; - for (unsigned i = 0; i != NumCases; ++i) { - IntegersSubsetToBB CaseBuilder; - unsigned NumItems = Record[CurIdx++]; - for (unsigned ci = 0; ci != NumItems; ++ci) { - bool isSingleNumber = Record[CurIdx++]; - - APInt Low; - unsigned ActiveWords = 1; + // New SwitchInst format with case ranges. + if (Record.size() < 4) + return Error("Invalid SWITCH record"); + Type *OpTy = getTypeByID(Record[0]); + unsigned ValueBitWidth = cast<IntegerType>(OpTy)->getBitWidth(); + + Value *Cond = getValue(Record, 1, NextValueNo, OpTy); + BasicBlock *Default = getBasicBlock(Record[2]); + if (OpTy == 0 || Cond == 0 || Default == 0) + return Error("Invalid SWITCH record"); + + unsigned NumCases = Record[3]; + + SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases); + InstructionList.push_back(SI); + + unsigned CurIdx = 4; + for (unsigned i = 0; i != NumCases; ++i) { + IntegersSubsetToBB CaseBuilder; + unsigned NumItems = Record[CurIdx++]; + for (unsigned ci = 0; ci != NumItems; ++ci) { + bool isSingleNumber = Record[CurIdx++]; + + APInt Low; + unsigned ActiveWords = 1; + if (ValueBitWidth > 64) + ActiveWords = Record[CurIdx++]; + Low = ReadWideAPInt(makeArrayRef(&Record[CurIdx], ActiveWords), + ValueBitWidth); + CurIdx += ActiveWords; + + if (!isSingleNumber) { + ActiveWords = 1; if (ValueBitWidth > 64) ActiveWords = Record[CurIdx++]; - Low = ReadWideAPInt(makeArrayRef(&Record[CurIdx], ActiveWords), - ValueBitWidth); - CurIdx += ActiveWords; + APInt High = + ReadWideAPInt(makeArrayRef(&Record[CurIdx], ActiveWords), + ValueBitWidth); - if (!isSingleNumber) { - ActiveWords = 1; - if (ValueBitWidth > 64) - ActiveWords = Record[CurIdx++]; - APInt High = - ReadWideAPInt(makeArrayRef(&Record[CurIdx], ActiveWords), - ValueBitWidth); - - CaseBuilder.add(IntItem::fromType(OpTy, Low), - IntItem::fromType(OpTy, High)); - CurIdx += ActiveWords; - } else - CaseBuilder.add(IntItem::fromType(OpTy, Low)); - } - BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]); - IntegersSubset Case = CaseBuilder.getCase(); - SI->addCase(Case, DestBB); + CaseBuilder.add(IntItem::fromType(OpTy, Low), + IntItem::fromType(OpTy, High)); + CurIdx += ActiveWords; + } else + CaseBuilder.add(IntItem::fromType(OpTy, Low)); } - uint16_t Hash = SI->hash(); - if (Hash != (Record[0] & 0xFFFF)) - return Error("Invalid SWITCH record"); - I = SI; - break; + BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]); + IntegersSubset Case = CaseBuilder.getCase(); + SI->addCase(Case, DestBB); } - return Error("Old SwitchInst representation not supported"); + I = SI; + break; } case naclbitc::FUNC_CODE_INST_INDIRECTBR: { // INDIRECTBR: [opty, op0, op1, ...] if (Record.size() < 2) diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp index 7afcf666dc..b41b3c83c6 100644 --- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp +++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp @@ -1252,9 +1252,6 @@ static void WriteInstruction(const Instruction &I, unsigned InstID, Code = naclbitc::FUNC_CODE_INST_SWITCH; const SwitchInst &SI = cast<SwitchInst>(I); - uint32_t SwitchRecordHeader = SI.hash() | (SWITCH_INST_MAGIC << 16); - Vals64.push_back(SwitchRecordHeader); - Vals64.push_back(VE.getTypeID(SI.getCondition()->getType())); pushValue64(SI.getCondition(), InstID, Vals64, VE); Vals64.push_back(VE.getValueID(SI.getDefaultDest())); |