diff --git a/src/HipifyAction.cpp b/src/HipifyAction.cpp index d0750cb9..69aaa7cd 100644 --- a/src/HipifyAction.cpp +++ b/src/HipifyAction.cpp @@ -1736,12 +1736,9 @@ void HipifyAction::EndSourceFileAction() { // one copy of the hip include into every file. bool placeForIncludeCalculated = false; clang::SourceLocation sl, controllingMacroLoc; - auto &SM = getCompilerInstance().getSourceManager(); - clang::Preprocessor &PP = getCompilerInstance().getPreprocessor(); - clang::HeaderSearch &HS = PP.getHeaderSearchInfo(); - clang::ExternalPreprocessorSource *EPL = HS.getExternalLookup(); - const clang::FileEntry *FE = SM.getFileEntryForID(SM.getMainFileID()); - const clang::IdentifierInfo *controllingMacro = HS.getFileInfo(FE).getControllingMacro(EPL); + auto &CI = getCompilerInstance(); + auto &SM = CI.getSourceManager(); + const clang::IdentifierInfo *controllingMacro = llcompat::getControllingMacro(CI); if (controllingMacro) { auto found = Ifndefs.find(controllingMacro->getName().str()); if (found != Ifndefs.end()) { diff --git a/src/LLVMCompat.cpp b/src/LLVMCompat.cpp index 7401f6c9..9d811dfc 100644 --- a/src/LLVMCompat.cpp +++ b/src/LLVMCompat.cpp @@ -175,4 +175,17 @@ void addTargetIfNeeded(ct::RefactoringTool& Tool) { #endif } +const clang::IdentifierInfo *getControllingMacro(clang::CompilerInstance &CI) { + auto &SM = CI.getSourceManager(); + clang::Preprocessor &PP = CI.getPreprocessor(); + clang::HeaderSearch &HS = PP.getHeaderSearchInfo(); + clang::ExternalPreprocessorSource *EPL = HS.getExternalLookup(); + const clang::FileEntry *FE = SM.getFileEntryForID(SM.getMainFileID()); +#if LLVM_VERSION_MAJOR >= 18 + return HS.getFileInfo(FE->getLastRef()).getControllingMacro(EPL); +#else + return HS.getFileInfo(FE).getControllingMacro(EPL); +#endif +} + } // namespace llcompat diff --git a/src/LLVMCompat.h b/src/LLVMCompat.h index 34292064..50b84399 100644 --- a/src/LLVMCompat.h +++ b/src/LLVMCompat.h @@ -101,4 +101,6 @@ Memory_Buffer getMemoryBuffer(const clang::SourceManager &SM); void addTargetIfNeeded(ct::RefactoringTool& Tool); +const clang::IdentifierInfo *getControllingMacro(clang::CompilerInstance &CI); + } // namespace llcompat