Author: bruno
Date: Wed Mar 30 18:54:00 2016
New Revision: 264970

URL: http://llvm.org/viewvc/llvm-project?rev=264970&view=rev
Log:
[VFS] Handle empty entries in directory traversal

The VFS YAML files contain empty directory entries to describe that it's
returning from a subdirectory before describing new files in the parent.
In the future, we should properly sort and write YAML files avoiding
such empty dirs and mitigate the extra recurson cost. However, since
this is used by previous existing YAMLs, make the traversal work in
their presence.

rdar://problem/24499339

Added:
    cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread/
    cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread.h
    
cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread/pthread_impl.h
    cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread_impl.h
    cfe/trunk/test/Modules/crash-vfs-path-emptydir-entries.m
Modified:
    cfe/trunk/lib/Basic/VirtualFileSystem.cpp
    cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/module.map

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=264970&r1=264969&r2=264970&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Wed Mar 30 18:54:00 2016
@@ -1358,16 +1358,21 @@ RedirectingFileSystem::lookupPath(sys::p
     ++Start;
 #endif
 
-  if (CaseSensitive ? !Start->equals(From->getName())
-                    : !Start->equals_lower(From->getName()))
-    // failure to match
-    return make_error_code(llvm::errc::no_such_file_or_directory);
+  StringRef FromName = From->getName();
 
-  ++Start;
+  // Forward the search to the next component in case this is an empty one.
+  if (!FromName.empty()) {
+    if (CaseSensitive ? !Start->equals(FromName)
+                      : !Start->equals_lower(FromName))
+      // failure to match
+      return make_error_code(llvm::errc::no_such_file_or_directory);
 
-  if (Start == End) {
-    // Match!
-    return From;
+    ++Start;
+
+    if (Start == End) {
+      // Match!
+      return From;
+    }
   }
 
   auto *DE = dyn_cast<RedirectingDirectoryEntry>(From);

Modified: cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/module.map
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/module.map?rev=264970&r1=264969&r2=264970&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/module.map 
(original)
+++ cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/module.map Wed Mar 
30 18:54:00 2016
@@ -3,4 +3,14 @@ module cstd [system] {
   module stdio {
     header "stdio.h"
   }
+
+  module pthread {
+    header "pthread.h"
+    export *
+
+    module impl {
+      header "pthread_impl.h"
+      export *
+    }
+  }
 }

Added: cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread.h?rev=264970&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread.h (added)
+++ cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread.h Wed Mar 
30 18:54:00 2016
@@ -0,0 +1 @@
+#include "pthread/pthread_impl.h"

Added: 
cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread/pthread_impl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread/pthread_impl.h?rev=264970&view=auto
==============================================================================
--- 
cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread/pthread_impl.h 
(added)
+++ 
cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread/pthread_impl.h 
Wed Mar 30 18:54:00 2016
@@ -0,0 +1 @@
+#define _PTHREAD_MUTEX_SIG_init   0x32AAABA7

Added: cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread_impl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread_impl.h?rev=264970&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread_impl.h 
(added)
+++ cfe/trunk/test/Modules/Inputs/crash-recovery/usr/include/pthread_impl.h Wed 
Mar 30 18:54:00 2016
@@ -0,0 +1 @@
+#define _PTHREAD_MUTEX_SIG_init   0x32AAABA7

Added: cfe/trunk/test/Modules/crash-vfs-path-emptydir-entries.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/crash-vfs-path-emptydir-entries.m?rev=264970&view=auto
==============================================================================
--- cfe/trunk/test/Modules/crash-vfs-path-emptydir-entries.m (added)
+++ cfe/trunk/test/Modules/crash-vfs-path-emptydir-entries.m Wed Mar 30 
18:54:00 2016
@@ -0,0 +1,48 @@
+// REQUIRES: crash-recovery, shell
+
+// FIXME: This XFAIL is cargo-culted from crash-report.c. Do we need it?
+// XFAIL: mingw32
+
+// Test clang can collect symbolic link headers used in modules.
+// crash reproducer if there's a symbolic link header file used in a module.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t/i %t/m %t %t/sysroot
+// RUN: cp -a %S/Inputs/crash-recovery/usr %t/i/
+
+// RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t \
+// RUN: %clang -fsyntax-only %s -I %/t/i -isysroot %/t/sysroot/ \
+// RUN:     -fmodules -fmodules-cache-path=%t/m/ 2>&1 | FileCheck %s
+
+// RUN: FileCheck --check-prefix=CHECKSRC %s -input-file %t/crash-vfs-*.m
+// RUN: FileCheck --check-prefix=CHECKSH %s -input-file %t/crash-vfs-*.sh
+// RUN: FileCheck --check-prefix=CHECKYAML %s -input-file \
+// RUN: %t/crash-vfs-*.cache/vfs/vfs.yaml
+// RUN: find %t/crash-vfs-*.cache/vfs | \
+// RUN:   grep "usr/include/stdio.h" | count 1
+
+#include "usr/include/stdio.h"
+
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK-NEXT: note: diagnostic msg: {{.*}}.m
+// CHECK-NEXT: note: diagnostic msg: {{.*}}.cache
+
+// CHECKSRC: @import cstd.stdio;
+
+// CHECKSH: # Crash reproducer
+// CHECKSH-NEXT: # Driver args: "-fsyntax-only"
+// CHECKSH-NEXT: # Original command: {{.*$}}
+// CHECKSH-NEXT: "-cc1"
+// CHECKSH: "-isysroot" "{{[^"]*}}/sysroot/"
+// CHECKSH-NOT: "-fmodules-cache-path="
+// CHECKSH: "crash-vfs-{{[^ ]*}}.m"
+// CHECKSH: "-ivfsoverlay" "crash-vfs-{{[^ ]*}}.cache/vfs/vfs.yaml"
+
+// CHECKYAML: 'type': 'directory',
+// CHECKYAML: 'name': "",
+// CHECKYAML-NEXT: 'contents': [
+// CHECKYAML-NEXT:   {
+// CHECKYAML-NEXT:     'type': 'file',
+// CHECKYAML-NEXT:     'name': "pthread_impl.h",
+// CHECKYAML-NEXT:     'external-contents': 
"/{{.*}}/i/usr/include/pthread_impl.h"
+// CHECKYAML-NEXT:   },


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to