diff --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp b/clang-tools-extra/clang-doc/BitcodeReader.cpp --- a/clang-tools-extra/clang-doc/BitcodeReader.cpp +++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp @@ -615,10 +615,12 @@ return Cursor::BadBlock; } - // FIXME check that the enum is in range. - auto Code = static_cast(MaybeCode.get()); - - switch (Code) { + unsigned Code = MaybeCode.get(); + if (Code >= static_cast(llvm::bitc::FIRST_APPLICATION_ABBREV)) { + BlockOrRecordID = Code; + return Cursor::Record; + } + switch (static_cast(Code)) { case llvm::bitc::ENTER_SUBBLOCK: if (Expected MaybeID = Stream.ReadSubBlockID()) BlockOrRecordID = MaybeID.get(); @@ -639,9 +641,8 @@ continue; case llvm::bitc::UNABBREV_RECORD: return Cursor::BadBlock; - default: - BlockOrRecordID = Code; - return Cursor::Record; + case llvm::bitc::FIRST_APPLICATION_ABBREV: + llvm_unreachable("Unexpected abbrev id."); } } llvm_unreachable("Premature stream end."); diff --git a/clang/lib/Frontend/SerializedDiagnosticReader.cpp b/clang/lib/Frontend/SerializedDiagnosticReader.cpp --- a/clang/lib/Frontend/SerializedDiagnosticReader.cpp +++ b/clang/lib/Frontend/SerializedDiagnosticReader.cpp @@ -124,7 +124,12 @@ else return llvm::errorToErrorCode(Res.takeError()); - switch ((llvm::bitc::FixedAbbrevIDs)Code) { + if (Code >= static_cast(llvm::bitc::FIRST_APPLICATION_ABBREV)) { + // We found a record. + BlockOrRecordID = Code; + return Cursor::Record; + } + switch (static_cast(Code)) { case llvm::bitc::ENTER_SUBBLOCK: if (Expected Res = Stream.ReadSubBlockID()) BlockOrRecordID = Res.get(); @@ -145,10 +150,8 @@ case llvm::bitc::UNABBREV_RECORD: return SDError::UnsupportedConstruct; - default: - // We found a record. - BlockOrRecordID = Code; - return Cursor::Record; + case llvm::bitc::FIRST_APPLICATION_ABBREV: + llvm_unreachable("Unexpected abbrev id."); } }