[llvm] r196358 - llvm-cov: Added support for function checksums.

Yuchen Wu yuchenericwu at hotmail.com
Wed Dec 4 00:38:46 PST 2013


Lang,

No problem. The fix is to check for Funcs.size() like it does with FileChecksums a few lines above it, and default to 0 in the cases where insertCounterWriteout() is called before emitProfileNotes().

Unfortunately I didn't have the llvm source properly checked out on my home machine, so it's taking forever to build + verify (the fact that I'm running on a VM doesn't help either).

I apologize for the inconvenience and will submit a proper fix when I'm back in the office tomorrow.

Thanks,
Yuchen

Date: Wed, 4 Dec 2013 09:29:48 +0100
Subject: Re: [llvm] r196358 - llvm-cov: Added support for function checksums.
From: djasper at google.com
To: lhames at gmail.com
CC: yuchenericwu at hotmail.com; llvm-commits at cs.uiuc.edu




On Wed, Dec 4, 2013 at 8:15 AM, Lang Hames <lhames at gmail.com> wrote:


Hi Yuchen,
This seems to have broken the clang/test/CodeGen/code-coverage.c test. Could you please take a look at it and fix or revert the patch?


Thanks very much!

Cheers,Lang.


On Tue, Dec 3, 2013 at 10:00 PM, Yuchen Wu <yuchenericwu at hotmail.com> wrote:



Author: ywu

Date: Wed Dec  4 00:00:17 2013

New Revision: 196358



URL: http://llvm.org/viewvc/llvm-project?rev=196358&view=rev

Log:

llvm-cov: Added support for function checksums.



The function checksums are hashed from the concatenation of the function

name and line number.



Added:

    llvm/trunk/test/tools/llvm-cov/Inputs/test_file_checksum_fail.gcda

    llvm/trunk/test/tools/llvm-cov/Inputs/test_func_checksum_fail.gcda

Removed:

    llvm/trunk/test/tools/llvm-cov/Inputs/test_checksum_mismatch.gcda

Modified:

    llvm/trunk/include/llvm/Support/GCOV.h

    llvm/trunk/lib/IR/GCOV.cpp

    llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp

    llvm/trunk/test/tools/llvm-cov/Inputs/test.gcda

    llvm/trunk/test/tools/llvm-cov/Inputs/test.gcno

    llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno

    llvm/trunk/test/tools/llvm-cov/llvm-cov.test



Modified: llvm/trunk/include/llvm/Support/GCOV.h

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/GCOV.h?rev=196358&r1=196357&r2=196358&view=diff




==============================================================================

--- llvm/trunk/include/llvm/Support/GCOV.h (original)

+++ llvm/trunk/include/llvm/Support/GCOV.h Wed Dec  4 00:00:17 2013

@@ -250,6 +250,7 @@ public:

 private:

   GCOVFile &Parent;

   uint32_t Ident;

+  uint32_t Checksum;

   uint32_t LineNumber;

   StringRef Name;

   StringRef Filename;



Modified: llvm/trunk/lib/IR/GCOV.cpp

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/GCOV.cpp?rev=196358&r1=196357&r2=196358&view=diff




==============================================================================

--- llvm/trunk/lib/IR/GCOV.cpp (original)

+++ llvm/trunk/lib/IR/GCOV.cpp Wed Dec  4 00:00:17 2013

@@ -125,7 +125,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &

   uint32_t Dummy;

   if (!Buff.readInt(Dummy)) return false; // Function header length

   if (!Buff.readInt(Ident)) return false;

-  if (!Buff.readInt(Dummy)) return false; // Checksum #1

+  if (!Buff.readInt(Checksum)) return false;

   if (Version != GCOV::V402) {

     uint32_t CfgChecksum;

     if (!Buff.readInt(CfgChecksum)) return false;

@@ -212,6 +212,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &

 bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {

   uint32_t Dummy;

   if (!Buff.readInt(Dummy)) return false; // Function header length

+

   uint32_t GCDAIdent;

   if (!Buff.readInt(GCDAIdent)) return false;

   if (Ident != GCDAIdent) {

@@ -220,8 +221,13 @@ bool GCOVFunction::readGCDA(GCOVBuffer &

     return false;

   }



-  if (!Buff.readInt(Dummy)) return false; // Checksum #1

-

+  uint32_t GCDAChecksum;

+  if (!Buff.readInt(GCDAChecksum)) return false;

+  if (Checksum != GCDAChecksum) {

+    errs() << "Function checksums do not match: " << Checksum << " != "

+           << GCDAChecksum << " (in " << Name << ").\n";

+    return false;

+  }



   uint32_t CfgChecksum;

   if (Version != GCOV::V402) {



Modified: llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp?rev=196358&r1=196357&r2=196358&view=diff




==============================================================================

--- llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp (original)

+++ llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp Wed Dec  4 00:00:17 2013

@@ -314,12 +314,18 @@ namespace {

       this->os = os;



       Function *F = SP.getFunction();

-      DEBUG(dbgs() << "Function: " << F->getName() << "\n");

+      DEBUG(dbgs() << "Function: " << getFunctionName(SP) << "\n");

       uint32_t i = 0;

       for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {

         Blocks[BB] = new GCOVBlock(i++, os);

       }

       ReturnBlock = new GCOVBlock(i++, os);

+

+      std::string FunctionNameAndLine;

+      raw_string_ostream FNLOS(FunctionNameAndLine);

+      FNLOS << getFunctionName(SP) << SP.getLineNumber();

+      FNLOS.flush();

+      FuncChecksum = hash_value(FunctionNameAndLine);

     }



     ~GCOVFunction() {

@@ -347,6 +353,10 @@ namespace {

       return EdgeDestinations;

     }



+    uint32_t getFuncChecksum() {

+      return FuncChecksum;

+    }

+

     void setCfgChecksum(uint32_t Checksum) {

       CfgChecksum = Checksum;

     }

@@ -359,7 +369,7 @@ namespace {

         ++BlockLen;

       write(BlockLen);

       write(Ident);

-      write(0);  // lineno checksum

+      write(FuncChecksum);

       if (UseCfgChecksum)

         write(CfgChecksum);

       writeGCOVString(getFunctionName(SP));

@@ -401,6 +411,7 @@ namespace {

    private:

     DISubprogram SP;

     uint32_t Ident;

+    uint32_t FuncChecksum;

     bool UseCfgChecksum;

     uint32_t CfgChecksum;

     DenseMap<BasicBlock *, GCOVBlock *> Blocks;

@@ -731,6 +742,7 @@ Constant *GCOVProfiler::getEmitFunctionF

   Type *Args[] = {

     Type::getInt32Ty(*Ctx),    // uint32_t ident

     Type::getInt8PtrTy(*Ctx),  // const char *function_name

+    Type::getInt32Ty(*Ctx),    // uint32_t func_checksum

     Type::getInt8Ty(*Ctx),     // uint8_t use_extra_checksum

     Type::getInt32Ty(*Ctx),    // uint32_t cfg_checksum

   };

@@ -813,11 +825,12 @@ Function *GCOVProfiler::insertCounterWri

                           Builder.getInt32(CfgChecksum));

       for (unsigned j = 0, e = CountersBySP.size(); j != e; ++j) {

         DISubprogram SP(CountersBySP[j].second);

-        Builder.CreateCall4(

+        Builder.CreateCall5(

             EmitFunction, Builder.getInt32(j),

             Options.FunctionNamesInData ?

               Builder.CreateGlobalStringPtr(getFunctionName(SP)) :

               Constant::getNullValue(Builder.getInt8PtrTy()),

+            Builder.getInt32(Funcs[j]->getFuncChecksum()),

The problem is that Funcs[j] is out of bounds (j is zero, but Funcs is empty). However, I don't know how to fix this so I have rolled it back in r196365. Sorry if this causes extra trouble.


Cheers,Daniel 




             Builder.getInt8(Options.UseCfgChecksum),

             Builder.getInt32(CfgChecksum));





Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test.gcda

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test.gcda?rev=196358&r1=196357&r2=196358&view=diff




==============================================================================

Binary files llvm/trunk/test/tools/llvm-cov/Inputs/test.gcda (original) and llvm/trunk/test/tools/llvm-cov/Inputs/test.gcda Wed Dec  4 00:00:17 2013 differ



Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test.gcno

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test.gcno?rev=196358&r1=196357&r2=196358&view=diff




==============================================================================

Binary files llvm/trunk/test/tools/llvm-cov/Inputs/test.gcno (original) and llvm/trunk/test/tools/llvm-cov/Inputs/test.gcno Wed Dec  4 00:00:17 2013 differ



Removed: llvm/trunk/test/tools/llvm-cov/Inputs/test_checksum_mismatch.gcda

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_checksum_mismatch.gcda?rev=196357&view=auto




==============================================================================

Binary files llvm/trunk/test/tools/llvm-cov/Inputs/test_checksum_mismatch.gcda (original) and llvm/trunk/test/tools/llvm-cov/Inputs/test_checksum_mismatch.gcda (removed) differ



Added: llvm/trunk/test/tools/llvm-cov/Inputs/test_file_checksum_fail.gcda

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_file_checksum_fail.gcda?rev=196358&view=auto




==============================================================================

Binary files llvm/trunk/test/tools/llvm-cov/Inputs/test_file_checksum_fail.gcda (added) and llvm/trunk/test/tools/llvm-cov/Inputs/test_file_checksum_fail.gcda Wed Dec  4 00:00:17 2013 differ



Added: llvm/trunk/test/tools/llvm-cov/Inputs/test_func_checksum_fail.gcda

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_func_checksum_fail.gcda?rev=196358&view=auto




==============================================================================

Binary files llvm/trunk/test/tools/llvm-cov/Inputs/test_func_checksum_fail.gcda (added) and llvm/trunk/test/tools/llvm-cov/Inputs/test_func_checksum_fail.gcda Wed Dec  4 00:00:17 2013 differ



Modified: llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno?rev=196358&r1=196357&r2=196358&view=diff




==============================================================================

Binary files llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno (original) and llvm/trunk/test/tools/llvm-cov/Inputs/test_read_fail.gcno Wed Dec  4 00:00:17 2013 differ



Modified: llvm/trunk/test/tools/llvm-cov/llvm-cov.test

URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/llvm-cov.test?rev=196358&r1=196357&r2=196358&view=diff




==============================================================================

--- llvm/trunk/test/tools/llvm-cov/llvm-cov.test (original)

+++ llvm/trunk/test/tools/llvm-cov/llvm-cov.test Wed Dec  4 00:00:17 2013

@@ -11,6 +11,8 @@ RUN: rm test.cpp.llcov



 RUN: not llvm-cov -gcno=test_read_fail.gcno -gcda=test.gcda



-RUN: not llvm-cov -gcno=test.gcno -gcda=test_checksum_mismatch.gcda

+RUN: not llvm-cov -gcno=test.gcno -gcda=test_file_checksum_fail.gcda

+

+RUN: not llvm-cov -gcno=test.gcno -gcda=test_func_checksum_fail.gcda



 XFAIL: powerpc64, s390x, mips





_______________________________________________

llvm-commits mailing list

llvm-commits at cs.uiuc.edu

http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




_______________________________________________

llvm-commits mailing list

llvm-commits at cs.uiuc.edu

http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131204/a063150f/attachment.html>


More information about the llvm-commits mailing list