[clang] 4f8d972 - [clang] Fix an uint32_t overflow in large preamble.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue May 5 01:37:23 PDT 2020


Author: Haojian Wu
Date: 2020-05-05T10:36:34+02:00
New Revision: 4f8d9722b4992272c0e1b33d57fc20bbd93269af

URL: https://github.com/llvm/llvm-project/commit/4f8d9722b4992272c0e1b33d57fc20bbd93269af
DIFF: https://github.com/llvm/llvm-project/commit/4f8d9722b4992272c0e1b33d57fc20bbd93269af.diff

LOG: [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

Added: 
    

Modified: 
    clang/include/clang/Serialization/ASTReader.h
    clang/include/clang/Serialization/ASTRecordReader.h
    clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h
index beaacefbc5c7..aa93c702bed1 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 52de383b0ebf..7248e6fa6c21 100644
--- a/clang/include/clang/Serialization/ASTRecordReader.h
+++ b/clang/include/clang/Serialization/ASTRecordReader.h
@@ -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);
   }
 

diff  --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index b53653852f02..0e92c86e3a84 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;
 }
 


        


More information about the cfe-commits mailing list