aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/libclang/LibclangTest.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2018-04-07 20:50:35 +0000
committerFangrui Song <maskray@google.com>2018-04-07 20:50:35 +0000
commite46ac5fb9dcbfd805bf1181dc6babcae0a5c9210 (patch)
tree9214254a04e853613f4bf949b44a47337a0710f3 /clang/unittests/libclang/LibclangTest.cpp
parent6b6552367135e09806190187a5551e8bc9e621b0 (diff)
downloadllvm-e46ac5fb9dcbfd805bf1181dc6babcae0a5c9210.zip
llvm-e46ac5fb9dcbfd805bf1181dc6babcae0a5c9210.tar.gz
llvm-e46ac5fb9dcbfd805bf1181dc6babcae0a5c9210.tar.bz2
[libclang] Add clang_File_tryGetRealPathName
Summary: clang_getFileName() may return a path relative to WorkingDir. On Arch Linux, during clang_indexTranslationUnit(), clang_getFileName() on CXIdxIncludedIncludedFileInfo::file may return "/../lib64/gcc/x86_64-pc-linux-gnu/7.3.0/../../../../include/c++/7.3.0/string", for `#include <string>`. I presume WorkingDir is somehow changed to /usr/lib or /usr/include and clang_getFileName() returns a path relative to WorkingDir. clang_File_tryGetRealPathName() returns "/usr/include/c++/7.3.0/string" which is more useful for the indexer in this case. Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42893 llvm-svn: 329515
Diffstat (limited to 'clang/unittests/libclang/LibclangTest.cpp')
-rw-r--r--clang/unittests/libclang/LibclangTest.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp
index c44095d..17a50676 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -482,6 +482,21 @@ public:
}
};
+TEST_F(LibclangReparseTest, FileName) {
+ std::string CppName = "main.cpp";
+ WriteFile(CppName, "int main() {}");
+ ClangTU = clang_parseTranslationUnit(Index, CppName.c_str(), nullptr, 0,
+ nullptr, 0, TUFlags);
+ CXFile cxf = clang_getFile(ClangTU, CppName.c_str());
+
+ CXString cxname = clang_getFileName(cxf);
+ ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+ clang_disposeString(cxname);
+
+ cxname = clang_File_tryGetRealPathName(cxf);
+ ASSERT_TRUE(strstr(clang_getCString(cxname), CppName.c_str()));
+ clang_disposeString(cxname);
+}
TEST_F(LibclangReparseTest, Reparse) {
const char *HeaderTop = "#ifndef H\n#define H\nstruct Foo { int bar;";