Skip to content

Commit c1ff133

Browse files
committed
[NFC] Rename ExtraFunctionInfo and update comments
1 parent d6537a2 commit c1ff133

File tree

11 files changed

+76
-62
lines changed

11 files changed

+76
-62
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,8 +1982,8 @@ class FunctionDecl : public DeclaratorDecl,
19821982
};
19831983

19841984
/// Stashed information about a defaulted/deleted function body.
1985-
class ExtraFunctionInfo final
1986-
: llvm::TrailingObjects<ExtraFunctionInfo, DeclAccessPair,
1985+
class DefaultedOrDeletedFunctionInfo final
1986+
: llvm::TrailingObjects<DefaultedOrDeletedFunctionInfo, DeclAccessPair,
19871987
StringLiteral *> {
19881988
friend TrailingObjects;
19891989
unsigned NumLookups;
@@ -1994,9 +1994,9 @@ class FunctionDecl : public DeclaratorDecl,
19941994
}
19951995

19961996
public:
1997-
static ExtraFunctionInfo *Create(ASTContext &Context,
1998-
ArrayRef<DeclAccessPair> Lookups,
1999-
StringLiteral *DeletedMessage = nullptr);
1997+
static DefaultedOrDeletedFunctionInfo *
1998+
Create(ASTContext &Context, ArrayRef<DeclAccessPair> Lookups,
1999+
StringLiteral *DeletedMessage = nullptr);
20002000

20012001
/// Get the unqualified lookup results that should be used in this
20022002
/// defaulted function definition.
@@ -2019,12 +2019,12 @@ class FunctionDecl : public DeclaratorDecl,
20192019
ParmVarDecl **ParamInfo = nullptr;
20202020

20212021
/// The active member of this union is determined by
2022-
/// FunctionDeclBits.HasExtraFunctionInfo.
2022+
/// FunctionDeclBits.HasDefaultedOrDeletedInfo.
20232023
union {
20242024
/// The body of the function.
20252025
LazyDeclStmtPtr Body;
20262026
/// Information about a future defaulted function definition.
2027-
ExtraFunctionInfo *ExtraInfo;
2027+
DefaultedOrDeletedFunctionInfo *DefaultedOrDeletedInfo;
20282028
};
20292029

20302030
unsigned ODRHash;
@@ -2282,18 +2282,18 @@ class FunctionDecl : public DeclaratorDecl,
22822282

22832283
/// Returns whether this specific declaration of the function has a body.
22842284
bool doesThisDeclarationHaveABody() const {
2285-
return (!FunctionDeclBits.HasExtraFunctionInfo && Body) ||
2285+
return (!FunctionDeclBits.HasDefaultedOrDeletedInfo && Body) ||
22862286
isLateTemplateParsed();
22872287
}
22882288

22892289
void setBody(Stmt *B);
22902290
void setLazyBody(uint64_t Offset) {
2291-
FunctionDeclBits.HasExtraFunctionInfo = false;
2291+
FunctionDeclBits.HasDefaultedOrDeletedInfo = false;
22922292
Body = LazyDeclStmtPtr(Offset);
22932293
}
22942294

2295-
void setExtraFunctionInfo(ExtraFunctionInfo *Info);
2296-
ExtraFunctionInfo *getExtraFunctionInfo() const;
2295+
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info);
2296+
DefaultedOrDeletedFunctionInfo *getDefalutedOrDeletedInfo() const;
22972297

22982298
/// Whether this function is variadic.
22992299
bool isVariadic() const;
@@ -2657,8 +2657,8 @@ class FunctionDecl : public DeclaratorDecl,
26572657

26582658
/// Get the message that indicates why this function was deleted.
26592659
StringLiteral *getDeletedMessage() const {
2660-
return FunctionDeclBits.HasExtraFunctionInfo
2661-
? ExtraInfo->getDeletedMessage()
2660+
return FunctionDeclBits.HasDefaultedOrDeletedInfo
2661+
? DefaultedOrDeletedInfo->getDeletedMessage()
26622662
: nullptr;
26632663
}
26642664

clang/include/clang/AST/DeclBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ class DeclContext {
17401740
LLVM_PREFERRED_TYPE(bool)
17411741
uint64_t IsExplicitlyDefaulted : 1;
17421742
LLVM_PREFERRED_TYPE(bool)
1743-
uint64_t HasExtraFunctionInfo : 1;
1743+
uint64_t HasDefaultedOrDeletedInfo : 1;
17441744

17451745
/// For member functions of complete types, whether this is an ineligible
17461746
/// special member function or an unselected destructor. See

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,7 +3203,7 @@ class Sema final {
32033203
void ActOnDocumentableDecls(ArrayRef<Decl *> Group);
32043204

32053205
enum class FnBodyKind {
3206-
/// C++ [dcl.fct.def.general]p1
3206+
/// C++26 [dcl.fct.def.general]p1
32073207
/// function-body:
32083208
/// ctor-initializer[opt] compound-statement
32093209
/// function-try-block

clang/lib/AST/ASTImporter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3961,8 +3961,9 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
39613961
ToFunction->setDefaultLoc(ToDefaultLoc);
39623962

39633963
if (Msg)
3964-
ToFunction->setExtraFunctionInfo(FunctionDecl::ExtraFunctionInfo::Create(
3965-
Importer.getToContext(), {}, Msg));
3964+
ToFunction->setDefaultedOrDeletedInfo(
3965+
FunctionDecl::DefaultedOrDeletedFunctionInfo::Create(
3966+
Importer.getToContext(), {}, Msg));
39663967

39673968
// Set the parameters.
39683969
for (auto *Param : Parameters) {

clang/lib/AST/Decl.cpp

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3058,7 +3058,7 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC,
30583058
FunctionDeclBits.IsTrivialForCall = false;
30593059
FunctionDeclBits.IsDefaulted = false;
30603060
FunctionDeclBits.IsExplicitlyDefaulted = false;
3061-
FunctionDeclBits.HasExtraFunctionInfo = false;
3061+
FunctionDeclBits.HasDefaultedOrDeletedInfo = false;
30623062
FunctionDeclBits.IsIneligibleOrNotSelected = false;
30633063
FunctionDeclBits.HasImplicitReturnZero = false;
30643064
FunctionDeclBits.IsLateTemplateParsed = false;
@@ -3092,18 +3092,18 @@ bool FunctionDecl::isVariadic() const {
30923092
return false;
30933093
}
30943094

3095-
FunctionDecl::ExtraFunctionInfo *
3096-
FunctionDecl::ExtraFunctionInfo::Create(ASTContext &Context,
3097-
ArrayRef<DeclAccessPair> Lookups,
3098-
StringLiteral *DeletedMessage) {
3095+
FunctionDecl::DefaultedOrDeletedFunctionInfo *
3096+
FunctionDecl::DefaultedOrDeletedFunctionInfo::Create(
3097+
ASTContext &Context, ArrayRef<DeclAccessPair> Lookups,
3098+
StringLiteral *DeletedMessage) {
30993099
static constexpr size_t Alignment =
3100-
std::max({alignof(ExtraFunctionInfo), alignof(DeclAccessPair),
3101-
alignof(StringLiteral *)});
3100+
std::max({alignof(DefaultedOrDeletedFunctionInfo),
3101+
alignof(DeclAccessPair), alignof(StringLiteral *)});
31023102
size_t Size = totalSizeToAlloc<DeclAccessPair, StringLiteral *>(
31033103
Lookups.size(), !!DeletedMessage);
31043104

3105-
ExtraFunctionInfo *Info =
3106-
new (Context.Allocate(Size, Alignment)) ExtraFunctionInfo;
3105+
DefaultedOrDeletedFunctionInfo *Info =
3106+
new (Context.Allocate(Size, Alignment)) DefaultedOrDeletedFunctionInfo;
31073107
Info->NumLookups = Lookups.size();
31083108
Info->HasDeletedMessage = !!DeletedMessage;
31093109

@@ -3114,36 +3114,40 @@ FunctionDecl::ExtraFunctionInfo::Create(ASTContext &Context,
31143114
return Info;
31153115
}
31163116

3117-
void FunctionDecl::setExtraFunctionInfo(ExtraFunctionInfo *Info) {
3118-
assert(!FunctionDeclBits.HasExtraFunctionInfo && "already have this");
3117+
void FunctionDecl::setDefaultedOrDeletedInfo(
3118+
DefaultedOrDeletedFunctionInfo *Info) {
3119+
assert(!FunctionDeclBits.HasDefaultedOrDeletedInfo && "already have this");
31193120
assert(!Body && "can't replace function body with defaulted function info");
31203121

3121-
FunctionDeclBits.HasExtraFunctionInfo = true;
3122-
ExtraInfo = Info;
3122+
FunctionDeclBits.HasDefaultedOrDeletedInfo = true;
3123+
DefaultedOrDeletedInfo = Info;
31233124
}
31243125

3125-
void FunctionDecl::ExtraFunctionInfo::setDeletedMessage(
3126+
void FunctionDecl::DefaultedOrDeletedFunctionInfo::setDeletedMessage(
31263127
StringLiteral *Message) {
3127-
// We should never get here with the ExtraInfo populated, but no space
3128-
// allocated for the deleted message, since that would require recreating
3129-
// this, but setExtraFunctionInfo() disallows overwriting an already existing
3130-
// ExtraFunctionInfo.
3131-
assert(HasDeletedMessage && "Explicitly deleting defaulted function?");
3128+
// We should never get here with the DefaultedOrDeletedInfo populated, but
3129+
// no space allocated for the deleted message, since that would require
3130+
// recreating this, but setDefaultedOrDeletedInfo() disallows overwriting
3131+
// an already existing DefaultedOrDeletedFunctionInfo.
3132+
assert(HasDeletedMessage &&
3133+
"No space to store a delete message in this DefaultedOrDeletedInfo");
31323134
*getTrailingObjects<StringLiteral *>() = Message;
31333135
}
31343136

3135-
FunctionDecl::ExtraFunctionInfo *FunctionDecl::getExtraFunctionInfo() const {
3136-
return FunctionDeclBits.HasExtraFunctionInfo ? ExtraInfo : nullptr;
3137+
FunctionDecl::DefaultedOrDeletedFunctionInfo *
3138+
FunctionDecl::getDefalutedOrDeletedInfo() const {
3139+
return FunctionDeclBits.HasDefaultedOrDeletedInfo ? DefaultedOrDeletedInfo
3140+
: nullptr;
31373141
}
31383142

31393143
void FunctionDecl::setDeletedMessage(StringLiteral *Message) {
31403144
assert(Message && "Should not be called with nullptr");
31413145
assert(isDeletedAsWritten() && "Function must be deleted");
3142-
if (FunctionDeclBits.HasExtraFunctionInfo)
3143-
ExtraInfo->setDeletedMessage(Message);
3146+
if (FunctionDeclBits.HasDefaultedOrDeletedInfo)
3147+
DefaultedOrDeletedInfo->setDeletedMessage(Message);
31443148
else
3145-
setExtraFunctionInfo(
3146-
ExtraFunctionInfo::Create(getASTContext(), {}, Message));
3149+
setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo::Create(
3150+
getASTContext(), /*Lookups=*/{}, Message));
31473151
}
31483152

31493153
bool FunctionDecl::hasBody(const FunctionDecl *&Definition) const {
@@ -3230,7 +3234,7 @@ Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
32303234
if (!hasBody(Definition))
32313235
return nullptr;
32323236

3233-
assert(!Definition->FunctionDeclBits.HasExtraFunctionInfo &&
3237+
assert(!Definition->FunctionDeclBits.HasDefaultedOrDeletedInfo &&
32343238
"definition should not have a body");
32353239
if (Definition->Body)
32363240
return Definition->Body.get(getASTContext().getExternalSource());
@@ -3239,7 +3243,7 @@ Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
32393243
}
32403244

32413245
void FunctionDecl::setBody(Stmt *B) {
3242-
FunctionDeclBits.HasExtraFunctionInfo = false;
3246+
FunctionDeclBits.HasDefaultedOrDeletedInfo = false;
32433247
Body = LazyDeclStmtPtr(B);
32443248
if (B)
32453249
EndRangeLoc = B->getEndLoc();

clang/lib/Sema/SemaDecl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16155,8 +16155,15 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1615516155
// This is meant to pop the context added in ActOnStartOfFunctionDef().
1615616156
ExitFunctionBodyRAII ExitRAII(*this, isLambdaCallOperator(FD));
1615716157
if (FD) {
16158-
// Do not overwrite the potentially present ExtraInfo of a deleted
16159-
// function declaration.
16158+
// If this is called by Parser::ParseFunctionDefinition() after marking
16159+
// the declaration as deleted, and if the deleted-function-body contains
16160+
// a message (C++26), then a DefaultedOrDeletedInfo will have already been
16161+
// added to store that message; do not overwrite it in that case.
16162+
//
16163+
// Since this would always set the body to 'nullptr' in that case anyway,
16164+
// which is already done when the function decl is initially created,
16165+
// always skipping this irrespective of whether there is a delete message
16166+
// should not be a problem.
1616016167
if (!FD->isDeletedAsWritten())
1616116168
FD->setBody(Body);
1616216169
FD->setWillHaveBody(false);

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7962,7 +7962,7 @@ class DefaultedComparisonVisitor {
79627962
DefaultedComparisonVisitor(Sema &S, CXXRecordDecl *RD, FunctionDecl *FD,
79637963
DefaultedComparisonKind DCK)
79647964
: S(S), RD(RD), FD(FD), DCK(DCK) {
7965-
if (auto *Info = FD->getExtraFunctionInfo()) {
7965+
if (auto *Info = FD->getDefalutedOrDeletedInfo()) {
79667966
// FIXME: Change CreateOverloadedBinOp to take an ArrayRef instead of an
79677967
// UnresolvedSet to avoid this copy.
79687968
Fns.assign(Info->getUnqualifiedLookups().begin(),
@@ -8830,8 +8830,9 @@ bool Sema::CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *FD,
88308830
UnresolvedSet<32> Operators;
88318831
lookupOperatorsForDefaultedComparison(*this, S, Operators,
88328832
FD->getOverloadedOperator());
8833-
FD->setExtraFunctionInfo(
8834-
FunctionDecl::ExtraFunctionInfo::Create(Context, Operators.pairs()));
8833+
FD->setDefaultedOrDeletedInfo(
8834+
FunctionDecl::DefaultedOrDeletedFunctionInfo::Create(
8835+
Context, Operators.pairs()));
88358836
}
88368837

88378838
// C++2a [class.compare.default]p1:

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4856,7 +4856,7 @@ TemplateDeclInstantiator::InitMethodInstantiation(CXXMethodDecl *New,
48564856
bool TemplateDeclInstantiator::SubstDefaultedFunction(FunctionDecl *New,
48574857
FunctionDecl *Tmpl) {
48584858
// Transfer across any unqualified lookups.
4859-
if (auto *DFI = Tmpl->getExtraFunctionInfo()) {
4859+
if (auto *DFI = Tmpl->getDefalutedOrDeletedInfo()) {
48604860
SmallVector<DeclAccessPair, 32> Lookups;
48614861
Lookups.reserve(DFI->getUnqualifiedLookups().size());
48624862
bool AnyChanged = false;
@@ -4871,10 +4871,10 @@ bool TemplateDeclInstantiator::SubstDefaultedFunction(FunctionDecl *New,
48714871

48724872
// It's unlikely that substitution will change any declarations. Don't
48734873
// store an unnecessary copy in that case.
4874-
New->setExtraFunctionInfo(
4875-
AnyChanged
4876-
? FunctionDecl::ExtraFunctionInfo::Create(SemaRef.Context, Lookups)
4877-
: DFI);
4874+
New->setDefaultedOrDeletedInfo(
4875+
AnyChanged ? FunctionDecl::DefaultedOrDeletedFunctionInfo::Create(
4876+
SemaRef.Context, Lookups)
4877+
: DFI);
48784878
}
48794879

48804880
SemaRef.SetDeclDefaulted(New, Tmpl->getLocation());

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,9 +1110,9 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
11101110
}
11111111

11121112
if (FD->isDefaulted() || FD->isDeletedAsWritten()) {
1113-
// If 'Info' is nonzero, we need to read an ExtraFunctionInfo; if,
1113+
// If 'Info' is nonzero, we need to read an DefaultedOrDeletedInfo; if,
11141114
// additionally, the second bit is also set, we also need to read
1115-
// a DeletedMessage for the ExtraFunctionInfo.
1115+
// a DeletedMessage for the DefaultedOrDeletedInfo.
11161116
if (auto Info = Record.readInt()) {
11171117
bool HasMessage = Info & 2;
11181118
StringLiteral *DeletedMessage =
@@ -1126,8 +1126,9 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
11261126
Lookups.push_back(DeclAccessPair::make(ND, AS));
11271127
}
11281128

1129-
FD->setExtraFunctionInfo(FunctionDecl::ExtraFunctionInfo::Create(
1130-
Reader.getContext(), Lookups, DeletedMessage));
1129+
FD->setDefaultedOrDeletedInfo(
1130+
FunctionDecl::DefaultedOrDeletedFunctionInfo::Create(
1131+
Reader.getContext(), Lookups, DeletedMessage));
11311132
}
11321133
}
11331134

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,9 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
750750
Record.push_back(D->getODRHash());
751751

752752
if (D->isDefaulted() || D->isDeletedAsWritten()) {
753-
if (auto *FDI = D->getExtraFunctionInfo()) {
754-
// Store both that there is an ExtraFunctionInfo and whether it contains
755-
// a DeletedMessage.
753+
if (auto *FDI = D->getDefalutedOrDeletedInfo()) {
754+
// Store both that there is an DefaultedOrDeletedInfo and whether it
755+
// contains a DeletedMessage.
756756
StringLiteral *DeletedMessage = FDI->getDeletedMessage();
757757
Record.push_back(1 | (DeletedMessage ? 2 : 0));
758758
if (DeletedMessage)

clang/test/PCH/cxx2a-defaulted-comparison.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace std {
2222
constexpr strong_ordering strong_ordering::less = {-1};
2323
}
2424

25-
// Ensure that we can round-trip ExtraFunctionInfo through an AST file.
25+
// Ensure that we can round-trip DefaultedOrDeletedInfo through an AST file.
2626
namespace LookupContext {
2727
struct A {};
2828

0 commit comments

Comments
 (0)