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