[PATCH] D69137: [profile] Do not cache __llvm_profile_get_filename result

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 15:06:54 PDT 2019


vsk updated this revision to Diff 225535.
vsk added a comment.

The test was not written clearly. I've added a clarifying comment. The test should exit with code 1 if the two filenames compare equal.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69137/new/

https://reviews.llvm.org/D69137

Files:
  compiler-rt/lib/profile/InstrProfilingFile.c
  compiler-rt/test/profile/Inputs/instrprof-get-filename-dso.c
  compiler-rt/test/profile/instrprof-get-filename-merge-mode.c


Index: compiler-rt/test/profile/instrprof-get-filename-merge-mode.c
===================================================================
--- /dev/null
+++ compiler-rt/test/profile/instrprof-get-filename-merge-mode.c
@@ -0,0 +1,18 @@
+// Test __llvm_profile_get_filename when the on-line merging mode is enabled.
+//
+// RUN: %clang_pgogen -dynamiclib -o %t.dso %p/Inputs/instrprof-get-filename-dso.c
+// RUN: %clang_pgogen -o %t %s %t.dso
+// RUN: env LLVM_PROFILE_FILE="%t-%m.profraw" %run %t
+
+#include <string.h>
+
+const char *__llvm_profile_get_filename(void);
+extern const char *get_filename_from_DSO(void);
+
+int main(int argc, const char *argv[]) {
+  const char *filename1 = __llvm_profile_get_filename();
+  const char *filename2 = get_filename_from_DSO();
+
+  // Exit with code 1 if the two filenames are the same.
+  return strcmp(filename1, filename2) == 0;
+}
Index: compiler-rt/test/profile/Inputs/instrprof-get-filename-dso.c
===================================================================
--- /dev/null
+++ compiler-rt/test/profile/Inputs/instrprof-get-filename-dso.c
@@ -0,0 +1,5 @@
+const char *__llvm_profile_get_filename(void);
+
+const char *get_filename_from_DSO(void) {
+  return __llvm_profile_get_filename();
+}
Index: compiler-rt/lib/profile/InstrProfilingFile.c
===================================================================
--- compiler-rt/lib/profile/InstrProfilingFile.c
+++ compiler-rt/lib/profile/InstrProfilingFile.c
@@ -70,7 +70,6 @@
    * by runtime. */
   unsigned OwnsFilenamePat;
   const char *ProfilePathPrefix;
-  const char *Filename;
   char PidChars[MAX_PID_SIZE];
   char Hostname[COMPILER_RT_MAX_HOSTLEN];
   unsigned NumPids;
@@ -86,7 +85,7 @@
   ProfileNameSpecifier PNS;
 } lprofFilename;
 
-COMPILER_RT_WEAK lprofFilename lprofCurFilename = {0,   0, 0, 0, {0},
+COMPILER_RT_WEAK lprofFilename lprofCurFilename = {0,   0, 0, {0},
                                                    {0}, 0, 0, 0, PNS_unknown};
 
 static int ProfileMergeRequested = 0;
@@ -387,8 +386,6 @@
   /* Clean up cached prefix and filename.  */
   if (lprofCurFilename.ProfilePathPrefix)
     free((void *)lprofCurFilename.ProfilePathPrefix);
-  if (lprofCurFilename.Filename)
-    free((void *)lprofCurFilename.Filename);
 
   if (lprofCurFilename.FilenamePat && lprofCurFilename.OwnsFilenamePat) {
     free((void *)lprofCurFilename.FilenamePat);
@@ -602,9 +599,6 @@
   char *FilenameBuf;
   const char *Filename;
 
-  if (lprofCurFilename.Filename)
-    return lprofCurFilename.Filename;
-
   Length = getCurFilenameLength();
   FilenameBuf = (char *)malloc(Length + 1);
   if (!FilenameBuf) {
@@ -615,7 +609,6 @@
   if (!Filename)
     return "\0";
 
-  lprofCurFilename.Filename = FilenameBuf;
   return FilenameBuf;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69137.225535.patch
Type: text/x-patch
Size: 2762 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191017/b5c3a264/attachment.bin>


More information about the llvm-commits mailing list