[compiler-rt] r275597 - [Profile] instroduce portability macro for dir separator(s
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 15 11:48:14 PDT 2016
Author: davidxl
Date: Fri Jul 15 13:48:14 2016
New Revision: 275597
URL: http://llvm.org/viewvc/llvm-project?rev=275597&view=rev
Log:
[Profile] instroduce portability macro for dir separator(s
Modified:
compiler-rt/trunk/lib/profile/GCDAProfiling.c
compiler-rt/trunk/lib/profile/InstrProfilingFile.c
compiler-rt/trunk/lib/profile/InstrProfilingPort.h
Modified: compiler-rt/trunk/lib/profile/GCDAProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/GCDAProfiling.c?rev=275597&r1=275596&r2=275597&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/GCDAProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/GCDAProfiling.c Fri Jul 15 13:48:14 2016
@@ -21,6 +21,7 @@
\*===----------------------------------------------------------------------===*/
#include "InstrProfilingUtil.h"
+#include "InstrProfilingPort.h"
#include <errno.h>
#include <fcntl.h>
@@ -194,7 +195,8 @@ static char *mangle_filename(const char
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
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;
Modified: compiler-rt/trunk/lib/profile/InstrProfilingFile.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingFile.c?rev=275597&r1=275596&r2=275597&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingFile.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingFile.c Fri Jul 15 13:48:14 2016
@@ -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);
Modified: compiler-rt/trunk/lib/profile/InstrProfilingPort.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingPort.h?rev=275597&r1=275596&r2=275597&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingPort.h (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingPort.h Fri Jul 15 13:48:14 2016
@@ -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__);
More information about the llvm-commits
mailing list