<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Sounds like it. Removing the raw profile before running the test binary fixes the issue for me.<div class=""><br class=""></div><div class="">I've gone ahead and tried to fix this in r372041, please let me know if there are any issues.</div><div class=""><br class=""></div><div class="">thanks,</div><div class="">vedant<br class=""><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Sep 16, 2019, at 2:38 PM, Sajjad Mirza via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class="">Maybe the .profraw isn't being cleaned up and so the counts are accumulating in it?</div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 16, 2019, 14:00 Vedant Kumar <<a href="mailto:vedant_kumar@apple.com" class="">vedant_kumar@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class="">The counts seem to keep bumping up when the test is re-run:<div class=""><br class=""></div><div class="">   14|     23|int main(int argc, const char *argv[]) {<br class="">   15|     23|  if (argc < 2)<br class="">   16|      0|    return 1;<br class="">   17|     23|<br class="">   18|     23|  FILE *F = fopen(argv[1], "r+b");<br class="">   19|     23|  if (!F) {<br class="">   20|      0|    // File might not exist, try opening with truncation<br class="">   21|      0|    F = fopen(argv[1], "w+b");<br class="">   22|      0|  }<br class="">   23|     23|  __llvm_profile_set_file_object(F, 1);<br class="">   24|     23|<br class="">   25|     23|  return 0;<br class="">   26|     23|}</div><div class=""><br class=""></div><div class="">vedant<br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Sep 16, 2019, at 1:59 PM, Vedant Kumar <<a href="mailto:vedant_kumar@apple.com" target="_blank" rel="noreferrer" class="">vedant_kumar@apple.com</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word;line-break:after-white-space" class=""><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On Sep 16, 2019, at 1:57 PM, Sajjad Mirza <<a href="mailto:sajjadm@google.com" target="_blank" rel="noreferrer" class="">sajjadm@google.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div class="">Hi Vedant,</div><div class=""><br class=""></div>Can you paste the output of llvm-cov? From the RUN at line 8 line, without piping to FileCheck.</div></div></blockquote><div class=""><br class=""></div><div class="">Ah, sorry for not including this. Here we go:</div><div class=""><br class=""></div><div class="">~/src/builds/llvm-project-master-RA (1) $ ./bin/llvm-cov show -instr-profile /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp.merging.profdata /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp<br class="">    1|       |// Test that the specified output merges the profiling data.<br class="">    2|       |// Run the program twice so that the counters accumulate.<br class="">    3|       |// RUN: %clang -fprofile-instr-generate -fcoverage-mapping -o %t %s<br class="">    4|       |// RUN: %run %t %t.merging.profraw<br class="">    5|       |// RUN: %run %t %t.merging.profraw<br class="">    6|       |// RUN: test -f %t.merging.profraw<br class="">    7|       |// RUN: llvm-profdata merge -o %t.merging.profdata %t.merging.profraw<br class="">    8|       |// RUN: llvm-cov show -instr-profile %t.merging.profdata %t | FileCheck %s --match-full-lines<br class="">    9|       |// RUN: rm %t.merging.profdata %t.merging.profraw<br class="">   10|       |#include <stdio.h><br class="">   11|       |<br class="">   12|       |extern void __llvm_profile_set_file_object(FILE *, int);<br class="">   13|       |<br class="">   14|     21|int main(int argc, const char *argv[]) {<br class="">   15|     21|  if (argc < 2)<br class="">   16|      0|    return 1;<br class="">   17|     21|<br class="">   18|     21|  FILE *F = fopen(argv[1], "r+b");<br class="">   19|     21|  if (!F) {<br class="">   20|      0|    // File might not exist, try opening with truncation<br class="">   21|      0|    F = fopen(argv[1], "w+b");<br class="">   22|      0|  }<br class="">   23|     21|  __llvm_profile_set_file_object(F, 1);<br class="">   24|     21|<br class="">   25|     21|  return 0;<br class="">   26|     21|}<br class="">   27|       |// CHECK:   10|       |#include <stdio.h><br class="">   28|       |// CHECK:   11|       |<br class="">   29|       |// CHECK:   12|       |extern void __llvm_profile_set_file_object(FILE *, int);<br class="">   30|       |// CHECK:   13|       |<br class="">   31|       |// CHECK:   14|      2|int main(int argc, const char *argv[]) {<br class="">   32|       |// CHECK:   15|      2|  if (argc < 2)<br class="">   33|       |// CHECK:   16|      0|    return 1;<br class="">   34|       |// CHECK:   17|      2|<br class="">   35|       |// CHECK:   18|      2|  FILE *F = fopen(argv[1], "r+b");<br class="">   36|       |// CHECK:   19|      2|  if (!F) {<br class="">   37|       |// CHECK:   20|      1|    // File might not exist, try opening with truncation<br class="">   38|       |// CHECK:   21|      1|    F = fopen(argv[1], "w+b");<br class="">   39|       |// CHECK:   22|      1|  }<br class="">   40|       |// CHECK:   23|      2|  __llvm_profile_set_file_object(F, 1);<br class="">   41|       |// CHECK:   24|      2|<br class="">   42|       |// CHECK:   25|      2|  return 0;<br class="">   43|       |// CHECK:   26|      2|}<br class=""><br class=""></div><div class="">vedant</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Sajjad</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 16, 2019 at 12:09 PM Vedant Kumar <<a href="mailto:vedant_kumar@apple.com" target="_blank" rel="noreferrer" class="">vedant_kumar@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Sajjad,<br class="">
<br class="">
I've consistently seen one of the tests added here fail on my Mac:<br class="">
<br class="">
    Profile-x86_64 :: instrprof-set-file-object-merging.c<br class="">
    Profile-x86_64h :: instrprof-set-file-object-merging.c<br class="">
<br class="">
Do you have any ideas as to what might be happening? Here is the output I see:<br class="">
<br class="">
********************<br class="">
FAIL: Profile-x86_64h :: instrprof-set-file-object-merging.c (208 of 234)<br class="">
******************** TEST 'Profile-x86_64h :: instrprof-set-file-object-merging.c' FAILED ********************<br class="">
Script:<br class="">
--<br class="">
: 'RUN: at line 3';      /Users/vsk/src/builds/llvm-project-master-RA/./bin/clang   -arch x86_64h -stdlib=libc++ -mmacosx-version-min=10.9 -isysroot /Applications/OSEng.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk  -fprofile-instr-generate -fcoverage-mapping -o /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp /Users/vsk/src/llvm-project-master/compiler-rt/test/profile/instrprof-set-file-object-merging.c<br class="">
: 'RUN: at line 4';    /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp.merging.profraw<br class="">
: 'RUN: at line 5';    /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp.merging.profraw<br class="">
: 'RUN: at line 6';   test -f /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp.merging.profraw<br class="">
: 'RUN: at line 7';   llvm-profdata merge -o /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp.merging.profdata /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp.merging.profraw<br class="">
: 'RUN: at line 8';   llvm-cov show -instr-profile /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp.merging.profdata /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp | FileCheck /Users/vsk/src/llvm-project-master/compiler-rt/test/profile/instrprof-set-file-object-merging.c --match-full-lines<br class="">
: 'RUN: at line 9';   rm /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp.merging.profdata /Users/vsk/src/builds/llvm-project-master-RA/projects/compiler-rt/test/profile/Profile-x86_64h/Output/instrprof-set-file-object-merging.c.tmp.merging.profraw<br class="">
--<br class="">
Exit Code: 1<br class="">
<br class="">
Command Output (stderr):<br class="">
--<br class="">
/Users/vsk/src/llvm-project-master/compiler-rt/test/profile/instrprof-set-file-object-merging.c:31:11: error: CHECK: expected string not found in input<br class="">
// CHECK: 14| 2|int main(int argc, const char *argv[]) {<br class="">
          ^<br class="">
<stdin>:14:2: note: scanning from here<br class="">
 14| 17|int main(int argc, const char *argv[]) {<br class="">
 ^<br class="">
<stdin>:31:15: note: possible intended match here<br class="">
 31| |// CHECK: 14| 2|int main(int argc, const char *argv[]) {<br class="">
              ^<br class="">
<br class="">
--<br class="">
<br class="">
thanks,<br class="">
vedant<br class="">
<br class="">
> On Jun 24, 2019, at 2:32 PM, Sajjad Mirza via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" rel="noreferrer" class="">llvm-commits@lists.llvm.org</a>> wrote:<br class="">
> <br class="">
> Author: sajjadm<br class="">
> Date: Mon Jun 24 14:32:50 2019<br class="">
> New Revision: 364231<br class="">
> <br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=364231&view=rev" rel="noreferrer noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=364231&view=rev</a><br class="">
> Log:<br class="">
> (Reland with changes) Adding a function for setting coverage output file.<br class="">
> <br class="">
> Summary:<br class="">
> User code can open a file on its own and pass it to the runtime, rather than<br class="">
> specifying a name and having the runtime open the file. This supports the use<br class="">
> case where a process cannot open a file on its own but can receive a file<br class="">
> descriptor from another process.<br class="">
> <br class="">
> Relanding <a href="https://reviews.llvm.org/D62541" rel="noreferrer noreferrer" target="_blank" class="">https://reviews.llvm.org/D62541</a>. The original revision unlocked<br class="">
> the file before calling flush, this revision fixes that.<br class="">
> <br class="">
> Reviewers: Dor1s, davidxl<br class="">
> <br class="">
> Reviewed By: Dor1s<br class="">
> <br class="">
> Subscribers: #sanitizers, llvm-commits<br class="">
> <br class="">
> Tags: #sanitizers, #llvm<br class="">
> <br class="">
> Differential Revision: <a href="https://reviews.llvm.org/D63581" rel="noreferrer noreferrer" target="_blank" class="">https://reviews.llvm.org/D63581</a><br class="">
> <br class="">
> Added:<br class="">
>    compiler-rt/trunk/test/profile/instrprof-set-file-object-merging.c<br class="">
>    compiler-rt/trunk/test/profile/instrprof-set-file-object.c<br class="">
> Modified:<br class="">
>    compiler-rt/trunk/lib/profile/InstrProfiling.h<br class="">
>    compiler-rt/trunk/lib/profile/InstrProfilingFile.c<br class="">
>    compiler-rt/trunk/lib/profile/InstrProfilingUtil.c<br class="">
>    compiler-rt/trunk/lib/profile/InstrProfilingUtil.h<br class="">
> <br class="">
> Modified: compiler-rt/trunk/lib/profile/InstrProfiling.h<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=364231&r1=364230&r2=364231&view=diff" rel="noreferrer noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.h?rev=364231&r1=364230&r2=364231&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- compiler-rt/trunk/lib/profile/InstrProfiling.h (original)<br class="">
> +++ compiler-rt/trunk/lib/profile/InstrProfiling.h Mon Jun 24 14:32:50 2019<br class="">
> @@ -10,6 +10,7 @@<br class="">
> #define PROFILE_INSTRPROFILING_H_<br class="">
> <br class="">
> #include "InstrProfilingPort.h"<br class="">
> +#include <stdio.h><br class="">
> <br class="">
> #define INSTR_PROF_VISIBILITY COMPILER_RT_VISIBILITY<br class="">
> #include "InstrProfData.inc"<br class="">
> @@ -125,7 +126,7 @@ int __llvm_orderfile_write_file(void);<br class="">
> /*!<br class="">
>  * \brief this is a wrapper interface to \c __llvm_profile_write_file.<br class="">
>  * After this interface is invoked, a arleady dumped flag will be set<br class="">
> - * so that profile won't be dumped again during program exit. <br class="">
> + * so that profile won't be dumped again during program exit.<br class="">
>  * Invocation of interface __llvm_profile_reset_counters will clear<br class="">
>  * the flag. This interface is designed to be used to collect profile<br class="">
>  * data from user selected hot regions. The use model is<br class="">
> @@ -157,6 +158,24 @@ int __llvm_orderfile_dump(void);<br class="">
>  */<br class="">
> void __llvm_profile_set_filename(const char *Name);<br class="">
> <br class="">
> +/*!<br class="">
> + * \brief Set the FILE object for writing instrumentation data.<br class="">
> + *<br class="">
> + * Sets the FILE object to be used for subsequent calls to<br class="">
> + * \a __llvm_profile_write_file(). The profile file name set by environment<br class="">
> + * variable, command-line option, or calls to \a  __llvm_profile_set_filename<br class="">
> + * will be ignored.<br class="">
> + *<br class="">
> + * \c File will not be closed after a call to \a __llvm_profile_write_file() but<br class="">
> + * it may be flushed. Passing NULL restores default behavior.<br class="">
> + *<br class="">
> + * If \c EnableMerge is nonzero, the runtime will always merge profiling data<br class="">
> + * with the contents of the profiling file. If EnableMerge is zero, the runtime<br class="">
> + * may still merge the data if it would have merged for another reason (for<br class="">
> + * example, because of a %m specifier in the file name).<br class="">
> + */<br class="">
> +void __llvm_profile_set_file_object(FILE *File, int EnableMerge);<br class="">
> +<br class="">
> /*! \brief Register to write instrumentation data to file at exit. */<br class="">
> int __llvm_profile_register_write_file_atexit(void);<br class="">
> <br class="">
> <br class="">
> Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=364231&r1=364230&r2=364231&view=diff" rel="noreferrer noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=364231&r1=364230&r2=364231&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)<br class="">
> +++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Mon Jun 24 14:32:50 2019<br class="">
> @@ -37,7 +37,7 @@<br class="">
> /* From where is profile name specified.<br class="">
>  * The order the enumerators define their<br class="">
>  * precedence. Re-order them may lead to<br class="">
> - * runtime behavior change. */ <br class="">
> + * runtime behavior change. */<br class="">
> typedef enum ProfileNameSpecifier {<br class="">
>   PNS_unknown = 0,<br class="">
>   PNS_default,<br class="">
> @@ -89,9 +89,27 @@ typedef struct lprofFilename {<br class="">
> COMPILER_RT_WEAK lprofFilename lprofCurFilename = {0,   0, 0, 0, {0},<br class="">
>                                                    {0}, 0, 0, 0, PNS_unknown};<br class="">
> <br class="">
> +static int ProfileMergeRequested = 0;<br class="">
> +static int isProfileMergeRequested() { return ProfileMergeRequested; }<br class="">
> +static void setProfileMergeRequested(int EnableMerge) {<br class="">
> +  ProfileMergeRequested = EnableMerge;<br class="">
> +}<br class="">
> +<br class="">
> +static FILE *ProfileFile = NULL;<br class="">
> +static FILE *getProfileFile() { return ProfileFile; }<br class="">
> +static void setProfileFile(FILE *File) { ProfileFile = File; }<br class="">
> +<br class="">
> +COMPILER_RT_VISIBILITY void __llvm_profile_set_file_object(FILE *File,<br class="">
> +                                                           int EnableMerge) {<br class="">
> +  setProfileFile(File);<br class="">
> +  setProfileMergeRequested(EnableMerge);<br class="">
> +}<br class="">
> +<br class="">
> static int getCurFilenameLength();<br class="">
> static const char *getCurFilename(char *FilenameBuf, int ForceUseBuf);<br class="">
> -static unsigned doMerging() { return lprofCurFilename.MergePoolSize; }<br class="">
> +static unsigned doMerging() {<br class="">
> +  return lprofCurFilename.MergePoolSize || isProfileMergeRequested();<br class="">
> +}<br class="">
> <br class="">
> /* Return 1 if there is an error, otherwise return  0.  */<br class="">
> static uint32_t fileWriter(ProfDataWriter *This, ProfDataIOVec *IOVecs,<br class="">
> @@ -225,11 +243,16 @@ static void createProfileDir(const char<br class="">
>  * its instrumented shared libraries dump profile data into their own data file.<br class="">
> */<br class="">
> static FILE *openFileForMerging(const char *ProfileFileName, int *MergeDone) {<br class="">
> -  FILE *ProfileFile;<br class="">
> +  FILE *ProfileFile = NULL;<br class="">
>   int rc;<br class="">
> <br class="">
> -  createProfileDir(ProfileFileName);<br class="">
> -  ProfileFile = lprofOpenFileEx(ProfileFileName);<br class="">
> +  ProfileFile = getProfileFile();<br class="">
> +  if (ProfileFile) {<br class="">
> +    lprofLockFileHandle(ProfileFile);<br class="">
> +  } else {<br class="">
> +    createProfileDir(ProfileFileName);<br class="">
> +    ProfileFile = lprofOpenFileEx(ProfileFileName);<br class="">
> +  }<br class="">
>   if (!ProfileFile)<br class="">
>     return NULL;<br class="">
> <br class="">
> @@ -244,6 +267,16 @@ static FILE *openFileForMerging(const ch<br class="">
>   return ProfileFile;<br class="">
> }<br class="">
> <br class="">
> +static FILE *getFileObject(const char *OutputName) {<br class="">
> +  FILE *File;<br class="">
> +  File = getProfileFile();<br class="">
> +  if (File != NULL) {<br class="">
> +    return File;<br class="">
> +  }<br class="">
> +<br class="">
> +  return fopen(OutputName, "ab");<br class="">
> +}<br class="">
> +<br class="">
> /* Write profile data to file \c OutputName.  */<br class="">
> static int writeFile(const char *OutputName) {<br class="">
>   int RetVal;<br class="">
> @@ -251,10 +284,10 @@ static int writeFile(const char *OutputN<br class="">
> <br class="">
>   int MergeDone = 0;<br class="">
>   VPMergeHook = &lprofMergeValueProfData;<br class="">
> -  if (!doMerging())<br class="">
> -    OutputFile = fopen(OutputName, "ab");<br class="">
> -  else<br class="">
> +  if (doMerging())<br class="">
>     OutputFile = openFileForMerging(OutputName, &MergeDone);<br class="">
> +  else<br class="">
> +    OutputFile = getFileObject(OutputName);<br class="">
> <br class="">
>   if (!OutputFile)<br class="">
>     return -1;<br class="">
> @@ -265,7 +298,15 @@ static int writeFile(const char *OutputN<br class="">
>   initFileWriter(&fileWriter, OutputFile);<br class="">
>   RetVal = lprofWriteData(&fileWriter, lprofGetVPDataReader(), MergeDone);<br class="">
> <br class="">
> -  fclose(OutputFile);<br class="">
> +  if (OutputFile == getProfileFile()) {<br class="">
> +    fflush(OutputFile);<br class="">
> +    if (doMerging()) {<br class="">
> +      lprofUnlockFileHandle(OutputFile);<br class="">
> +    }<br class="">
> +  } else {<br class="">
> +    fclose(OutputFile);<br class="">
> +  }<br class="">
> +<br class="">
>   return RetVal;<br class="">
> }<br class="">
> <br class="">
> @@ -591,7 +632,7 @@ void __llvm_profile_initialize_file(void<br class="">
> <br class="">
>   EnvFilenamePat = getFilenamePatFromEnv();<br class="">
>   if (EnvFilenamePat) {<br class="">
> -    /* Pass CopyFilenamePat = 1, to ensure that the filename would be valid <br class="">
> +    /* Pass CopyFilenamePat = 1, to ensure that the filename would be valid<br class="">
>        at the  moment when __llvm_profile_write_file() gets executed. */<br class="">
>     parseAndSetFilename(EnvFilenamePat, PNS_environment, 1);<br class="">
>     return;<br class="">
> @@ -627,8 +668,7 @@ int __llvm_profile_write_file(void) {<br class="">
>   int PDeathSig = 0;<br class="">
> <br class="">
>   if (lprofProfileDumped()) {<br class="">
> -    PROF_NOTE("Profile data not written to file: %s.\n", <br class="">
> -              "already written");<br class="">
> +    PROF_NOTE("Profile data not written to file: %s.\n", "already written");<br class="">
>     return 0;<br class="">
>   }<br class="">
> <br class="">
> <br class="">
> Modified: compiler-rt/trunk/lib/profile/InstrProfilingUtil.c<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.c?rev=364231&r1=364230&r2=364231&view=diff" rel="noreferrer noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.c?rev=364231&r1=364230&r2=364231&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- compiler-rt/trunk/lib/profile/InstrProfilingUtil.c (original)<br class="">
> +++ compiler-rt/trunk/lib/profile/InstrProfilingUtil.c Mon Jun 24 14:32:50 2019<br class="">
> @@ -154,6 +154,26 @@ COMPILER_RT_VISIBILITY int lprofUnlockFd<br class="">
> #endif<br class="">
> }<br class="">
> <br class="">
> +COMPILER_RT_VISIBILITY int lprofLockFileHandle(FILE *F) {<br class="">
> +  int fd;<br class="">
> +#if defined(_WIN32)<br class="">
> +  fd = _fileno(F);<br class="">
> +#else<br class="">
> +  fd = fileno(F);<br class="">
> +#endif<br class="">
> +  return lprofLockFd(fd);<br class="">
> +}<br class="">
> +<br class="">
> +COMPILER_RT_VISIBILITY int lprofUnlockFileHandle(FILE *F) {<br class="">
> +  int fd;<br class="">
> +#if defined(_WIN32)<br class="">
> +  fd = _fileno(F);<br class="">
> +#else<br class="">
> +  fd = fileno(F);<br class="">
> +#endif<br class="">
> +  return lprofUnlockFd(fd);<br class="">
> +}<br class="">
> +<br class="">
> COMPILER_RT_VISIBILITY FILE *lprofOpenFileEx(const char *ProfileName) {<br class="">
>   FILE *f;<br class="">
>   int fd;<br class="">
> <br class="">
> Modified: compiler-rt/trunk/lib/profile/InstrProfilingUtil.h<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.h?rev=364231&r1=364230&r2=364231&view=diff" rel="noreferrer noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.h?rev=364231&r1=364230&r2=364231&view=diff</a><br class="">
> ==============================================================================<br class="">
> --- compiler-rt/trunk/lib/profile/InstrProfilingUtil.h (original)<br class="">
> +++ compiler-rt/trunk/lib/profile/InstrProfilingUtil.h Mon Jun 24 14:32:50 2019<br class="">
> @@ -23,6 +23,8 @@ unsigned __llvm_profile_get_dir_mode(voi<br class="">
> <br class="">
> int lprofLockFd(int fd);<br class="">
> int lprofUnlockFd(int fd);<br class="">
> +int lprofLockFileHandle(FILE *F);<br class="">
> +int lprofUnlockFileHandle(FILE *F);<br class="">
> <br class="">
> /*! Open file \c Filename for read+write with write<br class="">
>  * lock for exclusive access. The caller will block<br class="">
> <br class="">
> Added: compiler-rt/trunk/test/profile/instrprof-set-file-object-merging.c<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-set-file-object-merging.c?rev=364231&view=auto" rel="noreferrer noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-set-file-object-merging.c?rev=364231&view=auto</a><br class="">
> ==============================================================================<br class="">
> --- compiler-rt/trunk/test/profile/instrprof-set-file-object-merging.c (added)<br class="">
> +++ compiler-rt/trunk/test/profile/instrprof-set-file-object-merging.c Mon Jun 24 14:32:50 2019<br class="">
> @@ -0,0 +1,43 @@<br class="">
> +// Test that the specified output merges the profiling data.<br class="">
> +// Run the program twice so that the counters accumulate.<br class="">
> +// RUN: %clang -fprofile-instr-generate -fcoverage-mapping -o %t %s<br class="">
> +// RUN: %run %t %t.merging.profraw<br class="">
> +// RUN: %run %t %t.merging.profraw<br class="">
> +// RUN: test -f %t.merging.profraw<br class="">
> +// RUN: llvm-profdata merge -o %t.merging.profdata %t.merging.profraw<br class="">
> +// RUN: llvm-cov show -instr-profile %t.merging.profdata %t | FileCheck %s --match-full-lines<br class="">
> +// RUN: rm %t.merging.profdata %t.merging.profraw<br class="">
> +#include <stdio.h><br class="">
> +<br class="">
> +extern void __llvm_profile_set_file_object(FILE *, int);<br class="">
> +<br class="">
> +int main(int argc, const char *argv[]) {<br class="">
> +  if (argc < 2)<br class="">
> +    return 1;<br class="">
> +<br class="">
> +  FILE *F = fopen(argv[1], "r+b");<br class="">
> +  if (!F) {<br class="">
> +    // File might not exist, try opening with truncation<br class="">
> +    F = fopen(argv[1], "w+b");<br class="">
> +  }<br class="">
> +  __llvm_profile_set_file_object(F, 1);<br class="">
> +<br class="">
> +  return 0;<br class="">
> +}<br class="">
> +// CHECK:   10|       |#include <stdio.h><br class="">
> +// CHECK:   11|       |<br class="">
> +// CHECK:   12|       |extern void __llvm_profile_set_file_object(FILE *, int);<br class="">
> +// CHECK:   13|       |<br class="">
> +// CHECK:   14|      2|int main(int argc, const char *argv[]) {<br class="">
> +// CHECK:   15|      2|  if (argc < 2)<br class="">
> +// CHECK:   16|      0|    return 1;<br class="">
> +// CHECK:   17|      2|<br class="">
> +// CHECK:   18|      2|  FILE *F = fopen(argv[1], "r+b");<br class="">
> +// CHECK:   19|      2|  if (!F) {<br class="">
> +// CHECK:   20|      1|    // File might not exist, try opening with truncation<br class="">
> +// CHECK:   21|      1|    F = fopen(argv[1], "w+b");<br class="">
> +// CHECK:   22|      1|  }<br class="">
> +// CHECK:   23|      2|  __llvm_profile_set_file_object(F, 1);<br class="">
> +// CHECK:   24|      2|<br class="">
> +// CHECK:   25|      2|  return 0;<br class="">
> +// CHECK:   26|      2|}<br class="">
> <br class="">
> Added: compiler-rt/trunk/test/profile/instrprof-set-file-object.c<br class="">
> URL: <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-set-file-object.c?rev=364231&view=auto" rel="noreferrer noreferrer" target="_blank" class="">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/profile/instrprof-set-file-object.c?rev=364231&view=auto</a><br class="">
> ==============================================================================<br class="">
> --- compiler-rt/trunk/test/profile/instrprof-set-file-object.c (added)<br class="">
> +++ compiler-rt/trunk/test/profile/instrprof-set-file-object.c Mon Jun 24 14:32:50 2019<br class="">
> @@ -0,0 +1,31 @@<br class="">
> +// Test that the specified output has profiling data.<br class="">
> +// RUN: %clang -fprofile-instr-generate -fcoverage-mapping -o %t %s<br class="">
> +// RUN: %run %t %t.file.profraw<br class="">
> +// RUN: test -f %t.file.profraw<br class="">
> +// RUN: llvm-profdata merge -o %t.file.profdata %t.file.profraw<br class="">
> +// RUN: llvm-cov show -instr-profile %t.file.profdata %t | FileCheck %s --match-full-lines<br class="">
> +// RUN: rm %t.file.profraw %t.file.profdata<br class="">
> +#include <stdio.h><br class="">
> +<br class="">
> +extern void __llvm_profile_set_file_object(FILE *, int);<br class="">
> +<br class="">
> +int main(int argc, const char *argv[]) {<br class="">
> +  if (argc < 2)<br class="">
> +    return 1;<br class="">
> +<br class="">
> +  FILE *F = fopen(argv[1], "w+b");<br class="">
> +  __llvm_profile_set_file_object(F, 0);<br class="">
> +  return 0;<br class="">
> +}<br class="">
> +// CHECK:    8|       |#include <stdio.h><br class="">
> +// CHECK:    9|       |<br class="">
> +// CHECK:   10|       |extern void __llvm_profile_set_file_object(FILE *, int);<br class="">
> +// CHECK:   11|       |<br class="">
> +// CHECK:   12|      1|int main(int argc, const char *argv[]) {<br class="">
> +// CHECK:   13|      1|  if (argc < 2)<br class="">
> +// CHECK:   14|      0|    return 1;<br class="">
> +// CHECK:   15|      1|<br class="">
> +// CHECK:   16|      1|  FILE *F = fopen(argv[1], "w+b");<br class="">
> +// CHECK:   17|      1|  __llvm_profile_set_file_object(F, 0);<br class="">
> +// CHECK:   18|      1|  return 0;<br class="">
> +// CHECK:   19|      1|}<br class="">
> <br class="">
> <br class="">
> _______________________________________________<br class="">
> llvm-commits mailing list<br class="">
> <a href="mailto:llvm-commits@lists.llvm.org" target="_blank" rel="noreferrer" class="">llvm-commits@lists.llvm.org</a><br class="">
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
<br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></blockquote></div>
_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" class="">llvm-commits@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits<br class=""></div></blockquote></div><br class=""></div></div></body></html>