From 68bf30a8b42ab56cf2ba54de2caf4bfcabea039d Mon Sep 17 00:00:00 2001 From: Bob Wilson Date: Tue, 22 Oct 2013 17:43:47 +0000 Subject: [PATCH] Fix llvm-cov counts to be 64-bit integers to avoid overflows. Line counts in llvm-cov are read in as 64-bit integers but were being truncated to 32-bit in collectLineCounts(), which caused overflow for large counts. This patch fixes all counts to be uint64_t. Patch by Yuchen Wu! llvm-svn: 193172 --- llvm/include/llvm/Support/GCOV.h | 6 +++--- llvm/lib/IR/GCOV.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/Support/GCOV.h b/llvm/include/llvm/Support/GCOV.h index 67d637021a23..aa436fbea973 100644 --- a/llvm/include/llvm/Support/GCOV.h +++ b/llvm/include/llvm/Support/GCOV.h @@ -205,17 +205,17 @@ class GCOVLines { public: ~GCOVLines() { Lines.clear(); } void add(uint32_t N) { Lines.push_back(N); } - void collectLineCounts(FileInfo &FI, StringRef Filename, uint32_t Count); + void collectLineCounts(FileInfo &FI, StringRef Filename, uint64_t Count); void dump(); private: SmallVector Lines; }; -typedef SmallVector LineCounts; +typedef SmallVector LineCounts; class FileInfo { public: - void addLineCount(StringRef Filename, uint32_t Line, uint32_t Count); + void addLineCount(StringRef Filename, uint32_t Line, uint64_t Count); void print(StringRef gcnoFile, StringRef gcdaFile); private: StringMap LineInfo; diff --git a/llvm/lib/IR/GCOV.cpp b/llvm/lib/IR/GCOV.cpp index 36c5390bbdbd..8a3fb47bf17a 100644 --- a/llvm/lib/IR/GCOV.cpp +++ b/llvm/lib/IR/GCOV.cpp @@ -219,7 +219,7 @@ void GCOVBlock::dump() { /// collectLineCounts - Collect line counts. This must be used after /// reading .gcno and .gcda files. void GCOVLines::collectLineCounts(FileInfo &FI, StringRef Filename, - uint32_t Count) { + uint64_t Count) { for (SmallVectorImpl::iterator I = Lines.begin(), E = Lines.end(); I != E; ++I) FI.addLineCount(Filename, *I, Count); @@ -236,7 +236,7 @@ void GCOVLines::dump() { // FileInfo implementation. /// addLineCount - Add line count for the given line number in a file. -void FileInfo::addLineCount(StringRef Filename, uint32_t Line, uint32_t Count) { +void FileInfo::addLineCount(StringRef Filename, uint32_t Line, uint64_t Count) { if (LineInfo.find(Filename) == LineInfo.end()) { OwningPtr Buff; if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {