From 208d7cfaf14c433cbc9a253db90db82f60591c89 Mon Sep 17 00:00:00 2001 From: emankov Date: Fri, 28 Dec 2018 01:34:35 +0300 Subject: [PATCH] [HIPIFY] LLVM compatibility + sys::fs::make_absolute fro LLVM < 5.0 + sys::fs::real_path for LLVM >= 5.0 --- hipify-clang/src/LLVMCompat.cpp | 9 +++++++++ hipify-clang/src/LLVMCompat.h | 3 +++ hipify-clang/src/main.cpp | 6 +++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hipify-clang/src/LLVMCompat.cpp b/hipify-clang/src/LLVMCompat.cpp index f96bd86bb0..22a0b56d64 100644 --- a/hipify-clang/src/LLVMCompat.cpp +++ b/hipify-clang/src/LLVMCompat.cpp @@ -94,4 +94,13 @@ clang::SourceLocation getEndLoc(const clang::TypeLoc& typeLoc) { #endif } +std::error_code real_path(const Twine &path, SmallVectorImpl &output, + bool expand_tilde) { +#if LLVM_VERSION_MAJOR < 5 + return sys::fs::make_absolute(path, output); +#else + return sys::fs::real_path(path, output, expand_tilde); +#endif +} + } // namespace llcompat diff --git a/hipify-clang/src/LLVMCompat.h b/hipify-clang/src/LLVMCompat.h index 4d6edcc9f8..98ff66fb41 100644 --- a/hipify-clang/src/LLVMCompat.h +++ b/hipify-clang/src/LLVMCompat.h @@ -78,4 +78,7 @@ void EnterPreprocessorTokenStream(clang::Preprocessor& _pp, size_t len, bool DisableMacroExpansion); +std::error_code real_path(const Twine &path, SmallVectorImpl &output, + bool expand_tilde = false); + } // namespace llcompat diff --git a/hipify-clang/src/main.cpp b/hipify-clang/src/main.cpp index 06981a9d70..7dc42f8882 100644 --- a/hipify-clang/src/main.cpp +++ b/hipify-clang/src/main.cpp @@ -46,7 +46,7 @@ std::string getAbsoluteDirectory(const std::string& sDir, std::error_code& EC, return sDir; } SmallString<256> dirAbsPath; - EC = sys::fs::real_path(sDir, dirAbsPath, true); + EC = llcompat::real_path(sDir, dirAbsPath, true); if (!EC && sys::fs::is_regular_file(dirAbsPath)) { llvm::errs() << "\n" << sHipify << sError << sDir << " is not a directory\n"; EC = std::error_code(static_cast(std::errc::not_a_directory), std::generic_category()); @@ -58,7 +58,7 @@ std::string getAbsoluteDirectory(const std::string& sDir, std::error_code& EC, llvm::errs() << "\n" << sHipify << sError << EC.message() << ": " << sDirType << " directory: " << sDir << "\n"; return ""; } - EC = sys::fs::real_path(sDir, dirAbsPath, true); + EC = llcompat::real_path(sDir, dirAbsPath, true); if (EC) { llvm::errs() << "\n" << sHipify << sError << EC.message() << ": " << sDirType << " directory: " << sDir << "\n"; return ""; @@ -137,7 +137,7 @@ int main(int argc, const char **argv) { // Create a copy of the file to work on. When we're done, we'll move this onto the // output (which may mean overwriting the input, if we're in-place). // Should we fail for some reason, we'll just leak this file and not corrupt the input. - EC = sys::fs::real_path(src, sourceAbsPath, true); + EC = llcompat::real_path(src, sourceAbsPath, true); if (EC) { llvm::errs() << "\n" << sHipify << sError << EC.message() << ": " << src << "\n"; Result = 1;