Skip to content

Add support for LLVM 19 #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions clang_delta/ExpressionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand Down Expand Up @@ -118,7 +120,11 @@ bool LocalTmpVarCollector::VisitDeclRefExpr(DeclRefExpr *DRE)
const VarDecl *VD = dyn_cast<VarDecl>(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;
}
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -524,8 +540,13 @@ bool ExpressionDetector::isValidExpr(Stmt *S, const Expr *E)
if (const DeclRefExpr *SubE =
dyn_cast<DeclRefExpr>(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;
}
}
Expand All @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions clang_delta/RemoveNamespace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions clang_delta/RenameCXXMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down