Index: include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h |
diff --git a/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h b/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h |
index 39a5009c865ba196a123d3947dfa8c1abf4cf2e0..331c3d181cfaf0886ddbb8ab014a23a4e7350d02 100644 |
--- a/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h |
+++ b/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h |
@@ -431,9 +431,9 @@ public: |
/// Returns a pointer to the abbreviation currently associated with |
/// the abbreviation index. Returns nullptr if no such abbreviation. |
const NaClBitCodeAbbrev *getAbbreviation(unsigned Index) const { |
- if (Index < naclbitc::FIRST_APPLICATION_ABBREV) |
- return nullptr; |
- if (Index >= BlockScope.back().AbbreviationIndexLimit) |
+ if (Index < naclbitc::FIRST_APPLICATION_ABBREV |
+ || BlockScope.empty() |
+ || Index >= BlockScope.back().AbbreviationIndexLimit) |
return nullptr; |
unsigned AbbrevNo = Index - naclbitc::FIRST_APPLICATION_ABBREV; |
if (AbbrevNo >= CurAbbrevs.size()) |
@@ -494,6 +494,7 @@ public: |
/// method takes ownership of the specified abbrev. |
unsigned EmitAbbrev(NaClBitCodeAbbrev *Abbv) { |
assert(Abbv->isValid() && "Can't emit invalid abbreviation!"); |
+ assert(!BlockScope.empty() && "Can't emit abbreviations outside of blocks"); |
// Emit the abbreviation as a record. |
EncodeAbbrev(Abbv); |
CurAbbrevs.push_back(Abbv); |