[compiler-rt] r337826 - [profile] Fix finding the first and last directory separators on Windows.

Igor Kudrin via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 24 06:06:20 PDT 2018


Author: ikudrin
Date: Tue Jul 24 06:06:19 2018
New Revision: 337826

URL: http://llvm.org/viewvc/llvm-project?rev=337826&view=rev
Log:
[profile] Fix finding the first and last directory separators on Windows.

Until now, our code preferred backslashes to slashes, whereas Windows
allows using both types of directory separators in one path string.

Differential Revision: https://reviews.llvm.org/D49664

Modified:
    compiler-rt/trunk/lib/profile/InstrProfilingUtil.c

Modified: compiler-rt/trunk/lib/profile/InstrProfilingUtil.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingUtil.c?rev=337826&r1=337825&r2=337826&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingUtil.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingUtil.c Tue Jul 24 06:06:19 2018
@@ -243,23 +243,21 @@ lprofApplyPathPrefix(char *Dest, const c
 
 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 (Sep2 && (!Sep || 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 (Sep2 && (!Sep || Sep2 > Sep))
+    Sep = Sep2;
 #endif
   return Sep;
 }




More information about the llvm-commits mailing list