From c87ab05fc6dee07fa0d9d9bb7345fd838c973fb2 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Wed, 6 Nov 2019 14:30:39 +0300 Subject: [PATCH] [HIPIFY] Add a compatibility for CharSourceRange if LLVM < 7 --- hipify-clang/src/HipifyAction.cpp | 2 +- hipify-clang/src/LLVMCompat.cpp | 8 ++++++++ hipify-clang/src/LLVMCompat.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/hipify-clang/src/HipifyAction.cpp b/hipify-clang/src/HipifyAction.cpp index 0e776df63e..032bfef2aa 100644 --- a/hipify-clang/src/HipifyAction.cpp +++ b/hipify-clang/src/HipifyAction.cpp @@ -391,7 +391,7 @@ bool HipifyAction::cudaLaunchKernel(const mat::MatchFinder::MatchResult &Result) } OS << ")"; clang::SourceLocation launchKernelExprLocBeg = launchKernel->getExprLoc(); - clang::SourceLocation launchKernelExprLocEnd = launchKernelExprLocBeg.isMacroID() ? SM->getExpansionRange(launchKernelExprLocBeg).getEnd() : llcompat::getEndLoc(launchKernel); + clang::SourceLocation launchKernelExprLocEnd = launchKernelExprLocBeg.isMacroID() ? llcompat::getEndOfExpansionRangeForLoc(*SM, launchKernelExprLocBeg) : llcompat::getEndLoc(launchKernel); clang::SourceLocation launchKernelEnd = llcompat::getEndLoc(launchKernel); clang::BeforeThanCompare isBefore(*SM); launchKernelExprLocEnd = isBefore(launchKernelEnd, launchKernelExprLocEnd) ? launchKernelExprLocEnd : launchKernelEnd; diff --git a/hipify-clang/src/LLVMCompat.cpp b/hipify-clang/src/LLVMCompat.cpp index daebd214d1..1d1119f206 100644 --- a/hipify-clang/src/LLVMCompat.cpp +++ b/hipify-clang/src/LLVMCompat.cpp @@ -151,4 +151,12 @@ bool CheckCompatibility() { return true; } +clang::SourceLocation getEndOfExpansionRangeForLoc(const clang::SourceManager& SM, const clang::SourceLocation& loc) { +#if LLVM_VERSION_MAJOR > 6 + return SM.getExpansionRange(loc).getEnd(); +#else + return SM.getExpansionRange(loc).second; +#endif +} + } // namespace llcompat diff --git a/hipify-clang/src/LLVMCompat.h b/hipify-clang/src/LLVMCompat.h index c1d671f513..8ad2862d9f 100644 --- a/hipify-clang/src/LLVMCompat.h +++ b/hipify-clang/src/LLVMCompat.h @@ -91,4 +91,6 @@ void RetainExcludedConditionalBlocks(clang::CompilerInstance &CI); bool CheckCompatibility(); +clang::SourceLocation getEndOfExpansionRangeForLoc(const clang::SourceManager& SM, const clang::SourceLocation& loc); + } // namespace llcompat