Skip to content

Commit 4770cd8

Browse files
committed
Migrate off the extra bits in FunctionDecl
Now record the information in ASTContext, this has the handy effect of allowing us to short circuit any consideration of type aware allocators entirely, though future refactoring of the operator resolution logic will likely make that less irksome.
1 parent 953c2e9 commit 4770cd8

File tree

13 files changed

+181
-88
lines changed

13 files changed

+181
-88
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ class ASTContext : public RefCountedBase<ASTContext> {
329329
/// This is lazily created. This is intentionally not serialized.
330330
mutable llvm::StringMap<StringLiteral *> StringLiteralCache;
331331

332+
mutable llvm::DenseSet<const FunctionDecl *> DestroyingOperatorDeletes;
333+
mutable llvm::DenseSet<const FunctionDecl *> TypeAwareOperatorNewAndDeletes;
334+
332335
/// The next string literal "version" to allocate during constant evaluation.
333336
/// This is used to distinguish between repeated evaluations of the same
334337
/// string literal.
@@ -3337,6 +3340,15 @@ class ASTContext : public RefCountedBase<ASTContext> {
33373340
void setStaticLocalNumber(const VarDecl *VD, unsigned Number);
33383341
unsigned getStaticLocalNumber(const VarDecl *VD) const;
33393342

3343+
bool hasSeenTypeAwareOperatorNewOrDelete() const {
3344+
return !TypeAwareOperatorNewAndDeletes.empty();
3345+
}
3346+
void setIsDestroyingOperatorDelete(const FunctionDecl *FD, bool IsDestroying);
3347+
bool isDestroyingOperatorDelete(const FunctionDecl *FD) const;
3348+
void setIsTypeAwareOperatorNewOrDelete(const FunctionDecl *FD,
3349+
bool IsTypeAware);
3350+
bool isTypeAwareOperatorNewOrDelete(const FunctionDecl *FD) const;
3351+
33403352
/// Retrieve the context for computing mangling numbers in the given
33413353
/// DeclContext.
33423354
MangleNumberingContext &getManglingNumberContext(const DeclContext *DC);

clang/include/clang/AST/Decl.h

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,13 +2541,19 @@ class FunctionDecl : public DeclaratorDecl,
25412541
/// This adds support for potentially templated type aware global allocation
25422542
/// functions of the form:
25432543
/// void *operator new(type-identity, std::size_t, std::align_val_t)
2544-
/// void *operator new(type-identity, std::size_t, std::align_val_t, const std::nothrow_t &) noexcept;
2544+
/// void *operator new(type-identity, std::size_t, std::align_val_t,
2545+
/// const std::nothrow_t &) noexcept;
25452546
/// void *operator new[](type-identity, std::size_t, std::align_val_t)
2546-
/// void *operator new[](type-identity, std::size_t, std::align_val_t, const std::nothrow_t &) noexcept;
2547-
/// void operator delete(type-identity, void*, std::size_t, std::align_val_t) noexcept;
2548-
/// void operator delete(type-identity, void*, std::size_t, std::align_val_t, const std::nothrow_t &) noexcept;
2549-
/// void operator delete[](type-identity, void*, std::size_t, std::align_val_t) noexcept;
2550-
/// void operator delete[](type-identity, void*, std::size_t, std::align_val_t, const std::nothrow_t &) noexcept;
2547+
/// void *operator new[](type-identity, std::size_t, std::align_val_t,
2548+
/// const std::nothrow_t &) noexcept;
2549+
/// void operator delete(type-identity, void*, std::size_t,
2550+
/// std::align_val_t) noexcept;
2551+
/// void operator delete(type-identity, void*, std::size_t,
2552+
/// std::align_val_t, const std::nothrow_t&) noexcept;
2553+
/// void operator delete[](type-identity, void*, std::size_t,
2554+
/// std::align_val_t) noexcept;
2555+
/// void operator delete[](type-identity, void*, std::size_t,
2556+
/// std::align_val_t, const std::nothrow_t&) noexcept;
25512557
/// Where `type-identity` is a specialization of std::type_identity. If the
25522558
/// declaration is a templated function, it may not include a parameter pack
25532559
/// in the argument list, the type-identity parameter is required to be
@@ -2560,12 +2566,8 @@ class FunctionDecl : public DeclaratorDecl,
25602566
bool isInlineBuiltinDeclaration() const;
25612567

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

25702572
/// Count of mandatory parameters for type aware operator new
25712573
static constexpr unsigned RequiredTypeAwareNewParameterCount =
@@ -2577,12 +2579,8 @@ class FunctionDecl : public DeclaratorDecl,
25772579
/* alignment */ 1;
25782580

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

25872585
/// Compute the language linkage.
25882586
LanguageLinkage getLanguageLinkage() const;

clang/include/clang/AST/DeclBase.h

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,18 +1829,10 @@ 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;
18401832
};
18411833

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

18451837
/// Stores the bits used by CXXConstructorDecl. If modified
18461838
/// NumCXXConstructorDeclBits and the accessor
@@ -1851,12 +1843,12 @@ class DeclContext {
18511843
LLVM_PREFERRED_TYPE(FunctionDeclBitfields)
18521844
uint64_t : NumFunctionDeclBits;
18531845

1854-
/// 17 bits to fit in the remaining available space.
1846+
/// 19 bits to fit in the remaining available space.
18551847
/// Note that this makes CXXConstructorDeclBitfields take
18561848
/// exactly 64 bits and thus the width of NumCtorInitializers
18571849
/// will need to be shrunk if some bit is added to NumDeclContextBitfields,
18581850
/// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
1859-
uint64_t NumCtorInitializers : 14;
1851+
uint64_t NumCtorInitializers : 16;
18601852
LLVM_PREFERRED_TYPE(bool)
18611853
uint64_t IsInheritingConstructor : 1;
18621854

@@ -1870,9 +1862,7 @@ class DeclContext {
18701862
};
18711863

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

18771867
/// Stores the bits used by ObjCMethodDecl.
18781868
/// If modified NumObjCMethodDeclBits and the accessor

clang/include/clang/Sema/Sema.h

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

4885+
TypeAwareAllocationMode ShouldUseTypeAwareOperatorNewOrDelete() const;
48854886
bool isTypeAwareOperatorNewOrDelete(const NamedDecl *FnDecl) const;
48864887
FunctionDecl *BuildTypeAwareUsualDelete(FunctionTemplateDecl *FnDecl,
48874888
QualType AllocType, SourceLocation);
@@ -4913,7 +4914,13 @@ class Sema final : public SemaBase {
49134914
/// it is and Element is not NULL, assigns the element type to Element.
49144915
bool isStdInitializerList(QualType Ty, QualType *Element);
49154916

4916-
bool isStdTypeIdentity(QualType Ty, QualType *TypeArgument);
4917+
/// Tests whether Ty is an instance of std::type_identity and, if
4918+
/// it is and TypeArgument is not NULL, assigns the element type to Element.
4919+
/// If MalformedDecl is not null, and type_identity was ruled out due to being
4920+
/// incorrectly structured despite having the correct name, the faulty Decl
4921+
/// will be assigned to MalformedDecl.
4922+
bool isStdTypeIdentity(QualType Ty, QualType *TypeArgument,
4923+
const Decl **MalformedDecl = nullptr);
49174924

49184925
/// Looks for the std::initializer_list template and instantiates it
49194926
/// with Element, or emits an error if it's not found.

clang/include/clang/Serialization/ASTWriter.h

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

10771076
operator uint32_t() { return UnderlyingValue; }
10781077

clang/lib/AST/ASTContext.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13117,6 +13117,31 @@ unsigned ASTContext::getStaticLocalNumber(const VarDecl *VD) const {
1311713117
return I != StaticLocalNumbers.end() ? I->second : 1;
1311813118
}
1311913119

13120+
void ASTContext::setIsDestroyingOperatorDelete(const FunctionDecl *FD,
13121+
bool IsDestroying) {
13122+
if (!IsDestroying) {
13123+
assert(!DestroyingOperatorDeletes.contains(FD->getCanonicalDecl()));
13124+
return;
13125+
}
13126+
DestroyingOperatorDeletes.insert(FD->getCanonicalDecl());
13127+
}
13128+
13129+
bool ASTContext::isDestroyingOperatorDelete(const FunctionDecl *FD) const {
13130+
return DestroyingOperatorDeletes.contains(FD->getCanonicalDecl());
13131+
}
13132+
void ASTContext::setIsTypeAwareOperatorNewOrDelete(const FunctionDecl *FD,
13133+
bool IsTypeAware) {
13134+
if (!IsTypeAware) {
13135+
assert(!TypeAwareOperatorNewAndDeletes.contains(FD->getCanonicalDecl()));
13136+
return;
13137+
}
13138+
TypeAwareOperatorNewAndDeletes.insert(FD->getCanonicalDecl());
13139+
}
13140+
13141+
bool ASTContext::isTypeAwareOperatorNewOrDelete(const FunctionDecl *FD) const {
13142+
return TypeAwareOperatorNewAndDeletes.contains(FD->getCanonicalDecl());
13143+
}
13144+
1312013145
MangleNumberingContext &
1312113146
ASTContext::getManglingNumberContext(const DeclContext *DC) {
1312213147
assert(LangOpts.CPlusPlus); // We don't need mangling numbers for plain C.

clang/lib/AST/Decl.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,8 +3083,6 @@ 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;
30883086

30893087
if (TrailingRequiresClause)
30903088
setTrailingRequiresClause(TrailingRequiresClause);
@@ -3513,6 +3511,22 @@ bool FunctionDecl::isInlineBuiltinDeclaration() const {
35133511
llvm_unreachable("Unknown GVALinkage");
35143512
}
35153513

3514+
bool FunctionDecl::isDestroyingOperatorDelete() const {
3515+
return getASTContext().isDestroyingOperatorDelete(this);
3516+
}
3517+
3518+
void FunctionDecl::setIsDestroyingOperatorDelete(bool IsDestroyingDelete) {
3519+
getASTContext().setIsDestroyingOperatorDelete(this, IsDestroyingDelete);
3520+
}
3521+
3522+
bool FunctionDecl::isTypeAwareOperatorNewOrDelete() const {
3523+
return getASTContext().isTypeAwareOperatorNewOrDelete(this);
3524+
}
3525+
3526+
void FunctionDecl::setIsTypeAwareOperatorNewOrDelete(bool IsTypeAware) {
3527+
getASTContext().setIsTypeAwareOperatorNewOrDelete(this, IsTypeAware);
3528+
}
3529+
35163530
LanguageLinkage FunctionDecl::getLanguageLinkage() const {
35173531
return getDeclLanguageLinkage(*this);
35183532
}

clang/lib/Sema/SemaCoroutine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ static bool findDeleteForPromise(Sema &S, SourceLocation Loc, QualType PromiseTy
11431143
ImplicitDeallocationParameters IDP = {
11441144
alignedAllocationModeFromBool(Overaligned), SizedDeallocationMode::Yes};
11451145
if (S.FindDeallocationFunction(Loc, PointeeRD, DeleteName, OperatorDelete,
1146-
IDP, /*Diagnose*/ true))
1146+
IDP, /*Diagnose=*/true))
11471147
return false;
11481148

11491149
// [dcl.fct.def.coroutine]p12
@@ -1476,11 +1476,11 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
14761476

14771477
FunctionDecl *UnusedResult = nullptr;
14781478
S.FindAllocationFunctions(Loc, SourceRange(), NewScope,
1479-
/*DeleteScope*/ Sema::AFS_Both, PromiseType,
1480-
/*isArray*/ false, IAP,
1479+
/*DeleteScope=*/Sema::AFS_Both, PromiseType,
1480+
/*isArray=*/false, IAP,
14811481
WithoutPlacementArgs ? MultiExprArg{}
14821482
: PlacementArgs,
1483-
OperatorNew, UnusedResult, /*Diagnose*/ false);
1483+
OperatorNew, UnusedResult, /*Diagnose=*/false);
14841484
assert(!OperatorNew || !OperatorNew->isTypeAwareOperatorNewOrDelete());
14851485
};
14861486

0 commit comments

Comments
 (0)