Skip to content

Commit 6934655

Browse files
committed
Addressing a few more review comments
Removed the new Type::* methods as the various refactorings have made them unnecessary. Renamed isOperatorNew, Delete, NewOrDelete, etc to say "Any" as while going through adopting them everywhere i noticed a few places where code is checking explicitly for non-array versions of the operators and realised the existing name was a recipe for mistakes. Also adopted the helper function in more places near other changes in this PR.
1 parent 4770cd8 commit 6934655

File tree

14 files changed

+53
-81
lines changed

14 files changed

+53
-81
lines changed

clang/include/clang/AST/DeclarationName.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ class DeclarationName {
477477
return OO_None;
478478
}
479479

480-
bool isOperatorNew() const {
480+
bool isAnyOperatorNew() const {
481481
if (getNameKind() != DeclarationName::CXXOperatorName)
482482
return false;
483483
switch (getCXXOverloadedOperator()) {
@@ -489,7 +489,7 @@ class DeclarationName {
489489
}
490490
}
491491

492-
bool isOperatorDelete() const {
492+
bool isAnyOperatorDelete() const {
493493
if (getNameKind() != DeclarationName::CXXOperatorName)
494494
return false;
495495
switch (getCXXOverloadedOperator()) {
@@ -501,8 +501,8 @@ class DeclarationName {
501501
}
502502
}
503503

504-
bool isOperatorNewOrDelete() const {
505-
return isOperatorNew() || isOperatorDelete();
504+
bool isAnyOperatorNewOrDelete() const {
505+
return isAnyOperatorNew() || isAnyOperatorDelete();
506506
}
507507

508508
/// If this name is the name of a literal operator,

clang/include/clang/AST/Type.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,13 +2636,6 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
26362636
// C++14 decltype(auto)
26372637
bool isTypedefNameType() const; // typedef or alias template
26382638

2639-
bool isDestroyingDeleteT() const; // C++ std::destroying_delete_t
2640-
2641-
/// If this type is a template specialization return the TemplateDecl
2642-
/// that was specialized. It this is not a template specialization,
2643-
/// returns NULL.
2644-
TemplateDecl *getSpecializedTemplateDecl() const;
2645-
26462639
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
26472640
bool is##Id##Type() const;
26482641
#include "clang/Basic/OpenCLImageTypes.def"

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4883,7 +4883,6 @@ class Sema final : public SemaBase {
48834883
EnumDecl *getStdAlignValT() const;
48844884

48854885
TypeAwareAllocationMode ShouldUseTypeAwareOperatorNewOrDelete() const;
4886-
bool isTypeAwareOperatorNewOrDelete(const NamedDecl *FnDecl) const;
48874886
FunctionDecl *BuildTypeAwareUsualDelete(FunctionTemplateDecl *FnDecl,
48884887
QualType AllocType, SourceLocation);
48894888

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4787,7 +4787,7 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
47874787
// Calls to replaceable operator new/operator delete.
47884788
if (FuncDecl &&
47894789
FuncDecl->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
4790-
if (FuncDecl->getDeclName().isOperatorNew()) {
4790+
if (FuncDecl->getDeclName().isAnyOperatorNew()) {
47914791
return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_new);
47924792
} else {
47934793
assert(FuncDecl->getDeclName().getCXXOverloadedOperator() == OO_Delete);

clang/lib/AST/Decl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3363,7 +3363,7 @@ bool FunctionDecl::isMSVCRTEntryPoint() const {
33633363
}
33643364

33653365
bool FunctionDecl::isReservedGlobalPlacementOperator() const {
3366-
if (!getDeclName().isOperatorNewOrDelete())
3366+
if (!getDeclName().isAnyOperatorNewOrDelete())
33673367
return false;
33683368

33693369
if (!getDeclContext()->getRedeclContext()->isTranslationUnit())
@@ -3387,7 +3387,7 @@ bool FunctionDecl::isReservedGlobalPlacementOperator() const {
33873387

33883388
bool FunctionDecl::isUsableAsGlobalAllocationFunctionInConstantEvaluation(
33893389
std::optional<unsigned> *AlignmentParam, bool *IsNothrow) const {
3390-
if (!getDeclName().isOperatorNewOrDelete())
3390+
if (!getDeclName().isAnyOperatorNewOrDelete())
33913391
return false;
33923392

33933393
if (isa<CXXRecordDecl>(getDeclContext()))
@@ -3401,7 +3401,7 @@ bool FunctionDecl::isUsableAsGlobalAllocationFunctionInConstantEvaluation(
34013401
return false;
34023402

34033403
if (isTypeAwareOperatorNewOrDelete()) {
3404-
bool IsDelete = getDeclName().isOperatorDelete();
3404+
bool IsDelete = getDeclName().isAnyOperatorDelete();
34053405
unsigned RequiredParameterCount =
34063406
IsDelete ? FunctionDecl::RequiredTypeAwareDeleteParameterCount
34073407
: FunctionDecl::RequiredTypeAwareNewParameterCount;
@@ -3441,8 +3441,7 @@ bool FunctionDecl::isUsableAsGlobalAllocationFunctionInConstantEvaluation(
34413441
// In C++14, the next parameter can be a 'std::size_t' for sized delete.
34423442
bool IsSizedDelete = false;
34433443
if (Ctx.getLangOpts().SizedDeallocation &&
3444-
(getDeclName().getCXXOverloadedOperator() == OO_Delete ||
3445-
getDeclName().getCXXOverloadedOperator() == OO_Array_Delete) &&
3444+
getDeclName().isAnyOperatorDelete() &&
34463445
Ctx.hasSameType(Ty, Ctx.getSizeType())) {
34473446
IsSizedDelete = true;
34483447
Consume();

clang/lib/AST/DeclCXX.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,8 +2529,7 @@ CXXMethodDecl *CXXMethodDecl::getDevirtualizedMethod(const Expr *Base,
25292529
bool CXXMethodDecl::isUsualDeallocationFunction(
25302530
SmallVectorImpl<const FunctionDecl *> &PreventedBy) const {
25312531
assert(PreventedBy.empty() && "PreventedBy is expected to be empty");
2532-
if (getOverloadedOperator() != OO_Delete &&
2533-
getOverloadedOperator() != OO_Array_Delete)
2532+
if (!getDeclName().isAnyOperatorDelete())
25342533
return false;
25352534

25362535
if (isTypeAwareOperatorNewOrDelete()) {

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8386,7 +8386,7 @@ class ExprEvaluatorBase
83868386
} else
83878387
FD = LambdaCallOp;
83888388
} else if (FD->isUsableAsGlobalAllocationFunctionInConstantEvaluation()) {
8389-
if (FD->getDeclName().isOperatorNew()) {
8389+
if (FD->getDeclName().isAnyOperatorNew()) {
83908390
LValue Ptr;
83918391
if (!HandleOperatorNewCall(Info, E, Ptr))
83928392
return false;

clang/lib/AST/Type.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3133,23 +3133,6 @@ bool Type::isStdByteType() const {
31333133
return false;
31343134
}
31353135

3136-
bool Type::isDestroyingDeleteT() const {
3137-
auto *RD = getAsCXXRecordDecl();
3138-
return RD && RD->isInStdNamespace() && RD->getIdentifier() &&
3139-
RD->getIdentifier()->isStr("destroying_delete_t");
3140-
}
3141-
3142-
TemplateDecl *Type::getSpecializedTemplateDecl() const {
3143-
auto UnderlyingType = getCanonicalTypeInternal();
3144-
if (auto *TST = UnderlyingType->getAs<TemplateSpecializationType>())
3145-
return TST->getTemplateName().getAsTemplateDecl();
3146-
if (auto *RT = UnderlyingType->getAsCXXRecordDecl()) {
3147-
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RT))
3148-
return CTSD->getSpecializedTemplate();
3149-
}
3150-
return nullptr;
3151-
}
3152-
31533136
bool Type::isSpecifierType() const {
31543137
// Note that this intentionally does not use the canonical type.
31553138
switch (getTypeClass()) {

clang/lib/Sema/SemaCoroutine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ static bool DiagnoseTypeAwareAllocators(Sema &S, SourceLocation Loc,
11101110
S.LookupQualifiedName(R, PromiseType->getAsCXXRecordDecl());
11111111
bool HaveIssuedWarning = false;
11121112
for (auto Decl : R) {
1113-
if (!S.isTypeAwareOperatorNewOrDelete(Decl))
1113+
if (!Decl->getAsFunction()->isTypeAwareOperatorNewOrDelete())
11141114
continue;
11151115
if (!HaveIssuedWarning) {
11161116
S.Diag(Loc, DiagnosticID) << Name;

clang/lib/Sema/SemaDecl.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10175,10 +10175,7 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1017510175
// deallocation function shall not be declared with the consteval
1017610176
// specifier.
1017710177
if (ConstexprKind == ConstexprSpecKind::Consteval &&
10178-
(NewFD->getOverloadedOperator() == OO_New ||
10179-
NewFD->getOverloadedOperator() == OO_Array_New ||
10180-
NewFD->getOverloadedOperator() == OO_Delete ||
10181-
NewFD->getOverloadedOperator() == OO_Array_Delete)) {
10178+
NewFD->getDeclName().isAnyOperatorNewOrDelete()) {
1018210179
Diag(D.getDeclSpec().getConstexprSpecLoc(),
1018310180
diag::err_invalid_consteval_decl_kind)
1018410181
<< NewFD;
@@ -10282,9 +10279,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1028210279
// A deallocation function with no exception-specification is treated
1028310280
// as if it were specified with noexcept(true).
1028410281
const FunctionProtoType *FPT = R->getAs<FunctionProtoType>();
10285-
if ((Name.getCXXOverloadedOperator() == OO_Delete ||
10286-
Name.getCXXOverloadedOperator() == OO_Array_Delete) &&
10287-
getLangOpts().CPlusPlus11 && FPT && !FPT->hasExceptionSpec())
10282+
if (Name.isAnyOperatorDelete() && getLangOpts().CPlusPlus11 && FPT &&
10283+
!FPT->hasExceptionSpec())
1028810284
NewFD->setType(Context.getFunctionType(
1028910285
FPT->getReturnType(), FPT->getParamTypes(),
1029010286
FPT->getExtProtoInfo().withExceptionSpec(EST_BasicNoexcept)));

0 commit comments

Comments
 (0)