[PATCH] D49664: [profile] Fix finding the first and last directory separators on Windows.

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 23 04:50:14 PDT 2018


ikudrin created this revision.
ikudrin added a reviewer: davidxl.

Windows allows using both types of directory separators in a path string,
but our code preferred backslashes to slashes.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D49664

Files:
  lib/profile/InstrProfilingUtil.c


Index: lib/profile/InstrProfilingUtil.c
===================================================================
--- lib/profile/InstrProfilingUtil.c
+++ lib/profile/InstrProfilingUtil.c
@@ -243,23 +243,21 @@
 
 COMPILER_RT_VISIBILITY const char *
 lprofFindFirstDirSeparator(const char *Path) {
-  const char *Sep;
-  Sep = strchr(Path, DIR_SEPARATOR);
-  if (Sep)
-    return Sep;
+  const char *Sep = strchr(Path, DIR_SEPARATOR);
 #if defined(DIR_SEPARATOR_2)
-  Sep = strchr(Path, DIR_SEPARATOR_2);
+  const char *Sep2 = strchr(Path, DIR_SEPARATOR_2);
+  if (!Sep || (Sep2 && Sep2 < Sep))
+    Sep = Sep2;
 #endif
   return Sep;
 }
 
 COMPILER_RT_VISIBILITY const char *lprofFindLastDirSeparator(const char *Path) {
-  const char *Sep;
-  Sep = strrchr(Path, DIR_SEPARATOR);
-  if (Sep)
-    return Sep;
+  const char *Sep = strrchr(Path, DIR_SEPARATOR);
 #if defined(DIR_SEPARATOR_2)
-  Sep = strrchr(Path, DIR_SEPARATOR_2);
+  const char *Sep2 = strrchr(Path, DIR_SEPARATOR_2);
+  if (!Sep || Sep2 > Sep)
+    Sep = Sep2;
 #endif
   return Sep;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49664.156749.patch
Type: text/x-patch
Size: 1049 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180723/33a110ee/attachment.bin>


More information about the llvm-commits mailing list