Bug 1873574 - Adjust searchfox plugin to LLVM 18 changes. r=asuth

StringLiteral was changed in 3e6ce58701

isPure was changed in e90e43fb9c

Differential Revision: https://phabricator.services.mozilla.com/D208723
This commit is contained in:
Mike Hommey 2024-04-30 19:49:41 +00:00
parent ba14267b34
commit b7aeb82b5e
2 changed files with 19 additions and 5 deletions

View file

@ -8,6 +8,7 @@
#include <clang/AST/Attr.h>
#include <clang/AST/Expr.h>
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Basic/Version.h>
#include <algorithm>
#include <array>
@ -173,10 +174,15 @@ constexpr StringRef BoundAs::ANNOTATION;
template<typename B>
void setBindingAttr(ASTContext &C, Decl &decl, B binding)
{
#if CLANG_VERSION_MAJOR >= 18
auto utf8 = StringLiteralKind::UTF8;
#else
auto utf8 = StringLiteral::UTF8;
#endif
// recent LLVM: CreateImplicit then setDelayedArgs
Expr *langExpr = StringLiteral::Create(C, AbstractBinding::stringFromLang(binding.lang), StringLiteral::UTF8, false, {}, {});
Expr *kindExpr = StringLiteral::Create(C, AbstractBinding::stringFromKind(binding.kind), StringLiteral::UTF8, false, {}, {});
Expr *symbolExpr = StringLiteral::Create(C, binding.symbol, StringLiteral::UTF8, false, {}, {});
Expr *langExpr = StringLiteral::Create(C, AbstractBinding::stringFromLang(binding.lang), utf8, false, {}, {});
Expr *kindExpr = StringLiteral::Create(C, AbstractBinding::stringFromKind(binding.kind), utf8, false, {}, {});
Expr *symbolExpr = StringLiteral::Create(C, binding.symbol, utf8, false, {}, {});
auto **args = new (C, 16) Expr *[3]{langExpr, kindExpr, symbolExpr};
auto *attr = AnnotateAttr::CreateImplicit(C, B::ANNOTATION, args, 3);
decl.addAttr(attr);

View file

@ -138,6 +138,14 @@ struct RAIITracer {
class IndexConsumer;
bool isPure(FunctionDecl* D) {
#if CLANG_VERSION_MAJOR >= 18
return D->isPureVirtual();
#else
return D->isPure();
#endif
}
// For each C++ file seen by the analysis (.cpp or .h), we track a
// FileInfo. This object tracks whether the file is "interesting" (i.e., whether
// it's in the source dir or the objdir). We also store the analysis output
@ -1749,7 +1757,7 @@ public:
D = D2->getTemplateInstantiationPattern();
}
// We treat pure virtual declarations as definitions.
Kind = (D2->isThisDeclarationADefinition() || D2->isPure()) ? "def" : "decl";
Kind = (D2->isThisDeclarationADefinition() || isPure(D2)) ? "def" : "decl";
PrettyKind = "function";
PeekRange = getFunctionPeekRange(D2);
@ -1881,7 +1889,7 @@ public:
}
}
if (FunctionDecl *D2 = dyn_cast<FunctionDecl>(D)) {
if ((D2->isThisDeclarationADefinition() || D2->isPure()) &&
if ((D2->isThisDeclarationADefinition() || isPure(D2)) &&
// a clause at the top should have generalized and set wasTemplate so
// it shouldn't be the case that isTemplateInstantiation() is true.
!D2->isTemplateInstantiation() &&