From 4222836303a1b25cac081dc7a0938104982e5c1e Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 9 Mar 2017 00:58:22 +0000 Subject: [PATCH] Fix handling of -fmodule-map-file=X where X has no directory component. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297349 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/HeaderSearch.cpp | 6 ++++-- test/Modules/module_map_cwd.c | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/Modules/module_map_cwd.c diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index c667f4bf22..4ee3871928 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -172,8 +172,10 @@ std::string HeaderSearch::getModuleFileName(StringRef ModuleName, // // 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); diff --git a/test/Modules/module_map_cwd.c b/test/Modules/module_map_cwd.c new file mode 100644 index 0000000000..d76734adee --- /dev/null +++ b/test/Modules/module_map_cwd.c @@ -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; -- 2.40.0