Skip to content

Commit 953c2e9

Browse files
committed
Start migrating to bits on funcdecl
1 parent 435d617 commit 953c2e9

File tree

14 files changed

+160
-96
lines changed

14 files changed

+160
-96
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,12 @@ class FunctionDecl : public DeclaratorDecl,
25602560
bool isInlineBuiltinDeclaration() const;
25612561

25622562
/// Determine whether this is a destroying operator delete.
2563-
bool isDestroyingOperatorDelete() const;
2563+
bool isDestroyingOperatorDelete() const {
2564+
return FunctionDeclBits.IsDestroyingOperatorDelete;
2565+
}
2566+
void setIsDestroyingOperatorDelete(bool IsDestroyingDelete) {
2567+
FunctionDeclBits.IsDestroyingOperatorDelete = IsDestroyingDelete;
2568+
}
25642569

25652570
/// Count of mandatory parameters for type aware operator new
25662571
static constexpr unsigned RequiredTypeAwareNewParameterCount =
@@ -2572,7 +2577,12 @@ class FunctionDecl : public DeclaratorDecl,
25722577
/* alignment */ 1;
25732578

25742579
/// Determine whether this is a type aware operator new or delete.
2575-
bool isTypeAwareOperatorNewOrDelete() const;
2580+
bool isTypeAwareOperatorNewOrDelete() const {
2581+
return FunctionDeclBits.IsTypeAwareOperatorNewOrDelete;
2582+
}
2583+
void setIsTypeAwareOperatorNewOrDelete(bool IsTypeAwareOperator = true) {
2584+
FunctionDeclBits.IsTypeAwareOperatorNewOrDelete = IsTypeAwareOperator;
2585+
}
25762586

25772587
/// Compute the language linkage.
25782588
LanguageLinkage getLanguageLinkage() const;

clang/include/clang/AST/DeclBase.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,10 +1829,18 @@ class DeclContext {
18291829
// refers to an enclosing template for hte purposes of [temp.friend]p9.
18301830
LLVM_PREFERRED_TYPE(bool)
18311831
uint64_t FriendConstraintRefersToEnclosingTemplate : 1;
1832+
1833+
// Indicates this function is type aware operator new or delete
1834+
LLVM_PREFERRED_TYPE(bool)
1835+
uint64_t IsDestroyingOperatorDelete : 1;
1836+
1837+
// Indicates this function is type aware operator new or delete
1838+
LLVM_PREFERRED_TYPE(bool)
1839+
uint64_t IsTypeAwareOperatorNewOrDelete : 1;
18321840
};
18331841

18341842
/// Number of inherited and non-inherited bits in FunctionDeclBitfields.
1835-
enum { NumFunctionDeclBits = NumDeclContextBits + 32 };
1843+
enum { NumFunctionDeclBits = NumDeclContextBits + 34 };
18361844

18371845
/// Stores the bits used by CXXConstructorDecl. If modified
18381846
/// NumCXXConstructorDeclBits and the accessor
@@ -1843,12 +1851,12 @@ class DeclContext {
18431851
LLVM_PREFERRED_TYPE(FunctionDeclBitfields)
18441852
uint64_t : NumFunctionDeclBits;
18451853

1846-
/// 19 bits to fit in the remaining available space.
1854+
/// 17 bits to fit in the remaining available space.
18471855
/// Note that this makes CXXConstructorDeclBitfields take
18481856
/// exactly 64 bits and thus the width of NumCtorInitializers
18491857
/// will need to be shrunk if some bit is added to NumDeclContextBitfields,
18501858
/// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
1851-
uint64_t NumCtorInitializers : 16;
1859+
uint64_t NumCtorInitializers : 14;
18521860
LLVM_PREFERRED_TYPE(bool)
18531861
uint64_t IsInheritingConstructor : 1;
18541862

@@ -1862,7 +1870,9 @@ class DeclContext {
18621870
};
18631871

18641872
/// Number of inherited and non-inherited bits in CXXConstructorDeclBitfields.
1865-
enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 19 };
1873+
enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 17 };
1874+
static_assert(NumCXXConstructorDeclBits == 64);
1875+
static_assert(sizeof(CXXConstructorDeclBitfields) == 8);
18661876

18671877
/// Stores the bits used by ObjCMethodDecl.
18681878
/// If modified NumObjCMethodDeclBits and the accessor

clang/include/clang/AST/Type.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,8 +2636,7 @@ 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-
bool isTypeIdentitySpecialization() const; // std::type_identity<X> for any X
2639+
bool isDestroyingDeleteT() const; // C++ std::destroying_delete_t
26412640

26422641
/// If this type is a template specialization return the TemplateDecl
26432642
/// that was specialized. It this is not a template specialization,

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4913,6 +4913,8 @@ class Sema final : public SemaBase {
49134913
/// it is and Element is not NULL, assigns the element type to Element.
49144914
bool isStdInitializerList(QualType Ty, QualType *Element);
49154915

4916+
bool isStdTypeIdentity(QualType Ty, QualType *TypeArgument);
4917+
49164918
/// Looks for the std::initializer_list template and instantiates it
49174919
/// with Element, or emits an error if it's not found.
49184920
///

clang/include/clang/Serialization/ASTWriter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ class BitsPacker {
10721072
UnderlyingValue |= Value << CurrentBitIndex;
10731073
CurrentBitIndex += BitsWidth;
10741074
}
1075+
uint32_t currentBitCount() const { return CurrentBitIndex; }
10751076

10761077
operator uint32_t() { return UnderlyingValue; }
10771078

clang/lib/AST/ASTImporter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4051,6 +4051,9 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
40514051
ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
40524052
ToFunction->setFriendConstraintRefersToEnclosingTemplate(
40534053
D->FriendConstraintRefersToEnclosingTemplate());
4054+
ToFunction->setIsDestroyingOperatorDelete(D->isDestroyingOperatorDelete());
4055+
ToFunction->setIsTypeAwareOperatorNewOrDelete(
4056+
D->isTypeAwareOperatorNewOrDelete());
40544057
ToFunction->setRangeEnd(ToEndLoc);
40554058
ToFunction->setDefaultLoc(ToDefaultLoc);
40564059

clang/lib/AST/Decl.cpp

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,6 +3083,9 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC,
30833083
static_cast<unsigned char>(DeductionCandidate::Normal);
30843084
FunctionDeclBits.HasODRHash = false;
30853085
FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate = false;
3086+
FunctionDeclBits.IsDestroyingOperatorDelete = false;
3087+
FunctionDeclBits.IsTypeAwareOperatorNewOrDelete = false;
3088+
30863089
if (TrailingRequiresClause)
30873090
setTrailingRequiresClause(TrailingRequiresClause);
30883091
}
@@ -3368,11 +3371,12 @@ bool FunctionDecl::isReservedGlobalPlacementOperator() const {
33683371
if (!getDeclContext()->getRedeclContext()->isTranslationUnit())
33693372
return false;
33703373

3374+
if (isTypeAwareOperatorNewOrDelete())
3375+
return false;
3376+
33713377
const auto *proto = getType()->castAs<FunctionProtoType>();
33723378
if (proto->getNumParams() != 2 || proto->isVariadic())
33733379
return false;
3374-
if (proto->getParamType(0)->isTypeIdentitySpecialization())
3375-
return false;
33763380

33773381
const ASTContext &Context =
33783382
cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext())
@@ -3509,34 +3513,6 @@ bool FunctionDecl::isInlineBuiltinDeclaration() const {
35093513
llvm_unreachable("Unknown GVALinkage");
35103514
}
35113515

3512-
bool FunctionDecl::isDestroyingOperatorDelete() const {
3513-
// C++ P0722:
3514-
// Within a class C, a single object deallocation function with signature
3515-
// (T, std::destroying_delete_t, <more params>)
3516-
// is a destroying operator delete.
3517-
if (!isa<CXXMethodDecl>(this) || getOverloadedOperator() != OO_Delete ||
3518-
getNumParams() < 2)
3519-
return false;
3520-
3521-
if (isTypeAwareOperatorNewOrDelete())
3522-
return false;
3523-
3524-
return getParamDecl(1)->getType()->isDestroyingDeleteT();
3525-
}
3526-
3527-
bool FunctionDecl::isTypeAwareOperatorNewOrDelete() const {
3528-
if (getDeclName().isOperatorNew()) {
3529-
if (getNumParams() < FunctionDecl::RequiredTypeAwareNewParameterCount)
3530-
return false;
3531-
} else if (getDeclName().isOperatorDelete()) {
3532-
if (getNumParams() < FunctionDecl::RequiredTypeAwareDeleteParameterCount)
3533-
return false;
3534-
} else
3535-
return false;
3536-
3537-
return getParamDecl(0)->getType()->isTypeIdentitySpecialization();
3538-
}
3539-
35403516
LanguageLinkage FunctionDecl::getLanguageLinkage() const {
35413517
return getDeclLanguageLinkage(*this);
35423518
}

clang/lib/AST/Type.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,14 +3150,6 @@ TemplateDecl *Type::getSpecializedTemplateDecl() const {
31503150
return nullptr;
31513151
}
31523152

3153-
bool Type::isTypeIdentitySpecialization() const {
3154-
const TemplateDecl *STDecl = getSpecializedTemplateDecl();
3155-
if (!STDecl)
3156-
return false;
3157-
IdentifierInfo *II = STDecl->getIdentifier();
3158-
return STDecl->isInStdNamespace() && II->isStr("type_identity");
3159-
}
3160-
31613153
bool Type::isSpecifierType() const {
31623154
// Note that this intentionally does not use the canonical type.
31633155
switch (getTypeClass()) {

0 commit comments

Comments
 (0)