r297349 - Fix handling of -fmodule-map-file=X where X has no directory component.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 8 16:58:23 PST 2017


Author: rsmith
Date: Wed Mar  8 18:58:22 2017
New Revision: 297349

URL: http://llvm.org/viewvc/llvm-project?rev=297349&view=rev
Log:
Fix handling of -fmodule-map-file=X where X has no directory component.

Added:
    cfe/trunk/test/Modules/module_map_cwd.c
Modified:
    cfe/trunk/lib/Lex/HeaderSearch.cpp

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=297349&r1=297348&r2=297349&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Wed Mar  8 18:58:22 2017
@@ -172,8 +172,10 @@ std::string HeaderSearch::getModuleFileN
     //
     // To avoid false-negatives, we form as canonical a path as we can, and map
     // to lower-case in case we're on a case-insensitive file system.
-   auto *Dir =
-        FileMgr.getDirectory(llvm::sys::path::parent_path(ModuleMapPath));
+    std::string Parent = llvm::sys::path::parent_path(ModuleMapPath);
+    if (Parent.empty())
+      Parent = ".";
+    auto *Dir = FileMgr.getDirectory(Parent);
     if (!Dir)
       return std::string();
     auto DirName = FileMgr.getCanonicalName(Dir);

Added: cfe/trunk/test/Modules/module_map_cwd.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/module_map_cwd.c?rev=297349&view=auto
==============================================================================
--- cfe/trunk/test/Modules/module_map_cwd.c (added)
+++ cfe/trunk/test/Modules/module_map_cwd.c Wed Mar  8 18:58:22 2017
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo 'module X { header "x.h" }' > %t/map
+// RUN: echo 'extern int n;' > %t/x.h
+// RUN: cd %t
+// RUN: %clang_cc1 %s -fmodules -fmodule-map-file=map -fmodules-cache-path=. -verify -I.
+// expected-no-diagnostics
+#include "x.h"
+int *m = &n;




More information about the cfe-commits mailing list