diff --git a/clang_delta/ExpressionDetector.cpp b/clang_delta/ExpressionDetector.cpp index cf703924..22bdfcff 100644 --- a/clang_delta/ExpressionDetector.cpp +++ b/clang_delta/ExpressionDetector.cpp @@ -64,7 +64,8 @@ class IncludesPPCallbacks : public PPCallbacks { StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + const Module *SuggestedModule, + bool ModuleImported, SrcMgr::CharacteristicKind FileType) override; private: @@ -85,7 +86,8 @@ void IncludesPPCallbacks::InclusionDirective(SourceLocation HashLoc, OptionalFileEntryRef /*File*/, StringRef /*SearchPath*/, StringRef /*RelativePath*/, - const Module * /*Imported*/, + const Module * /*SuggestedModule*/, + bool /*ModuleImported*/, SrcMgr::CharacteristicKind /*FileType*/) { if (!SrcManager.isInMainFile(HashLoc)) @@ -118,7 +120,11 @@ bool LocalTmpVarCollector::VisitDeclRefExpr(DeclRefExpr *DRE) const VarDecl *VD = dyn_cast(DRE->getDecl()); if (!VD) return true; +#if LLVM_VERSION_MAJOR >= 19 + if (VD->getName().starts_with(Prefix)) +#else if (VD->getName().startswith(Prefix)) +#endif TmpVars.push_back(VD); return true; } @@ -363,7 +369,11 @@ void ExpressionDetector::addOneTempVar(const VarDecl *VD) { if (!VD) return; +#if LLVM_VERSION_MAJOR >= 19 + if (!VD->getName().starts_with(TmpVarNamePrefix)) +#else if (!VD->getName().startswith(TmpVarNamePrefix)) +#endif return; if (const Expr *E = VD->getInit()) ProcessedExprs[VD] = E->IgnoreParenImpCasts(); @@ -374,9 +384,15 @@ bool ExpressionDetector::refToTmpVar(const NamedDecl *ND) StringRef Name = ND->getName(); // We don't want to repeatly replace temporary variables // __creduce_expr_tmp_xxx, __creduce_printed_yy and __creduce_checked_zzz. +#if LLVM_VERSION_MAJOR >= 19 + return Name.starts_with(TmpVarNamePrefix) || + Name.starts_with(PrintedVarNamePrefix) || + Name.starts_with(CheckedVarNamePrefix); +#else return Name.startswith(TmpVarNamePrefix) || Name.startswith(PrintedVarNamePrefix) || Name.startswith(CheckedVarNamePrefix); +#endif } // Reference: IdenticalExprChecker.cpp from Clang @@ -524,8 +540,13 @@ bool ExpressionDetector::isValidExpr(Stmt *S, const Expr *E) if (const DeclRefExpr *SubE = dyn_cast(UO->getSubExpr()->IgnoreParenCasts())) { StringRef SubEName = SubE->getDecl()->getName(); +#if LLVM_VERSION_MAJOR >= 19 + if (SubEName.starts_with(PrintedVarNamePrefix) || + SubEName.starts_with(CheckedVarNamePrefix)) +#else if (SubEName.startswith(PrintedVarNamePrefix) || SubEName.startswith(CheckedVarNamePrefix)) +#endif return false; } } @@ -541,7 +562,11 @@ bool ExpressionDetector::isValidExpr(Stmt *S, const Expr *E) bool IsLit = SC == Stmt::IntegerLiteralClass || SC == Stmt::FloatingLiteralClass; if (IsLit && DRE && +#if LLVM_VERSION_MAJOR >= 19 + DRE->getDecl()->getName().starts_with(TmpVarNamePrefix) && +#else DRE->getDecl()->getName().startswith(TmpVarNamePrefix) && +#endif S->getStmtClass() == Stmt::IfStmtClass) { return false; } diff --git a/clang_delta/RemoveNamespace.cpp b/clang_delta/RemoveNamespace.cpp index 0f8fc427..82cd3b82 100644 --- a/clang_delta/RemoveNamespace.cpp +++ b/clang_delta/RemoveNamespace.cpp @@ -944,7 +944,11 @@ void RemoveNamespace::handleOneNamedDecl(const NamedDecl *ND, TransAssert(IdInfo && "Invalid IdentifierInfo!"); NewName += IdInfo->getName(); // Make sure we have valid suffix for user literals +#if LLVM_VERSION_MAJOR >= 19 + if (IsUserLiteral && IdInfo->getName().starts_with("_")) { +#else if (IsUserLiteral && IdInfo->getName().startswith("_")) { +#endif NewName = "_" + NewName; } NamedDeclToNewName[ND] = NewName; diff --git a/clang_delta/RenameCXXMethod.cpp b/clang_delta/RenameCXXMethod.cpp index e71cc738..680c03da 100644 --- a/clang_delta/RenameCXXMethod.cpp +++ b/clang_delta/RenameCXXMethod.cpp @@ -426,7 +426,11 @@ bool RenameCXXMethod::isValidName(const StringRef &Name) { size_t PrefixLen = MethodNamePrefix.length(); StringRef NamePrefix = Name.substr(0, PrefixLen); +#if LLVM_VERSION_MAJOR >= 19 + if (NamePrefix != MethodNamePrefix) +#else if (!NamePrefix.equals(MethodNamePrefix)) +#endif return false; llvm::APInt Num; return !Name.drop_front(PrefixLen).getAsInteger(10, Num); diff --git a/clang_delta/Transformation.cpp b/clang_delta/Transformation.cpp index b350eec5..707a0209 100644 --- a/clang_delta/Transformation.cpp +++ b/clang_delta/Transformation.cpp @@ -95,7 +95,7 @@ void Transformation::Initialize(ASTContext &context) void Transformation::outputTransformedSource(llvm::raw_ostream &OutStream) { FileID MainFileID = SrcManager->getMainFileID(); - const RewriteBuffer *RWBuf = TheRewriter.getRewriteBufferFor(MainFileID); + const llvm::RewriteBuffer *RWBuf = TheRewriter.getRewriteBufferFor(MainFileID); // RWBuf is non-empty upon any rewrites TransAssert(RWBuf && "Empty RewriteBuffer!"); diff --git a/clang_delta/TransformationManager.cpp b/clang_delta/TransformationManager.cpp index 79b17cee..e16e07ce 100644 --- a/clang_delta/TransformationManager.cpp +++ b/clang_delta/TransformationManager.cpp @@ -24,6 +24,7 @@ #include "clang/Lex/PreprocessorOptions.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Parse/ParseAST.h" +#include "llvm/Support/VirtualFileSystem.h" // For llvm::vfs::get GlobalVirtualFileSystem() #include "Transformation.h" @@ -90,8 +91,14 @@ bool TransformationManager::initializeCompilerInstance(std::string &ErrorMsg) ClangInstance = new CompilerInstance(); assert(ClangInstance); - + +#if LLVM_VERSION_MAJOR >= 20 + // Get the global virtual file system + auto VFS = llvm::vfs::getRealFileSystem(); + ClangInstance->createDiagnostics(*VFS); +#else ClangInstance->createDiagnostics(); +#endif TargetOptions &TargetOpts = ClangInstance->getTargetOpts(); PreprocessorOptions &PPOpts = ClangInstance->getPreprocessorOpts();