Skip to content

Commit dbe0f5f

Browse files
committed
More cleanup following mandatory arguments, responding to review comments
1 parent ded826b commit dbe0f5f

28 files changed

+212
-374
lines changed

clang/docs/CXXTypeAwareAllocators.rst

Lines changed: 0 additions & 227 deletions
This file was deleted.

clang/docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Using Clang as a Compiler
6161
APINotes
6262
DebuggingCoroutines
6363
AMDGPUSupport
64-
CXXTypeAwareAllocators
6564
CommandGuide/index
6665
FAQ
6766

clang/include/clang/AST/Type.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2637,6 +2637,7 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
26372637
bool isTypedefNameType() const; // typedef or alias template
26382638

26392639
bool isTypeIdentitySpecialization() const; // std::type_identity<X> for any X
2640+
bool isDestroyingDeleteT() const;
26402641

26412642
TemplateDecl *TryGetSpecializedTemplateDecl() const;
26422643

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9839,10 +9839,14 @@ def err_operator_delete_param_type : Error<
98399839
def err_destroying_operator_delete_not_usual : Error<
98409840
"destroying operator delete can have only an optional size and optional "
98419841
"alignment parameter">;
9842+
98429843
def err_type_aware_destroying_operator_delete : Error<
9843-
"type aware destroying delete is not permitted, enable with '-fexperimental-cxx-type-aware-destroying-delete'">;
9844+
"type aware destroying delete is not permitted in C++26">;
98449845
def err_unsupported_type_aware_allocator : Error<
9845-
"type aware allocation operators are disabled, enable with '-fexperimental-cxx-type-aware-allocators'">;
9846+
"type aware allocation operators are disabled, enable with '-fcxx-type-aware-allocators'">;
9847+
def warn_cxx26_type_aware_allocator : Warning<
9848+
"use or declaration of type aware allocators are incompatible with C++ standards before C++26">,
9849+
DefaultIgnore, InGroup<CXXPre26Compat>;
98469850
def err_no_type_aware_cleanup_operator_delete : Error<
98479851
"type aware %0 requires there to be a corresponding cleanup %1 in %2">;
98489852
def err_type_aware_cleanup_deallocator_context_mismatch : Error<

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ defvar cpp14 = LangOpts<"CPlusPlus14">;
624624
defvar cpp17 = LangOpts<"CPlusPlus17">;
625625
defvar cpp20 = LangOpts<"CPlusPlus20">;
626626
defvar cpp23 = LangOpts<"CPlusPlus23">;
627+
defvar cpp26 = LangOpts<"CPlusPlus26">;
627628
defvar c99 = LangOpts<"C99">;
628629
defvar c23 = LangOpts<"C23">;
629630
defvar lang_std = LangOpts<"LangStd">;
@@ -3521,9 +3522,9 @@ def : Flag<["-"], "faligned-new">, Alias<faligned_allocation>;
35213522
def : Flag<["-"], "fno-aligned-new">, Alias<fno_aligned_allocation>;
35223523
def faligned_new_EQ : Joined<["-"], "faligned-new=">;
35233524

3524-
defm cxx_type_aware_allocators : BoolFOption<"experimental-cxx-type-aware-allocators",
3525-
LangOpts<"TypeAwareAllocators">, DefaultFalse,
3526-
PosFlag<SetTrue, [], [ClangOption], "Enable experimental C++ type aware allocator operators">,
3525+
defm cxx_type_aware_allocators : BoolFOption<"cxx-type-aware-allocators",
3526+
LangOpts<"TypeAwareAllocators">, Default<cpp26.KeyPath>,
3527+
PosFlag<SetTrue, [], [ClangOption], "Enable C++26 type aware allocator operators">,
35273528
NegFlag<SetFalse>, BothFlags<[], [ClangOption, CC1Option]>>;
35283529
def fobjc_legacy_dispatch : Flag<["-"], "fobjc-legacy-dispatch">, Group<f_Group>;
35293530
def fobjc_new_property : Flag<["-"], "fobjc-new-property">, Group<clang_ignored_f_Group>;

clang/lib/AST/Decl.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3395,22 +3395,36 @@ bool FunctionDecl::isUsableAsGlobalAllocationFunctionInConstantEvaluation(
33953395
if (!getDeclContext()->getRedeclContext()->isTranslationUnit())
33963396
return false;
33973397

3398-
bool IsTypeAware = isTypeAwareOperatorNewOrDelete();
3399-
// address, (size or hot_cold_t), alignment, no_throw_t
3400-
unsigned MaxImplicitParameters = 4;
3401-
unsigned MaxParamCount = IsTypeAware + MaxImplicitParameters;
3398+
if (isVariadic())
3399+
return false;
3400+
3401+
if (isTypeAwareOperatorNewOrDelete()) {
3402+
bool IsDelete = getDeclName().isOperatorDelete();
3403+
unsigned RequiredParameterCount = IsDelete ? FunctionDecl::RequiredTypeAwareDeleteParameterCount : FunctionDecl::RequiredTypeAwareNewParameterCount;
3404+
if (AlignmentParam)
3405+
*AlignmentParam = /* type identity */ 1 + /* address */ IsDelete + /* size */ 1;
3406+
if (RequiredParameterCount == getNumParams())
3407+
return true;
3408+
if (getNumParams() > RequiredParameterCount + 1)
3409+
return false;
3410+
if (!getParamDecl(RequiredParameterCount)->getType()->isNothrowT())
3411+
return false;
3412+
3413+
if (IsNothrow)
3414+
*IsNothrow = true;
3415+
return true;
3416+
}
3417+
34023418
const auto *FPT = getType()->castAs<FunctionProtoType>();
3403-
if (FPT->getNumParams() == 0 || FPT->getNumParams() > MaxParamCount ||
3404-
FPT->isVariadic())
3419+
if (FPT->getNumParams() == 0 || FPT->getNumParams() > 4)
34053420
return false;
34063421

3407-
unsigned MinimumParamCount = IsTypeAware + 1;
34083422
// If this is a single-parameter function, it must be a replaceable global
34093423
// allocation or deallocation function.
3410-
if (FPT->getNumParams() == MinimumParamCount)
3424+
if (FPT->getNumParams() == 1)
34113425
return true;
34123426

3413-
unsigned Params = MinimumParamCount;
3427+
unsigned Params = 1;
34143428
QualType Ty = FPT->getParamType(Params);
34153429
const ASTContext &Ctx = getASTContext();
34163430

@@ -3421,7 +3435,7 @@ bool FunctionDecl::isUsableAsGlobalAllocationFunctionInConstantEvaluation(
34213435

34223436
// In C++14, the next parameter can be a 'std::size_t' for sized delete.
34233437
bool IsSizedDelete = false;
3424-
if ((IsTypeAware || Ctx.getLangOpts().SizedDeallocation) &&
3438+
if (Ctx.getLangOpts().SizedDeallocation &&
34253439
(getDeclName().getCXXOverloadedOperator() == OO_Delete ||
34263440
getDeclName().getCXXOverloadedOperator() == OO_Array_Delete) &&
34273441
Ctx.hasSameType(Ty, Ctx.getSizeType())) {
@@ -3431,8 +3445,7 @@ bool FunctionDecl::isUsableAsGlobalAllocationFunctionInConstantEvaluation(
34313445

34323446
// In C++17, the next parameter can be a 'std::align_val_t' for aligned
34333447
// new/delete.
3434-
if ((IsTypeAware || Ctx.getLangOpts().AlignedAllocation) && !Ty.isNull() &&
3435-
Ty->isAlignValT()) {
3448+
if (Ctx.getLangOpts().AlignedAllocation && !Ty.isNull() && Ty->isAlignValT()) {
34363449
Consume();
34373450
if (AlignmentParam)
34383451
*AlignmentParam = Params;
@@ -3505,9 +3518,7 @@ bool FunctionDecl::isDestroyingOperatorDelete() const {
35053518
if (isTypeAwareOperatorNewOrDelete())
35063519
return false;
35073520

3508-
auto *RD = getParamDecl(1)->getType()->getAsCXXRecordDecl();
3509-
return RD && RD->isInStdNamespace() && RD->getIdentifier() &&
3510-
RD->getIdentifier()->isStr("destroying_delete_t");
3521+
return getParamDecl(1)->getType()->isDestroyingDeleteT();
35113522
}
35123523

35133524
bool FunctionDecl::isTypeAwareOperatorNewOrDelete() const {

clang/lib/AST/Type.cpp

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

3137+
bool Type::isDestroyingDeleteT() const {
3138+
auto *RD = getAsCXXRecordDecl();
3139+
return RD && RD->isInStdNamespace() && RD->getIdentifier() &&
3140+
RD->getIdentifier()->isStr("destroying_delete_t");
3141+
}
3142+
31373143
TemplateDecl *Type::TryGetSpecializedTemplateDecl() const {
31383144
auto UnderlyingType = getCanonicalTypeInternal();
31393145
if (auto *TST = UnderlyingType->getAs<TemplateSpecializationType>())

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7188,9 +7188,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
71887188
types::isCXX(InputType))
71897189
CmdArgs.push_back("-fcoro-aligned-allocation");
71907190

7191-
if (Args.hasFlag(options::OPT_fcxx_type_aware_allocators,
7192-
options::OPT_fno_cxx_type_aware_allocators, false))
7193-
CmdArgs.push_back("-fexperimental-cxx-type-aware-allocators");
7191+
if (Arg *A = Args.getLastArg(options::OPT_fcxx_type_aware_allocators,
7192+
options::OPT_fno_cxx_type_aware_allocators)) {
7193+
if (A->getOption().matches(options::OPT_fno_cxx_type_aware_allocators))
7194+
CmdArgs.push_back("-fno-cxx-type-aware-allocators");
7195+
else
7196+
CmdArgs.push_back("-fcxx-type-aware-allocators");
7197+
}
71947198

71957199
Args.AddLastArg(CmdArgs, options::OPT_fdouble_square_bracket_attributes,
71967200
options::OPT_fno_double_square_bracket_attributes);

0 commit comments

Comments
 (0)