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; } 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/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 + +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; +}