jansvoboda11 updated this revision to Diff 525691.
jansvoboda11 added a comment.
Make directory non-optional
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151398/new/
https://reviews.llvm.org/D151398
Files:
clang/include/clang/Basic/FileEntry.h
clang/lib/Basic/FileManager.cpp
clang/test/Modules/vfs-umbrella-same-dir.m
clang/unittests/Basic/FileEntryTest.cpp
clang/unittests/Basic/FileManagerTest.cpp
Index: clang/unittests/Basic/FileManagerTest.cpp
===================================================================
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -310,6 +310,26 @@
EXPECT_EQ(&F2->getFileEntry(), &F2Alias2->getFileEntry());
}
+TEST_F(FileManagerTest, getFileRefReturnsCorrectDirNameForDifferentStatPath) {
+ // Inject files with the same inode into distinct directories (name & inode).
+ auto StatCache = std::make_unique<FakeStatCache>();
+ StatCache->InjectDirectory("dir1", 40);
+ StatCache->InjectDirectory("dir2", 41);
+ StatCache->InjectFile("dir1/f.cpp", 42);
+ StatCache->InjectFile("dir2/f.cpp", 42, "dir1/f.cpp");
+
+ manager.setStatCache(std::move(StatCache));
+ auto Dir1F = manager.getFileRef("dir1/f.cpp");
+ auto Dir2F = manager.getFileRef("dir2/f.cpp");
+
+ ASSERT_FALSE(!Dir1F);
+ ASSERT_FALSE(!Dir2F);
+ EXPECT_EQ("dir1", Dir1F->getDir().getName());
+ EXPECT_EQ("dir2", Dir2F->getDir().getName());
+ EXPECT_EQ("dir1/f.cpp", Dir1F->getNameAsRequested());
+ EXPECT_EQ("dir2/f.cpp", Dir2F->getNameAsRequested());
+}
+
// getFile() returns the same FileEntry for virtual files that have
// corresponding real files that are aliases.
TEST_F(FileManagerTest, getFileReturnsSameFileEntryForAliasedVirtualFiles) {
Index: clang/unittests/Basic/FileEntryTest.cpp
===================================================================
--- clang/unittests/Basic/FileEntryTest.cpp
+++ clang/unittests/Basic/FileEntryTest.cpp
@@ -9,6 +9,7 @@
#include "clang/Basic/FileEntry.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/Path.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -51,11 +52,14 @@
.first);
}
FileEntryRef addFileRedirect(StringRef Name, FileEntryRef Base) {
+ auto Dir = addDirectory(llvm::sys::path::parent_path(Name));
+
return FileEntryRef(
*Files
.insert({Name, FileEntryRef::MapValue(
const_cast<FileEntryRef::MapEntry &>(
- Base.getMapEntry()))})
+ Base.getMapEntry()),
+ Dir)})
.first);
}
};
Index: clang/test/Modules/vfs-umbrella-same-dir.m
===================================================================
--- /dev/null
+++ clang/test/Modules/vfs-umbrella-same-dir.m
@@ -0,0 +1,53 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- sources/FW/Private.h
+#include <FW/PrivateUnmapped.h>
+//--- sources/FW/PrivateUnmapped.h
+#include <FW/Public.h>
+//--- sources/FW/Public.h
+#include <FW/PublicPresent.h>
+//--- frameworks/FW.framework/Headers/PublicPresent.h
+// empty
+//--- frameworks/FW.framework/Modules/module.modulemap
+framework module FW { umbrella header "Public.h" }
+//--- frameworks/FW.framework/Modules/module.private.modulemap
+framework module FW_Private { umbrella header "Private.h" }
+//--- vfs.json.in
+{
+ "case-sensitive": "false",
+ "version": 0,
+ "roots": [
+ {
+ "contents": [
+ {
+ "external-contents": "DIR/sources/FW/Public.h",
+ "name": "Public.h",
+ "type": "file"
+ }
+ ],
+ "name": "DIR/frameworks/FW.framework/Headers",
+ "type": "directory"
+ },
+ {
+ "contents": [
+ {
+ "external-contents": "DIR/sources/FW/Private.h",
+ "name": "Private.h",
+ "type": "file"
+ }
+ ],
+ "name": "DIR/frameworks/FW.framework/PrivateHeaders",
+ "type": "directory"
+ }
+ ]
+}
+
+//--- tu.m
+#import <FW/Private.h>
+// expected-no-diagnostics
+
+// RUN: sed -e "s|DIR|%/t|g" %t/vfs.json.in > %t/vfs.json
+
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \
+// RUN: -ivfsoverlay %t/vfs.json -I %t/sources -F %t/frameworks -fsyntax-only %t/tu.m -verify
Index: clang/lib/Basic/FileManager.cpp
===================================================================
--- clang/lib/Basic/FileManager.cpp
+++ clang/lib/Basic/FileManager.cpp
@@ -319,7 +319,7 @@
// Cache the redirection in the previously-inserted entry, still available
// in the tentative return value.
- NamedFileEnt->second = FileEntryRef::MapValue(Redirection);
+ NamedFileEnt->second = FileEntryRef::MapValue(Redirection, DirInfo);
}
FileEntryRef ReturnedRef(*NamedFileEnt);
Index: clang/include/clang/Basic/FileEntry.h
===================================================================
--- clang/include/clang/Basic/FileEntry.h
+++ clang/include/clang/Basic/FileEntry.h
@@ -70,7 +70,7 @@
const FileEntry &getFileEntry() const {
return *getBaseMapEntry().second->V.get<FileEntry *>();
}
- DirectoryEntryRef getDir() const { return *getBaseMapEntry().second->Dir; }
+ DirectoryEntryRef getDir() const { return ME->second->Dir; }
inline off_t getSize() const;
inline unsigned getUID() const;
@@ -120,12 +120,12 @@
/// name that was used to lookup the file.
llvm::PointerUnion<FileEntry *, const MapEntry *> V;
- /// Directory the file was found in. Set if and only if V is a FileEntry.
- OptionalDirectoryEntryRef Dir;
+ /// Directory the file was found in.
+ DirectoryEntryRef Dir;
MapValue() = delete;
MapValue(FileEntry &FE, DirectoryEntryRef Dir) : V(&FE), Dir(Dir) {}
- MapValue(MapEntry &ME) : V(&ME) {}
+ MapValue(MapEntry &ME, DirectoryEntryRef Dir) : V(&ME), Dir(Dir) {}
};
/// Check if RHS referenced the file in exactly the same way.
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits