Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h

Issue 1146203003: Fix abbreviation handling in munged bitcode writer. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Don't allow application of abbreviation if index out of range. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- NaClBitstreamWriter.h - NaCl bitstream writer ------------*- C++ -*-===// 1 //===- NaClBitstreamWriter.h - NaCl bitstream writer ------------*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This header defines the BitstreamWriter class. This class can be used to 10 // This header defines the BitstreamWriter class. This class can be used to
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 assert(RecordIdx < Vals.size() && "Invalid abbrev/record"); 414 assert(RecordIdx < Vals.size() && "Invalid abbrev/record");
415 EmitAbbreviatedField(Op, Vals[RecordIdx]); 415 EmitAbbreviatedField(Op, Vals[RecordIdx]);
416 ++RecordIdx; 416 ++RecordIdx;
417 } 417 }
418 } 418 }
419 assert(RecordIdx == Vals.size() && "Not all record operands emitted!"); 419 assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
420 } 420 }
421 421
422 public: 422 public:
423 423
424 /// Returns true if the given abbreviation index corresponds to a user-defined 424 /// Returns a pointer to the abbreviation currently associated with
425 /// abbreviation. 425 // the abbreviation index. Returns nullptr if no such abbreviation
jvoung (off chromium) 2015/05/20 22:40:09 slash consistency /// vs // period
Karl 2015/05/21 18:22:07 Done.
426 bool isUserRecordAbbreviation(unsigned Abbrev) const { 426 const NaClBitCodeAbbrev *getAbbreviation(unsigned Index) const {
427 return Abbrev >= naclbitc::FIRST_APPLICATION_ABBREV 427 if (Index < naclbitc::FIRST_APPLICATION_ABBREV)
428 && Abbrev < (CurAbbrevs.size() + naclbitc::FIRST_APPLICATION_ABBREV); 428 return nullptr;
429 unsigned AbbrevNo = Index - naclbitc::FIRST_APPLICATION_ABBREV;
430 if (AbbrevNo >= CurAbbrevs.size())
431 return nullptr;
432 return CurAbbrevs[AbbrevNo];
433 }
434
435 size_t getCurNumAbbreviations() const {
jvoung (off chromium) 2015/05/20 22:40:09 unused method ?
Karl 2015/05/21 18:22:07 Removed.
436 return CurAbbrevs.size();
429 } 437 }
430 438
431 /// EmitRecord - Emit the specified record to the stream, using an abbrev if 439 /// EmitRecord - Emit the specified record to the stream, using an abbrev if
432 /// we have one to compress the output. 440 /// we have one to compress the output.
433 template<typename uintty> 441 template<typename uintty>
434 void EmitRecord(unsigned Code, const SmallVectorImpl<uintty> &Vals, 442 void EmitRecord(unsigned Code, const SmallVectorImpl<uintty> &Vals,
435 unsigned Abbrev = 0) { 443 unsigned Abbrev = 0) {
436 if (!Abbrev) { 444 if (!Abbrev) {
437 // If we don't have an abbrev to use, emit this in its fully unabbreviated 445 // If we don't have an abbrev to use, emit this in its fully unabbreviated
438 // form. 446 // form.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 Info.Abbrevs.push_back(Abbv); 539 Info.Abbrevs.push_back(Abbv);
532 540
533 return Info.Abbrevs.size()-1+naclbitc::FIRST_APPLICATION_ABBREV; 541 return Info.Abbrevs.size()-1+naclbitc::FIRST_APPLICATION_ABBREV;
534 } 542 }
535 }; 543 };
536 544
537 545
538 } // End llvm namespace 546 } // End llvm namespace
539 547
540 #endif 548 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698