Skip to content

Commit

Permalink
[Clang][NFC] Rename CXXMethodDecl::isPure -> is VirtualPure (#78463)
Browse files Browse the repository at this point in the history
To avoid any possible confusion with the notion of pure function and the
gnu::pure attribute.
  • Loading branch information
cor3ntin authored Jan 18, 2024
1 parent d87a53a commit e90e43f
Show file tree
Hide file tree
Showing 33 changed files with 61 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool MultipleInheritanceCheck::isCurrentClassInterface(

// Interfaces should have exclusively pure methods.
return llvm::none_of(Node->methods(), [](const CXXMethodDecl *M) {
return M->isUserProvided() && !M->isPure() && !M->isStatic();
return M->isUserProvided() && !M->isPureVirtual() && !M->isStatic();
});
}

Expand Down Expand Up @@ -103,8 +103,8 @@ void MultipleInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Base = cast<CXXRecordDecl>(Ty->getDecl()->getDefinition());
if (!isInterface(Base)) NumConcrete++;
}
// Check virtual bases to see if there is more than one concrete

// Check virtual bases to see if there is more than one concrete
// non-virtual base.
for (const auto &V : D->vbases()) {
const auto *Ty = V.getType()->getAs<RecordType>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ namespace clang::tidy::modernize {

namespace {
AST_MATCHER(FunctionDecl, hasAnyDefinition) {
if (Node.hasBody() || Node.isPure() || Node.isDefaulted() || Node.isDeleted())
if (Node.hasBody() || Node.isPureVirtual() || Node.isDefaulted() ||
Node.isDeleted())
return true;

if (const FunctionDecl *Definition = Node.getDefinition())
if (Definition->hasBody() || Definition->isPure() ||
if (Definition->hasBody() || Definition->isPureVirtual() ||
Definition->isDefaulted() || Definition->isDeleted())
return true;

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/SemanticHighlighting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ bool isStatic(const Decl *D) {

bool isAbstract(const Decl *D) {
if (const auto *CMD = llvm::dyn_cast<CXXMethodDecl>(D))
return CMD->isPure();
return CMD->isPureVirtual();
if (const auto *CRD = llvm::dyn_cast<CXXRecordDecl>(D))
return CRD->hasDefinition() && CRD->isAbstract();
return false;
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/XRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
// Special case: virtual void ^method() = 0: jump to all overrides.
// FIXME: extend it to ^virtual, unfortunately, virtual location is not
// saved in the AST.
if (CMD->isPure()) {
if (CMD->isPureVirtual()) {
if (TouchedIdentifier && SM.getSpellingLoc(CMD->getLocation()) ==
TouchedIdentifier->location()) {
VirtualMethods.insert(getSymbolID(CMD));
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2294,8 +2294,8 @@ class FunctionDecl : public DeclaratorDecl,

/// Whether this virtual function is pure, i.e. makes the containing class
/// abstract.
bool isPure() const { return FunctionDeclBits.IsPure; }
void setPure(bool P = true);
bool isPureVirtual() const { return FunctionDeclBits.IsPureVirtual; }
void setIsPureVirtual(bool P = true);

/// Whether this templated function will be late parsed.
bool isLateTemplateParsed() const {
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/DeclBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ class DeclContext {
LLVM_PREFERRED_TYPE(bool)
uint64_t IsVirtualAsWritten : 1;
LLVM_PREFERRED_TYPE(bool)
uint64_t IsPure : 1;
uint64_t IsPureVirtual : 1;
LLVM_PREFERRED_TYPE(bool)
uint64_t HasInheritedPrototype : 1;
LLVM_PREFERRED_TYPE(bool)
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class CXXRecordDecl : public RecordDecl {
friend class LambdaExpr;
friend class ODRDiagsEmitter;

friend void FunctionDecl::setPure(bool);
friend void FunctionDecl::setIsPureVirtual(bool);
friend void TagDecl::startDefinition();

/// Values used in DefinitionData fields to represent special members.
Expand Down Expand Up @@ -2110,7 +2110,7 @@ class CXXMethodDecl : public FunctionDecl {

// Member function is virtual if it is marked explicitly so, or if it is
// declared in __interface -- then it is automatically pure virtual.
if (CD->isVirtualAsWritten() || CD->isPure())
if (CD->isVirtualAsWritten() || CD->isPureVirtual())
return true;

return CD->size_overridden_methods() != 0;
Expand Down
4 changes: 1 addition & 3 deletions clang/include/clang/ASTMatchers/ASTMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -6351,9 +6351,7 @@ AST_POLYMORPHIC_MATCHER(isFinal,
/// };
/// \endcode
/// matches A::x
AST_MATCHER(CXXMethodDecl, isPure) {
return Node.isPure();
}
AST_MATCHER(CXXMethodDecl, isPure) { return Node.isPureVirtual(); }

/// Matches if the given method declaration is const.
///
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3896,7 +3896,7 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
ToFunction->setLexicalDeclContext(LexicalDC);
ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
ToFunction->setTrivial(D->isTrivial());
ToFunction->setPure(D->isPure());
ToFunction->setIsPureVirtual(D->isPureVirtual());
ToFunction->setDefaulted(D->isDefaulted());
ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted());
ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ASTStructuralEquivalence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
Method1->isConst() == Method2->isConst() &&
Method1->isVolatile() == Method2->isVolatile() &&
Method1->isVirtual() == Method2->isVirtual() &&
Method1->isPure() == Method2->isPure() &&
Method1->isPureVirtual() == Method2->isPureVirtual() &&
Method1->isDefaulted() == Method2->isDefaulted() &&
Method1->isDeleted() == Method2->isDeleted();
if (!PropertiesEqual)
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3036,7 +3036,7 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC,
FunctionDeclBits.IsInline = isInlineSpecified;
FunctionDeclBits.IsInlineSpecified = isInlineSpecified;
FunctionDeclBits.IsVirtualAsWritten = false;
FunctionDeclBits.IsPure = false;
FunctionDeclBits.IsPureVirtual = false;
FunctionDeclBits.HasInheritedPrototype = false;
FunctionDeclBits.HasWrittenPrototype = true;
FunctionDeclBits.IsDeleted = false;
Expand Down Expand Up @@ -3203,8 +3203,8 @@ void FunctionDecl::setBody(Stmt *B) {
EndRangeLoc = B->getEndLoc();
}

void FunctionDecl::setPure(bool P) {
FunctionDeclBits.IsPure = P;
void FunctionDecl::setIsPureVirtual(bool P) {
FunctionDeclBits.IsPureVirtual = P;
if (P)
if (auto *Parent = dyn_cast<CXXRecordDecl>(getDeclContext()))
Parent->markedVirtualFunctionPure();
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/AST/DeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ void CXXRecordDecl::completeDefinition(CXXFinalOverriderMap *FinalOverriders) {
// A class is abstract if it contains or inherits at least one
// pure virtual function for which the final overrider is pure
// virtual.
if (SO->second.front().Method->isPure()) {
if (SO->second.front().Method->isPureVirtual()) {
data().Abstract = true;
Done = true;
break;
Expand Down Expand Up @@ -2298,7 +2298,7 @@ CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base,
// If the member function is marked 'final', we know that it can't be
// overridden and can therefore devirtualize it unless it's pure virtual.
if (hasAttr<FinalAttr>())
return isPure() ? nullptr : this;
return isPureVirtual() ? nullptr : this;

// If Base is unknown, we cannot devirtualize.
if (!Base)
Expand Down Expand Up @@ -2327,7 +2327,7 @@ CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base,
// If that method is pure virtual, we can't devirtualize. If this code is
// reached, the result would be UB, not a direct call to the derived class
// function, and we can't assume the derived class function is defined.
if (DevirtualizedMethod->isPure())
if (DevirtualizedMethod->isPureVirtual())
return nullptr;

// If that method is marked final, we can devirtualize it.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/DeclPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ void DeclPrinter::VisitFunctionDecl(FunctionDecl *D) {

prettyPrintAttributes(D, Out, AttrPrintLoc::Right);

if (D->isPure())
if (D->isPureVirtual())
Out << " = 0";
else if (D->isDeletedAsWritten())
Out << " = delete";
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5839,7 +5839,7 @@ static const CXXMethodDecl *HandleVirtualDispatch(
// C++2a [class.abstract]p6:
// the effect of making a virtual call to a pure virtual function [...] is
// undefined
if (Callee->isPure()) {
if (Callee->isPureVirtual()) {
Info.FFDiag(E, diag::note_constexpr_pure_virtual_call, 1) << Callee;
Info.Note(Callee->getLocation(), diag::note_declared_at);
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ bool CheckThis(InterpState &S, CodePtr OpPC, const Pointer &This) {
}

bool CheckPure(InterpState &S, CodePtr OpPC, const CXXMethodDecl *MD) {
if (!MD->isPure())
if (!MD->isPureVirtual())
return true;
const SourceInfo &E = S.Current->getSource(OpPC);
S.FFDiag(E, diag::note_constexpr_pure_virtual_call, 1) << MD;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/JSONNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ void JSONNodeDumper::VisitFunctionDecl(const FunctionDecl *FD) {
JOS.attribute("storageClass", VarDecl::getStorageClassSpecifierString(SC));
attributeOnlyIfTrue("inline", FD->isInlineSpecified());
attributeOnlyIfTrue("virtual", FD->isVirtualAsWritten());
attributeOnlyIfTrue("pure", FD->isPure());
attributeOnlyIfTrue("pure", FD->isPureVirtual());
attributeOnlyIfTrue("explicitlyDeleted", FD->isDeletedAsWritten());
attributeOnlyIfTrue("constexpr", FD->isConstexpr());
attributeOnlyIfTrue("variadic", FD->isVariadic());
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/ODRDiagsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,8 @@ bool ODRDiagsEmitter::diagnoseMismatch(

const bool FirstVirtual = FirstMethod->isVirtualAsWritten();
const bool SecondVirtual = SecondMethod->isVirtualAsWritten();
const bool FirstPure = FirstMethod->isPure();
const bool SecondPure = SecondMethod->isPure();
const bool FirstPure = FirstMethod->isPureVirtual();
const bool SecondPure = SecondMethod->isPureVirtual();
if ((FirstVirtual || SecondVirtual) &&
(FirstVirtual != SecondVirtual || FirstPure != SecondPure)) {
DiagMethodError(MethodVirtual) << FirstPure << FirstVirtual;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ODRHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ void ODRHash::AddFunctionDecl(const FunctionDecl *Function,
ID.AddInteger(Function->getStorageClass());
AddBoolean(Function->isInlineSpecified());
AddBoolean(Function->isVirtualAsWritten());
AddBoolean(Function->isPure());
AddBoolean(Function->isPureVirtual());
AddBoolean(Function->isDeletedAsWritten());
AddBoolean(Function->isExplicitlyDefaulted());

Expand Down
4 changes: 2 additions & 2 deletions clang/lib/AST/RecordLayoutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,7 @@ static const CXXMethodDecl *computeKeyFunction(ASTContext &Context,
if (!MD->isVirtual())
continue;

if (MD->isPure())
if (MD->isPureVirtual())
continue;

// Ignore implicit member functions, they are always marked as inline, but
Expand Down Expand Up @@ -3293,7 +3293,7 @@ void MicrosoftRecordLayoutBuilder::computeVtorDispSet(
// Seed the working set with our non-destructor, non-pure virtual methods.
for (const CXXMethodDecl *MD : RD->methods())
if (MicrosoftVTableContext::hasVtableSlot(MD) &&
!isa<CXXDestructorDecl>(MD) && !MD->isPure())
!isa<CXXDestructorDecl>(MD) && !MD->isPureVirtual())
Work.insert(MD);
while (!Work.empty()) {
const CXXMethodDecl *MD = *Work.begin();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/TextNodeDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ void TextNodeDumper::VisitFunctionDecl(const FunctionDecl *D) {
if (D->isModulePrivate())
OS << " __module_private__";

if (D->isPure())
if (D->isPureVirtual())
OS << " pure";
if (D->isDefaulted()) {
OS << " default";
Expand Down
18 changes: 9 additions & 9 deletions clang/lib/AST/VTableBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void FinalOverriders::dump(raw_ostream &Out, BaseSubobject Base,
Out << ", " << Overrider.Offset.getQuantity() << ')';

BaseOffset Offset;
if (!Overrider.Method->isPure())
if (!Overrider.Method->isPureVirtual())
Offset = ComputeReturnAdjustmentBaseOffset(Context, Overrider.Method, MD);

if (!Offset.isEmpty()) {
Expand Down Expand Up @@ -1261,7 +1261,7 @@ ThisAdjustment ItaniumVTableBuilder::ComputeThisAdjustment(
const CXXMethodDecl *MD, CharUnits BaseOffsetInLayoutClass,
FinalOverriders::OverriderInfo Overrider) {
// Ignore adjustments for pure virtual member functions.
if (Overrider.Method->isPure())
if (Overrider.Method->isPureVirtual())
return ThisAdjustment();

BaseSubobject OverriddenBaseSubobject(MD->getParent(),
Expand Down Expand Up @@ -1607,7 +1607,7 @@ void ItaniumVTableBuilder::AddMethods(
// Check if this overrider needs a return adjustment.
// We don't want to do this for pure virtual member functions.
BaseOffset ReturnAdjustmentOffset;
if (!OverriderMD->isPure()) {
if (!OverriderMD->isPureVirtual()) {
ReturnAdjustmentOffset =
ComputeReturnAdjustmentBaseOffset(Context, OverriderMD, MD);
}
Expand Down Expand Up @@ -1959,7 +1959,7 @@ void ItaniumVTableBuilder::dumpLayout(raw_ostream &Out) {
std::string Str = PredefinedExpr::ComputeName(
PredefinedIdentKind::PrettyFunctionNoVirtual, MD);
Out << Str;
if (MD->isPure())
if (MD->isPureVirtual())
Out << " [pure]";

if (MD->isDeleted())
Expand Down Expand Up @@ -2010,7 +2010,7 @@ void ItaniumVTableBuilder::dumpLayout(raw_ostream &Out) {
else
Out << "() [deleting]";

if (DD->isPure())
if (DD->isPureVirtual())
Out << " [pure]";

ThunkInfo Thunk = VTableThunks.lookup(I);
Expand Down Expand Up @@ -2038,7 +2038,7 @@ void ItaniumVTableBuilder::dumpLayout(raw_ostream &Out) {
std::string Str = PredefinedExpr::ComputeName(
PredefinedIdentKind::PrettyFunctionNoVirtual, MD);
Out << "[unused] " << Str;
if (MD->isPure())
if (MD->isPureVirtual())
Out << " [pure]";
}

Expand Down Expand Up @@ -3076,7 +3076,7 @@ void VFTableBuilder::AddMethods(BaseSubobject Base, unsigned BaseDepth,
// We don't want to do this for pure virtual member functions.
BaseOffset ReturnAdjustmentOffset;
ReturnAdjustment ReturnAdjustment;
if (!FinalOverriderMD->isPure()) {
if (!FinalOverriderMD->isPureVirtual()) {
ReturnAdjustmentOffset =
ComputeReturnAdjustmentBaseOffset(Context, FinalOverriderMD, MD);
}
Expand Down Expand Up @@ -3175,7 +3175,7 @@ void VFTableBuilder::dumpLayout(raw_ostream &Out) {
std::string Str = PredefinedExpr::ComputeName(
PredefinedIdentKind::PrettyFunctionNoVirtual, MD);
Out << Str;
if (MD->isPure())
if (MD->isPureVirtual())
Out << " [pure]";

if (MD->isDeleted())
Expand All @@ -3194,7 +3194,7 @@ void VFTableBuilder::dumpLayout(raw_ostream &Out) {
DD->printQualifiedName(Out);
Out << "() [scalar deleting]";

if (DD->isPure())
if (DD->isPureVirtual())
Out << " [pure]";

ThunkInfo Thunk = VTableThunks.lookup(I);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,7 +1926,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
int ThisAdjustment = 0;

if (VTableContextBase::hasVtableSlot(Method)) {
if (Method->isPure())
if (Method->isPureVirtual())
SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
else
SPFlags |= llvm::DISubprogram::SPFlagVirtual;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGVTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ void CodeGenVTables::addVTableComponent(ConstantArrayBuilder &builder,
llvm::Constant *fnPtr;

// Pure virtual member functions.
if (cast<CXXMethodDecl>(GD.getDecl())->isPure()) {
if (cast<CXXMethodDecl>(GD.getDecl())->isPureVirtual()) {
if (!PureVirtualFn)
PureVirtualFn =
getSpecialVirtualFn(CGM.getCXXABI().GetPureVirtualCallName());
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/Sema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ static bool MethodsAndNestedClassesComplete(const CXXRecordDecl *RD,
I != E && Complete; ++I) {
if (const CXXMethodDecl *M = dyn_cast<CXXMethodDecl>(*I))
Complete = M->isDefined() || M->isDefaulted() ||
(M->isPure() && !isa<CXXDestructorDecl>(M));
(M->isPureVirtual() && !isa<CXXDestructorDecl>(M));
else if (const FunctionTemplateDecl *F = dyn_cast<FunctionTemplateDecl>(*I))
// If the template function is marked as late template parsed at this
// point, it has not been instantiated and therefore we have not
Expand Down
9 changes: 5 additions & 4 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4390,8 +4390,8 @@ bool Sema::MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old,
mergeDeclAttributes(New, Old);

// Merge "pure" flag.
if (Old->isPure())
New->setPure();
if (Old->isPureVirtual())
New->setIsPureVirtual();

// Merge "used" flag.
if (Old->getMostRecentDecl()->isUsed(false))
Expand Down Expand Up @@ -9878,7 +9878,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
if (const CXXRecordDecl *Parent =
dyn_cast<CXXRecordDecl>(NewFD->getDeclContext())) {
if (Parent->isInterface() && cast<CXXMethodDecl>(NewFD)->isUserProvided())
NewFD->setPure(true);
NewFD->setIsPureVirtual(true);

// C++ [class.union]p2
// A union can have member functions, but not virtual functions.
Expand Down Expand Up @@ -16012,7 +16012,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,

// MSVC permits the use of pure specifier (=0) on function definition,
// defined at class scope, warn about this non-standard construct.
if (getLangOpts().MicrosoftExt && FD->isPure() && !FD->isOutOfLine())
if (getLangOpts().MicrosoftExt && FD->isPureVirtual() &&
!FD->isOutOfLine())
Diag(FD->getLocation(), diag::ext_pure_function_definition);

if (!FD->isInvalidDecl()) {
Expand Down
Loading

0 comments on commit e90e43f

Please sign in to comment.