[llvm] r193172 - Fix llvm-cov counts to be 64-bit integers to avoid overflows.

Bob Wilson bob.wilson at apple.com
Tue Oct 22 10:43:48 PDT 2013


Author: bwilson
Date: Tue Oct 22 12:43:47 2013
New Revision: 193172

URL: http://llvm.org/viewvc/llvm-project?rev=193172&view=rev
Log:
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!

Modified:
    llvm/trunk/include/llvm/Support/GCOV.h
    llvm/trunk/lib/IR/GCOV.cpp

Modified: llvm/trunk/include/llvm/Support/GCOV.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GCOV.h?rev=193172&r1=193171&r2=193172&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/GCOV.h (original)
+++ llvm/trunk/include/llvm/Support/GCOV.h Tue Oct 22 12:43:47 2013
@@ -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<uint32_t, 4> Lines;
 };
 
-typedef SmallVector<uint32_t, 16> LineCounts;
+typedef SmallVector<uint64_t, 16> 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<LineCounts> LineInfo;

Modified: llvm/trunk/lib/IR/GCOV.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/GCOV.cpp?rev=193172&r1=193171&r2=193172&view=diff
==============================================================================
--- llvm/trunk/lib/IR/GCOV.cpp (original)
+++ llvm/trunk/lib/IR/GCOV.cpp Tue Oct 22 12:43:47 2013
@@ -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<uint32_t>::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<MemoryBuffer> Buff;
     if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {





More information about the llvm-commits mailing list