Skip to content

Commit

Permalink
[clang] Fix an uint32_t overflow in large preamble.
Browse files Browse the repository at this point in the history
Summary:
I was surprised to see the LocalOffset can exceed uint32_t, but it
does happen and lead to crashes in one of our internal huge TU with a large
preamble.

with this patch, the crash is gone.

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D79397
  • Loading branch information
hokein committed May 5, 2020
1 parent b79751e commit 4f8d972
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Serialization/ASTReader.h
Expand Up @@ -1367,7 +1367,7 @@ class ASTReader
unsigned PreviousGeneration = 0);

RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
uint64_t getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset);

/// Returns the first preprocessed entity ID that begins or ends after
/// \arg Loc.
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/Serialization/ASTRecordReader.h
Expand Up @@ -119,7 +119,7 @@ class ASTRecordReader
//readExceptionSpecInfo(SmallVectorImpl<QualType> &ExceptionStorage);

/// Get the global offset corresponding to a local offset.
uint64_t getGlobalBitOffset(uint32_t LocalOffset) {
uint64_t getGlobalBitOffset(uint64_t LocalOffset) {
return Reader->getGlobalBitOffset(*F, LocalOffset);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Serialization/ASTReaderDecl.cpp
Expand Up @@ -2879,7 +2879,7 @@ ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
}

uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset) {
return LocalOffset + M.GlobalBitOffset;
}

Expand Down

0 comments on commit 4f8d972

Please sign in to comment.