Skip to content

Commit

Permalink
Merge pull request #1047 from emankov/HIPIFY
Browse files Browse the repository at this point in the history
[HIPIFY][#1046][clang][compatibility][fix] clang 18.0.0git compatibility support
  • Loading branch information
emankov authored Oct 2, 2023
2 parents 7b303a9 + fb45cd3 commit fef2984
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/HipifyAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
13 changes: 13 additions & 0 deletions src/LLVMCompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/LLVMCompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fef2984

Please sign in to comment.