[clang] 461255e - [clang][NFC] Convert `Sema::AllocationFunctionScope` to scoped enum
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Fri May 2 02:38:58 PDT 2025
Author: Vlad Serebrennikov
Date: 2025-05-02T12:38:52+03:00
New Revision: 461255e0c17265141009437ba3887f49f9838a40
URL: https://github.com/llvm/llvm-project/commit/461255e0c17265141009437ba3887f49f9838a40
DIFF: https://github.com/llvm/llvm-project/commit/461255e0c17265141009437ba3887f49f9838a40.diff
LOG: [clang][NFC] Convert `Sema::AllocationFunctionScope` to scoped enum
Added:
Modified:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0f8e560bd68e6..d5ac4d2fa0fb2 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -771,6 +771,18 @@ enum class AssignConvertType {
Incompatible
};
+/// The scope in which to find allocation functions.
+enum class AllocationFunctionScope {
+ /// Only look for allocation functions in the global scope.
+ Global,
+ /// Only look for allocation functions in the scope of the
+ /// allocated class.
+ Class,
+ /// Look for allocation functions in both the global scope
+ /// and in the scope of the allocated class.
+ Both
+};
+
/// Sema - This implements semantic analysis and AST building for C.
/// \nosubgrouping
class Sema final : public SemaBase {
@@ -8372,18 +8384,6 @@ class Sema final : public SemaBase {
bool CheckAllocatedType(QualType AllocType, SourceLocation Loc,
SourceRange R);
- /// The scope in which to find allocation functions.
- enum AllocationFunctionScope {
- /// Only look for allocation functions in the global scope.
- AFS_Global,
- /// Only look for allocation functions in the scope of the
- /// allocated class.
- AFS_Class,
- /// Look for allocation functions in both the global scope
- /// and in the scope of the allocated class.
- AFS_Both
- };
-
/// Finds the overloads of operator new and delete that are appropriate
/// for the allocation.
bool FindAllocationFunctions(
diff --git a/clang/lib/Sema/SemaCoroutine.cpp b/clang/lib/Sema/SemaCoroutine.cpp
index d631ad11fc9f5..279e4c77d04aa 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -1455,8 +1455,8 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
// allocation function.
ImplicitAllocationParameters IAP(
alignedAllocationModeFromBool(S.getLangOpts().CoroAlignedAllocation));
- auto LookupAllocationFunction = [&](Sema::AllocationFunctionScope NewScope =
- Sema::AFS_Both,
+ auto LookupAllocationFunction = [&](AllocationFunctionScope NewScope =
+ AllocationFunctionScope::Both,
bool WithoutPlacementArgs = false,
bool ForceNonAligned = false) {
// [dcl.fct.def.coroutine]p9
@@ -1465,8 +1465,9 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
// - If any declarations are found, ...
// - If no declarations are found in the scope of the promise type, a search
// is performed in the global scope.
- if (NewScope == Sema::AFS_Both)
- NewScope = PromiseContainsNew ? Sema::AFS_Class : Sema::AFS_Global;
+ if (NewScope == AllocationFunctionScope::Both)
+ NewScope = PromiseContainsNew ? AllocationFunctionScope::Class
+ : AllocationFunctionScope::Global;
bool ShouldUseAlignedAlloc =
!ForceNonAligned && S.getLangOpts().CoroAlignedAllocation;
@@ -1474,12 +1475,12 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
alignedAllocationModeFromBool(ShouldUseAlignedAlloc));
FunctionDecl *UnusedResult = nullptr;
- S.FindAllocationFunctions(Loc, SourceRange(), NewScope,
- /*DeleteScope=*/Sema::AFS_Both, PromiseType,
- /*isArray=*/false, IAP,
- WithoutPlacementArgs ? MultiExprArg{}
- : PlacementArgs,
- OperatorNew, UnusedResult, /*Diagnose=*/false);
+ S.FindAllocationFunctions(
+ Loc, SourceRange(), NewScope,
+ /*DeleteScope=*/AllocationFunctionScope::Both, PromiseType,
+ /*isArray=*/false, IAP,
+ WithoutPlacementArgs ? MultiExprArg{} : PlacementArgs, OperatorNew,
+ UnusedResult, /*Diagnose=*/false);
assert(!OperatorNew || !OperatorNew->isTypeAwareOperatorNewOrDelete());
};
@@ -1506,7 +1507,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
// an argument of type std:align_val_t as the second argument.
if (!OperatorNew || (S.getLangOpts().CoroAlignedAllocation &&
!isAlignedAllocation(IAP.PassAlignment)))
- LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class,
+ LookupAllocationFunction(/*NewScope*/ AllocationFunctionScope::Class,
/*WithoutPlacementArgs*/ true);
}
@@ -1533,12 +1534,12 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
if (!OperatorNew || !isAlignedAllocation(IAP.PassAlignment)) {
FoundNonAlignedInPromise = OperatorNew;
- LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class,
+ LookupAllocationFunction(/*NewScope*/ AllocationFunctionScope::Class,
/*WithoutPlacementArgs*/ false,
/*ForceNonAligned*/ true);
if (!OperatorNew && !PlacementArgs.empty())
- LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class,
+ LookupAllocationFunction(/*NewScope*/ AllocationFunctionScope::Class,
/*WithoutPlacementArgs*/ true,
/*ForceNonAligned*/ true);
}
@@ -1554,7 +1555,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
return false;
PlacementArgs = {StdNoThrow};
OperatorNew = nullptr;
- LookupAllocationFunction(Sema::AFS_Global);
+ LookupAllocationFunction(AllocationFunctionScope::Global);
}
// If we found a non-aligned allocation function in the promise_type,
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 050e0ff1df164..ee45e196bdb5d 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2431,7 +2431,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
if (CheckArgsForPlaceholders(PlacementArgs))
return ExprError();
- AllocationFunctionScope Scope = UseGlobal ? AFS_Global : AFS_Both;
+ AllocationFunctionScope Scope = UseGlobal ? AllocationFunctionScope::Global
+ : AllocationFunctionScope::Both;
SourceRange AllocationParameterRange = Range;
if (PlacementLParen.isValid() && PlacementRParen.isValid())
AllocationParameterRange = SourceRange(PlacementLParen, PlacementRParen);
@@ -2906,9 +2907,11 @@ bool Sema::FindAllocationFunctions(
FunctionDecl *&OperatorDelete, bool Diagnose) {
// --- Choosing an allocation function ---
// C++ 5.3.4p8 - 14 & 18
- // 1) If looking in AFS_Global scope for allocation functions, only look in
- // the global scope. Else, if AFS_Class, only look in the scope of the
- // allocated class. If AFS_Both, look in both.
+ // 1) If looking in AllocationFunctionScope::Global scope for allocation
+ // functions, only look in
+ // the global scope. Else, if AllocationFunctionScope::Class, only look in
+ // the scope of the allocated class. If AllocationFunctionScope::Both, look
+ // in both.
// 2) If an array size is given, look for operator new[], else look for
// operator new.
// 3) The first argument is always size_t. Append the arguments from the
@@ -2981,7 +2984,8 @@ bool Sema::FindAllocationFunctions(
// function's name is looked up in the global scope. Otherwise, if the
// allocated type is a class type T or array thereof, the allocation
// function's name is looked up in the scope of T.
- if (AllocElemType->isRecordType() && NewScope != AFS_Global)
+ if (AllocElemType->isRecordType() &&
+ NewScope != AllocationFunctionScope::Global)
LookupQualifiedName(R, AllocElemType->getAsCXXRecordDecl());
// We can see ambiguity here if the allocation function is found in
@@ -2993,7 +2997,7 @@ bool Sema::FindAllocationFunctions(
// a class type, the allocation function's name is looked up in the
// global scope.
if (R.empty()) {
- if (NewScope == AFS_Class)
+ if (NewScope == AllocationFunctionScope::Class)
return true;
LookupQualifiedName(R, Context.getTranslationUnitDecl());
@@ -3043,7 +3047,8 @@ bool Sema::FindAllocationFunctions(
// the allocated type is not a class type or array thereof, the
// deallocation function's name is looked up in the global scope.
LookupResult FoundDelete(*this, DeleteName, StartLoc, LookupOrdinaryName);
- if (AllocElemType->isRecordType() && DeleteScope != AFS_Global) {
+ if (AllocElemType->isRecordType() &&
+ DeleteScope != AllocationFunctionScope::Global) {
auto *RD =
cast<CXXRecordDecl>(AllocElemType->castAs<RecordType>()->getDecl());
LookupQualifiedName(FoundDelete, RD);
@@ -3086,7 +3091,7 @@ bool Sema::FindAllocationFunctions(
if (FoundDelete.empty()) {
FoundDelete.clear(LookupOrdinaryName);
- if (DeleteScope == AFS_Class)
+ if (DeleteScope == AllocationFunctionScope::Class)
return true;
DeclareGlobalNewDelete();
More information about the cfe-commits
mailing list