diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c index 1079f242406a..51a40c5b67d3 100644 --- a/compiler-rt/lib/profile/GCDAProfiling.c +++ b/compiler-rt/lib/profile/GCDAProfiling.c @@ -21,6 +21,7 @@ \*===----------------------------------------------------------------------===*/ #include "InstrProfilingUtil.h" +#include "InstrProfilingPort.h" #include #include @@ -194,7 +195,8 @@ static char *mangle_filename(const char *orig_filename) { for (level = 0, ptr = fname + 1; level < prefix_strip; ++ptr) { if (*ptr == '\0') break; - if (*ptr != '/') + + if (!IS_DIR_SEPARATOR(*ptr)) continue; fname = ptr; ++level; @@ -205,8 +207,8 @@ static char *mangle_filename(const char *orig_filename) { new_filename = malloc(prefix_len + 1 + filename_len + 1); memcpy(new_filename, prefix, prefix_len); - if (prefix[prefix_len - 1] != '/') - new_filename[prefix_len++] = '/'; + if (!IS_DIR_SEPARATOR(prefix[prefix_len - 1])) + new_filename[prefix_len++] = DIR_SEPARATOR; memcpy(new_filename + prefix_len, fname, filename_len + 1); return new_filename; diff --git a/compiler-rt/lib/profile/InstrProfilingFile.c b/compiler-rt/lib/profile/InstrProfilingFile.c index 1bd6c63395c4..b737baff405b 100644 --- a/compiler-rt/lib/profile/InstrProfilingFile.c +++ b/compiler-rt/lib/profile/InstrProfilingFile.c @@ -229,7 +229,11 @@ static void truncateCurrentFile(void) { return; /* Create the directory holding the file, if needed. */ - if (strchr(Filename, '/') || strchr(Filename, '\\')) { + if (strchr(Filename, DIR_SEPARATOR) +#if defined(DIR_SEPARATOR_2) + || strchr(Filename, DIR_SEPERATOR_2) +#endif + ) { char *Copy = (char *)COMPILER_RT_ALLOCA(Length + 1); strncpy(Copy, Filename, Length + 1); __llvm_profile_recursive_mkdir(Copy); diff --git a/compiler-rt/lib/profile/InstrProfilingPort.h b/compiler-rt/lib/profile/InstrProfilingPort.h index 4fd8aca4a9da..c947153e2517 100644 --- a/compiler-rt/lib/profile/InstrProfilingPort.h +++ b/compiler-rt/lib/profile/InstrProfilingPort.h @@ -84,6 +84,20 @@ (DomType *)lprofPtrFetchAdd((void **)&PtrVar, sizeof(DomType) * PtrIncr) #endif +#if defined(_WIN32) +#define DIR_SEPARATOR '\\' +#define DIR_SEPARATOR_2 '/' +#else +#define DIR_SEPARATOR '/' +#endif + +#ifndef DIR_SEPARATOR_2 +#define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR) +#else /* DIR_SEPARATOR_2 */ +#define IS_DIR_SEPARATOR(ch) \ + (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2)) +#endif /* DIR_SEPARATOR_2 */ + #define PROF_ERR(Format, ...) \ fprintf(stderr, "LLVM Profile Error: " Format, __VA_ARGS__);