From 4f8d9722b4992272c0e1b33d57fc20bbd93269af Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Tue, 5 May 2020 09:26:12 +0200 Subject: [PATCH] [clang] Fix an uint32_t overflow in large preamble. 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 --- clang/include/clang/Serialization/ASTReader.h | 2 +- clang/include/clang/Serialization/ASTRecordReader.h | 2 +- clang/lib/Serialization/ASTReaderDecl.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index beaacefbc5c7b..aa93c702bed1a 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -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. diff --git a/clang/include/clang/Serialization/ASTRecordReader.h b/clang/include/clang/Serialization/ASTRecordReader.h index 52de383b0ebfc..7248e6fa6c21d 100644 --- a/clang/include/clang/Serialization/ASTRecordReader.h +++ b/clang/include/clang/Serialization/ASTRecordReader.h @@ -119,7 +119,7 @@ class ASTRecordReader //readExceptionSpecInfo(SmallVectorImpl &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); } diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index b53653852f02a..0e92c86e3a844 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -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; }