diff options
| author | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2019-07-05 20:22:40 +0000 |
|---|---|---|
| committer | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2019-07-05 20:22:40 +0000 |
| commit | 009225374a410888a4c1ed28549a650c516550f0 (patch) | |
| tree | 9610888fd632ce18969031d8f28f96357ae45dea /clang/lib | |
| parent | 28e0187175ceeadae61d01fcedefa15f97f454f0 (diff) | |
| download | bcm5719-llvm-009225374a410888a4c1ed28549a650c516550f0.tar.gz bcm5719-llvm-009225374a410888a4c1ed28549a650c516550f0.zip | |
Bitstream reader: Fix undefined behavior seen after rL364464
Summary:
After rL364464 the following tests started to fail when
running the clang-doc tests with an ubsan instrumented
build of clang-doc:
Clang Tools :: clang-doc/single-file-public.cpp
Extra Tools Unit Tests :: clang-doc/./ClangDocTests/BitcodeTest.emitEnumInfoBitcode
Extra Tools Unit Tests :: clang-doc/./ClangDocTests/BitcodeTest.emitMethodInfoBitcode
Extra Tools Unit Tests :: clang-doc/./ClangDocTests/BitcodeTest.emitRecordInfoBitcode
Extra Tools Unit Tests :: clang-doc/./ClangDocTests/SerializeTest.emitInfoWithCommentBitcode
We need to check that the read value is in range for being
casted to the llvm::bitc::FixedAbbrevIDs enum, before the
cast in ClangDocBitcodeReader::skipUntilRecordOrBlock.
SerializedDiagnosticReader::skipUntilRecordOrBlock was updated
in the same way.
Reviewers: jfb
Reviewed By: jfb
Subscribers: Bigcheese, vsapsai, bruno, ilya-biryukov, dexonsmith, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64262
llvm-svn: 365239
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Frontend/SerializedDiagnosticReader.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/clang/lib/Frontend/SerializedDiagnosticReader.cpp b/clang/lib/Frontend/SerializedDiagnosticReader.cpp index 045d757adbf..eca6f5ee180 100644 --- a/clang/lib/Frontend/SerializedDiagnosticReader.cpp +++ b/clang/lib/Frontend/SerializedDiagnosticReader.cpp @@ -124,7 +124,12 @@ SerializedDiagnosticReader::skipUntilRecordOrBlock( else return llvm::errorToErrorCode(Res.takeError()); - switch ((llvm::bitc::FixedAbbrevIDs)Code) { + if (Code >= static_cast<unsigned>(llvm::bitc::FIRST_APPLICATION_ABBREV)) { + // We found a record. + BlockOrRecordID = Code; + return Cursor::Record; + } + switch (static_cast<llvm::bitc::FixedAbbrevIDs>(Code)) { case llvm::bitc::ENTER_SUBBLOCK: if (Expected<unsigned> Res = Stream.ReadSubBlockID()) BlockOrRecordID = Res.get(); @@ -145,10 +150,8 @@ SerializedDiagnosticReader::skipUntilRecordOrBlock( 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."); } } |

