[PathV2]: Fix bug in create_directories which caused infinite recursion on
authorMichael J. Spencer <bigcheesegs@gmail.com>
Wed, 21 Mar 2012 23:09:14 +0000 (23:09 +0000)
committerMichael J. Spencer <bigcheesegs@gmail.com>
Wed, 21 Mar 2012 23:09:14 +0000 (23:09 +0000)
som inputs.

Bug found and fix proposed by Kal Conley!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153225 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/PathV2.cpp

index 786e1a12c30dc6b7ac4ea239dc852982bb3c1b36..e2a69a650db8ca12cb8eb94ed8a4816e83b566b0 100644 (file)
@@ -654,12 +654,13 @@ error_code create_directories(const Twine &path, bool &existed) {
   StringRef p = path.toStringRef(path_storage);
 
   StringRef parent = path::parent_path(p);
-  bool parent_exists;
+  if (!parent.empty()) {
+    bool parent_exists;
+    if (error_code ec = fs::exists(parent, parent_exists)) return ec;
 
-  if (error_code ec = fs::exists(parent, parent_exists)) return ec;
-
-  if (!parent_exists)
-    if (error_code ec = create_directories(parent, existed)) return ec;
+    if (!parent_exists)
+      if (error_code ec = create_directories(parent, existed)) return ec;
+  }
 
   return create_directory(p, existed);
 }