Skip to content

Commit 19f69d0

Browse files
committed
More updates and clang-format
1 parent 302840d commit 19f69d0

File tree

10 files changed

+64
-61
lines changed

10 files changed

+64
-61
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,8 @@ class FunctionDecl : public DeclaratorDecl,
25252525
bool *IsNothrow = nullptr) const {
25262526
if (isTypeAwareOperatorNewOrDelete())
25272527
return false;
2528-
return isConstEvalSafeOrReplaceableGlobalAllocationFunction(AlignmentParam, IsNothrow);
2528+
return isConstEvalSafeOrReplaceableGlobalAllocationFunction(AlignmentParam,
2529+
IsNothrow);
25292530
}
25302531

25312532
/// Determines whether this function is one of the replaceable global

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3545,11 +3545,11 @@ def : Flag<["-"], "fno-aligned-new">, Alias<fno_aligned_allocation>;
35453545
def faligned_new_EQ : Joined<["-"], "faligned-new=">;
35463546
defm cxx_type_aware_allocators : BoolFOption<"experimental-cxx-type-aware-allocators",
35473547
LangOpts<"TypeAwareAllocators">, DefaultFalse,
3548-
PosFlag<SetTrue, [], [ClangOption], "Enable experimental C++YY type aware allocator operators">,
3548+
PosFlag<SetTrue, [], [ClangOption], "Enable experimental C++ type aware allocator operators">,
35493549
NegFlag<SetFalse>, BothFlags<[], [ClangOption, CC1Option]>>;
35503550
defm cxx_type_aware_destroying_delete : BoolFOption<"experimental-cxx-type-aware-destroying-delete",
35513551
LangOpts<"TypeAwareDestroyingDelete">, DefaultFalse,
3552-
PosFlag<SetTrue, [], [ClangOption], "Enable experimental C++YY type aware allocator operators for destroying delete">,
3552+
PosFlag<SetTrue, [], [ClangOption], "Enable experimental C++ type aware allocator operators for destroying delete">,
35533553
NegFlag<SetFalse>, BothFlags<[], [ClangOption, CC1Option]>>;
35543554
def fobjc_legacy_dispatch : Flag<["-"], "fobjc-legacy-dispatch">, Group<f_Group>;
35553555
def fobjc_new_property : Flag<["-"], "fobjc-new-property">, Group<clang_ignored_f_Group>;

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,7 +3304,8 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
33043304
// Always invalid.
33053305
return this->emitInvalid(E);
33063306
}
3307-
} else if (!OperatorNew->isConstEvalSafeOrReplaceableGlobalAllocationFunction())
3307+
} else if (!OperatorNew
3308+
->isConstEvalSafeOrReplaceableGlobalAllocationFunction())
33083309
return this->emitInvalidNewDeleteExpr(E, E);
33093310

33103311
const Descriptor *Desc;
@@ -4559,7 +4560,8 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
45594560

45604561
const FunctionDecl *FuncDecl = E->getDirectCallee();
45614562
// Calls to replaceable operator new/operator delete.
4562-
if (FuncDecl && FuncDecl->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
4563+
if (FuncDecl &&
4564+
FuncDecl->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
45634565
if (FuncDecl->getDeclName().getCXXOverloadedOperator() == OO_New ||
45644566
FuncDecl->getDeclName().getCXXOverloadedOperator() == OO_Array_New) {
45654567
return VisitBuiltinCallExpr(E, Builtin::BI__builtin_operator_new);

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,8 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
10631063
if (const FunctionDecl *VirtualDelete =
10641064
getVirtualOperatorDelete(AllocType);
10651065
VirtualDelete &&
1066-
!VirtualDelete->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
1066+
!VirtualDelete
1067+
->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
10671068
S.FFDiag(S.Current->getSource(OpPC),
10681069
diag::note_constexpr_new_non_replaceable)
10691070
<< isa<CXXMethodDecl>(VirtualDelete) << VirtualDelete;
@@ -1498,14 +1499,16 @@ bool InvalidNewDeleteExpr(InterpState &S, CodePtr OpPC, const Expr *E) {
14981499
!OperatorNew->isReservedGlobalPlacementOperator()) {
14991500
S.FFDiag(Loc, diag::note_constexpr_new_placement)
15001501
<< /*Unsupported*/ 0 << E->getSourceRange();
1501-
} else if (!OperatorNew->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
1502+
} else if (!OperatorNew
1503+
->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
15021504
S.FFDiag(Loc, diag::note_constexpr_new_non_replaceable)
15031505
<< isa<CXXMethodDecl>(OperatorNew) << OperatorNew;
15041506
}
15051507
} else {
15061508
const auto *DeleteExpr = cast<CXXDeleteExpr>(E);
15071509
const FunctionDecl *OperatorDelete = DeleteExpr->getOperatorDelete();
1508-
if (!OperatorDelete->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
1510+
if (!OperatorDelete
1511+
->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
15091512
S.FFDiag(Loc, diag::note_constexpr_new_non_replaceable)
15101513
<< isa<CXXMethodDecl>(OperatorDelete) << OperatorDelete;
15111514
}

clang/lib/AST/Decl.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,12 +3357,10 @@ bool FunctionDecl::isReservedGlobalPlacementOperator() const {
33573357
return false;
33583358

33593359
const auto *proto = getType()->castAs<FunctionProtoType>();
3360-
if (proto->getNumParams() < 2)
3360+
if (proto->getNumParams() != 2 || proto->isVariadic())
33613361
return false;
33623362
if (proto->getParamType(0)->isTypeIdentitySpecialization())
33633363
return false;
3364-
if (proto->getNumParams() != 2 || proto->isVariadic())
3365-
return false;
33663364

33673365
const ASTContext &Context =
33683366
cast<TranslationUnitDecl>(getDeclContext()->getRedeclContext())
@@ -3393,7 +3391,8 @@ bool FunctionDecl::isConstEvalSafeOrReplaceableGlobalAllocationFunction(
33933391
bool IsTypeAware = isTypeAwareOperatorNewOrDelete();
33943392
unsigned MaxParamCount = IsTypeAware + 4;
33953393
const auto *FPT = getType()->castAs<FunctionProtoType>();
3396-
if (FPT->getNumParams() == 0 || FPT->getNumParams() > MaxParamCount || FPT->isVariadic())
3394+
if (FPT->getNumParams() == 0 || FPT->getNumParams() > MaxParamCount ||
3395+
FPT->isVariadic())
33973396
return false;
33983397

33993398
unsigned MinimumParamCount = IsTypeAware + 1;

clang/lib/AST/ExprConstant.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10188,7 +10188,8 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const CXXNewExpr *E) {
1018810188
Info.FFDiag(E, diag::note_constexpr_new_placement)
1018910189
<< /*Unsupported*/ 0 << E->getSourceRange();
1019010190
return false;
10191-
} else if (!OperatorNew->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
10191+
} else if (!OperatorNew
10192+
->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
1019210193
Info.FFDiag(E, diag::note_constexpr_new_non_replaceable)
1019310194
<< isa<CXXMethodDecl>(OperatorNew) << OperatorNew;
1019410195
return false;
@@ -16300,7 +16301,8 @@ bool VoidExprEvaluator::VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
1630016301
if (!E->isArrayForm() && !E->isGlobalDelete()) {
1630116302
const FunctionDecl *VirtualDelete = getVirtualOperatorDelete(AllocType);
1630216303
if (VirtualDelete &&
16303-
!VirtualDelete->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
16304+
!VirtualDelete
16305+
->isConstEvalSafeOrReplaceableGlobalAllocationFunction()) {
1630416306
Info.FFDiag(E, diag::note_constexpr_new_non_replaceable)
1630516307
<< isa<CXXMethodDecl>(VirtualDelete) << VirtualDelete;
1630616308
return false;

clang/lib/Sema/SemaCoroutine.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,33 +1424,34 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
14241424
ImplicitAllocationParameters IAP = {
14251425
typeAwareAllocationModeFromBool(S.getLangOpts().TypeAwareAllocators),
14261426
alignedAllocationModeFromBool(S.getLangOpts().CoroAlignedAllocation)};
1427-
auto LookupAllocationFunction =
1428-
[&](Sema::AllocationFunctionScope NewScope = Sema::AFS_Both,
1429-
bool WithoutPlacementArgs = false, bool ForceNonAligned = false) {
1430-
// [dcl.fct.def.coroutine]p9
1431-
// The allocation function's name is looked up by searching for it in
1432-
// the
1433-
// scope of the promise type.
1434-
// - If any declarations are found, ...
1435-
// - If no declarations are found in the scope of the promise type, a
1436-
// search is performed in the global scope.
1437-
if (NewScope == Sema::AFS_Both)
1438-
NewScope = PromiseContainsNew ? Sema::AFS_Class : Sema::AFS_Global;
1439-
1440-
bool ShouldUseAlignedAlloc = !ForceNonAligned && S.getLangOpts().CoroAlignedAllocation;
1441-
IAP = {
1442-
typeAwareAllocationModeFromBool(S.getLangOpts().TypeAwareAllocators),
1443-
alignedAllocationModeFromBool(ShouldUseAlignedAlloc)};
1444-
1445-
FunctionDecl *UnusedResult = nullptr;
1446-
1447-
S.FindAllocationFunctions(
1448-
Loc, SourceRange(), NewScope,
1449-
/*DeleteScope*/ Sema::AFS_Both, PromiseType,
1450-
/*isArray*/ false, IAP,
1451-
WithoutPlacementArgs ? MultiExprArg{} : PlacementArgs, OperatorNew,
1452-
UnusedResult, /*Diagnose*/ false);
1453-
};
1427+
auto LookupAllocationFunction = [&](Sema::AllocationFunctionScope NewScope =
1428+
Sema::AFS_Both,
1429+
bool WithoutPlacementArgs = false,
1430+
bool ForceNonAligned = false) {
1431+
// [dcl.fct.def.coroutine]p9
1432+
// The allocation function's name is looked up by searching for it in
1433+
// the
1434+
// scope of the promise type.
1435+
// - If any declarations are found, ...
1436+
// - If no declarations are found in the scope of the promise type, a
1437+
// search is performed in the global scope.
1438+
if (NewScope == Sema::AFS_Both)
1439+
NewScope = PromiseContainsNew ? Sema::AFS_Class : Sema::AFS_Global;
1440+
1441+
bool ShouldUseAlignedAlloc =
1442+
!ForceNonAligned && S.getLangOpts().CoroAlignedAllocation;
1443+
IAP = {typeAwareAllocationModeFromBool(S.getLangOpts().TypeAwareAllocators),
1444+
alignedAllocationModeFromBool(ShouldUseAlignedAlloc)};
1445+
1446+
FunctionDecl *UnusedResult = nullptr;
1447+
1448+
S.FindAllocationFunctions(Loc, SourceRange(), NewScope,
1449+
/*DeleteScope*/ Sema::AFS_Both, PromiseType,
1450+
/*isArray*/ false, IAP,
1451+
WithoutPlacementArgs ? MultiExprArg{}
1452+
: PlacementArgs,
1453+
OperatorNew, UnusedResult, /*Diagnose*/ false);
1454+
};
14541455

14551456
// We don't expect to call to global operator new with (size, p0, …, pn).
14561457
// So if we choose to lookup the allocation function in global scope, we

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14475,11 +14475,10 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
1447514475
<< var;
1447614476

1447714477
// Check whether the initializer is sufficiently constant.
14478-
bool c1 = (getLangOpts().CPlusPlus || (getLangOpts().C23 && var->isConstexpr()));
14479-
bool c2 = !type->isDependentType() && Init && !Init->isValueDependent();
14480-
bool c3 = var->isConstexpr();
14481-
bool c4 = var->mightBeUsableInConstantExpressions(Context);
14482-
if (c1 && c2 && (GlobalStorage || c3 || c4)) {
14478+
if ((getLangOpts().CPlusPlus || (getLangOpts().C23 && var->isConstexpr())) &&
14479+
!type->isDependentType() && Init && !Init->isValueDependent() &&
14480+
(GlobalStorage || var->isConstexpr() ||
14481+
var->mightBeUsableInConstantExpressions(Context))) {
1448314482
// If this variable might have a constant initializer or might be usable in
1448414483
// constant expressions, check whether or not it actually is now. We can't
1448514484
// do this lazily, because the result might depend on things that change

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9716,9 +9716,8 @@ bool Sema::ShouldDeleteSpecialMember(CXXMethodDecl *MD,
97169716
DeclarationName Name =
97179717
Context.DeclarationNames.getCXXOperatorName(OO_Delete);
97189718
ImplicitDeallocationParameters IDP = {
9719-
typeAwareAllocationModeFromBool(getLangOpts().TypeAwareAllocators),
9720-
AlignedAllocationMode::No,
9721-
SizedDeallocationMode::No};
9719+
typeAwareAllocationModeFromBool(getLangOpts().TypeAwareAllocators),
9720+
AlignedAllocationMode::No, SizedDeallocationMode::No};
97229721
if (FindDeallocationFunction(MD->getLocation(), MD->getParent(), Name,
97239722
OperatorDelete, DeallocType, IDP,
97249723
/*Diagnose*/ false)) {

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,8 +1754,8 @@ static bool isNonPlacementDeallocationFunction(Sema &S, FunctionDecl *FD) {
17541754
return false;
17551755

17561756
unsigned UsualParams = 1;
1757-
if (S.getLangOpts().TypeAwareAllocators &&
1758-
UsualParams < FD->getNumParams() && FD->isTypeAwareOperatorNewOrDelete())
1757+
if (S.getLangOpts().TypeAwareAllocators && UsualParams < FD->getNumParams() &&
1758+
FD->isTypeAwareOperatorNewOrDelete())
17591759
++UsualParams;
17601760

17611761
if (S.getLangOpts().SizedDeallocation && UsualParams < FD->getNumParams() &&
@@ -3513,10 +3513,9 @@ FunctionDecl *Sema::FindUsualDeallocationFunction(
35133513
DeclareGlobalNewDelete();
35143514

35153515
LookupResult FoundDelete(*this, Name, StartLoc, LookupOrdinaryName);
3516-
DeallocLookupMode LookupMode =
3517-
getLangOpts().TypeAwareAllocators
3518-
? DeallocLookupMode::OptionallyTyped
3519-
: DeallocLookupMode::Untyped;
3516+
DeallocLookupMode LookupMode = getLangOpts().TypeAwareAllocators
3517+
? DeallocLookupMode::OptionallyTyped
3518+
: DeallocLookupMode::Untyped;
35203519
LookupGlobalDeallocationFunctions(*this, StartLoc, FoundDelete, LookupMode,
35213520
Name, DeallocType);
35223521

@@ -3545,9 +3544,8 @@ FunctionDecl *Sema::FindDeallocationFunctionForDestructor(SourceLocation Loc,
35453544
FunctionDecl *OperatorDelete = nullptr;
35463545
QualType DeallocType = Context.getRecordType(RD);
35473546
ImplicitDeallocationParameters IDP = {
3548-
typeAwareAllocationModeFromBool(getLangOpts().TypeAwareAllocators),
3549-
AlignedAllocationMode::No,
3550-
SizedDeallocationMode::No};
3547+
typeAwareAllocationModeFromBool(getLangOpts().TypeAwareAllocators),
3548+
AlignedAllocationMode::No, SizedDeallocationMode::No};
35513549

35523550
if (FindDeallocationFunction(Loc, RD, Name, OperatorDelete, DeallocType, IDP))
35533551
return nullptr;
@@ -4019,9 +4017,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
40194017

40204018
if (PointeeRD) {
40214019
ImplicitDeallocationParameters IDP = {
4022-
typeAwareAllocationModeFromBool(getLangOpts().TypeAwareAllocators),
4023-
AlignedAllocationMode::No,
4024-
SizedDeallocationMode::No};
4020+
typeAwareAllocationModeFromBool(getLangOpts().TypeAwareAllocators),
4021+
AlignedAllocationMode::No, SizedDeallocationMode::No};
40254022
if (!UseGlobal &&
40264023
FindDeallocationFunction(StartLoc, PointeeRD, DeleteName,
40274024
OperatorDelete, Pointee, IDP))

0 commit comments

Comments
 (0)