[clang] [NFC][Sema] Move `Sema::AssignmentAction` into its own scoped enum (PR #106453)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 28 14:06:15 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-arm
Author: Dan Liew (delcypher)
<details>
<summary>Changes</summary>
The primary motivation behind this is to allow the enum type to be
referred to earlier in the `Sema.h` file which is needed for #<!-- -->106321.
It was requested in #<!-- -->106321 that a scoped enum be used (rather than
moving the enum declaration earlier in the `Sema` class declaration).
Unfortunately doing this creates a lot of churn as all use sites of
the enum constants had to be changed. Appologies in advanced.
Note the `AA_` prefix has been dropped from the enum value names as they are now redundant.
---
Patch is 34.29 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/106453.diff
12 Files Affected:
- (modified) clang/include/clang/Sema/Sema.h (+18-13)
- (modified) clang/lib/Sema/SemaARM.cpp (+3-2)
- (modified) clang/lib/Sema/SemaCast.cpp (+2-2)
- (modified) clang/lib/Sema/SemaChecking.cpp (+2-1)
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+2-1)
- (modified) clang/lib/Sema/SemaExpr.cpp (+16-16)
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+24-23)
- (modified) clang/lib/Sema/SemaInit.cpp (+12-11)
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+41-36)
- (modified) clang/lib/Sema/SemaOverload.cpp (+19-11)
- (modified) clang/lib/Sema/SemaPseudoObject.cpp (+1-1)
- (modified) clang/lib/Sema/SemaStmt.cpp (+2-1)
``````````diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1f7e555d1b8717..ee2ca1d9b0f812 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -204,6 +204,24 @@ class SemaPPCallbacks;
class TemplateDeductionInfo;
} // namespace sema
+// AssignmentAction - This is used by all the assignment diagnostic functions
+// to represent what is actually causing the operation
+enum class AssignmentAction : unsigned {
+ Assigning,
+ Passing,
+ Returning,
+ Converting,
+ Initializing,
+ Sending,
+ Casting,
+ Passing_CFAudited
+};
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ const AssignmentAction &AA) {
+ DB << (unsigned)AA;
+ return DB;
+}
+
namespace threadSafety {
class BeforeSet;
void threadSafetyCleanup(BeforeSet *Cache);
@@ -6490,19 +6508,6 @@ class Sema final : public SemaBase {
/// cleanup that are created by the current full expression.
SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects;
- // AssignmentAction - This is used by all the assignment diagnostic functions
- // to represent what is actually causing the operation
- enum AssignmentAction {
- AA_Assigning,
- AA_Passing,
- AA_Returning,
- AA_Converting,
- AA_Initializing,
- AA_Sending,
- AA_Casting,
- AA_Passing_CFAudited
- };
-
/// Determine whether the use of this declaration is valid, without
/// emitting diagnostics.
bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid);
diff --git a/clang/lib/Sema/SemaARM.cpp b/clang/lib/Sema/SemaARM.cpp
index e18872f0dc551e..185e0427d5c995 100644
--- a/clang/lib/Sema/SemaARM.cpp
+++ b/clang/lib/Sema/SemaARM.cpp
@@ -795,7 +795,8 @@ bool SemaARM::CheckNeonBuiltinFunctionCall(const TargetInfo &TI,
if (RHS.isInvalid())
return true;
if (SemaRef.DiagnoseAssignmentResult(ConvTy, Arg->getBeginLoc(), LHSTy,
- RHSTy, RHS.get(), Sema::AA_Assigning))
+ RHSTy, RHS.get(),
+ AssignmentAction::Assigning))
return true;
}
@@ -921,7 +922,7 @@ bool SemaARM::CheckARMBuiltinExclusiveCall(unsigned BuiltinID,
CastNeeded = CK_BitCast;
Diag(DRE->getBeginLoc(), diag::ext_typecheck_convert_discards_qualifiers)
<< PointerArg->getType() << Context.getPointerType(AddrType)
- << Sema::AA_Passing << PointerArg->getSourceRange();
+ << AssignmentAction::Passing << PointerArg->getSourceRange();
}
// Finally, do the cast and replace the argument with the corrected version.
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index eca8363ee9605c..f01b22a72915c8 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -2673,7 +2673,7 @@ void CastOperation::checkAddressSpaceCast(QualType SrcType, QualType DestType) {
? DestPPointee.getAddressSpace() != SrcPPointee.getAddressSpace()
: !DestPPointee.isAddressSpaceOverlapping(SrcPPointee)) {
Self.Diag(OpRange.getBegin(), DiagID)
- << SrcType << DestType << Sema::AA_Casting
+ << SrcType << DestType << AssignmentAction::Casting
<< SrcExpr.get()->getSourceRange();
if (!Nested)
SrcExpr = ExprError();
@@ -3213,7 +3213,7 @@ void CastOperation::CheckCStyleCast() {
!CastQuals.compatiblyIncludesObjCLifetime(ExprQuals)) {
Self.Diag(SrcExpr.get()->getBeginLoc(),
diag::err_typecheck_incompatible_ownership)
- << SrcType << DestType << Sema::AA_Casting
+ << SrcType << DestType << AssignmentAction::Casting
<< SrcExpr.get()->getSourceRange();
return;
}
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ee143381cf4f79..b021e27209cf1b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4880,7 +4880,8 @@ bool Sema::BuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs,
if (Arg->isTypeDependent())
return false;
- ExprResult Res = PerformImplicitConversion(Arg, Context.IntTy, AA_Passing);
+ ExprResult Res = PerformImplicitConversion(Arg, Context.IntTy,
+ AssignmentAction::Passing);
if (Res.isInvalid())
return true;
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index d89a47f3e6226a..3044f1218f5b23 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -10871,7 +10871,8 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) {
ExprResult This =
ActOnCXXThis(OperatorDelete->getParamDecl(0)->getLocation());
assert(!This.isInvalid() && "couldn't form 'this' expr in dtor?");
- This = PerformImplicitConversion(This.get(), ParamType, AA_Passing);
+ This = PerformImplicitConversion(This.get(), ParamType,
+ AssignmentAction::Passing);
if (This.isInvalid()) {
// FIXME: Register this as a context note so that it comes out
// in the right order.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 95f53dfefbcc52..a6763832715c7f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9586,7 +9586,7 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS,
QualType RHSType = RHS.get()->getType();
if (Diagnose) {
RHS = PerformImplicitConversion(RHS.get(), LHSType.getUnqualifiedType(),
- AA_Assigning);
+ AssignmentAction::Assigning);
} else {
ImplicitConversionSequence ICS =
TryImplicitConversion(RHS.get(), LHSType.getUnqualifiedType(),
@@ -9598,7 +9598,7 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS,
if (ICS.isFailure())
return Incompatible;
RHS = PerformImplicitConversion(RHS.get(), LHSType.getUnqualifiedType(),
- ICS, AA_Assigning);
+ ICS, AssignmentAction::Assigning);
}
if (RHS.isInvalid())
return Incompatible;
@@ -13654,8 +13654,8 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS,
ConvTy = CheckAssignmentConstraints(Loc, LHSType, RHSType);
}
- if (DiagnoseAssignmentResult(ConvTy, Loc, LHSType, RHSType,
- RHS.get(), AA_Assigning))
+ if (DiagnoseAssignmentResult(ConvTy, Loc, LHSType, RHSType, RHS.get(),
+ AssignmentAction::Assigning))
return QualType();
CheckForNullPointerDereference(*this, LHSExpr);
@@ -16663,7 +16663,7 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
MayHaveConvFixit = true;
break;
case IncompatiblePointer:
- if (Action == AA_Passing_CFAudited) {
+ if (Action == AssignmentAction::Passing_CFAudited) {
DiagKind = diag::err_arc_typecheck_convert_incompatible_pointer;
} else if (getLangOpts().CPlusPlus) {
DiagKind = diag::err_typecheck_convert_incompatible_pointer;
@@ -16817,19 +16817,19 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
QualType FirstType, SecondType;
switch (Action) {
- case AA_Assigning:
- case AA_Initializing:
+ case AssignmentAction::Assigning:
+ case AssignmentAction::Initializing:
// The destination type comes first.
FirstType = DstType;
SecondType = SrcType;
break;
- case AA_Returning:
- case AA_Passing:
- case AA_Passing_CFAudited:
- case AA_Converting:
- case AA_Sending:
- case AA_Casting:
+ case AssignmentAction::Returning:
+ case AssignmentAction::Passing:
+ case AssignmentAction::Passing_CFAudited:
+ case AssignmentAction::Converting:
+ case AssignmentAction::Sending:
+ case AssignmentAction::Casting:
// The source type comes first.
FirstType = SrcType;
SecondType = DstType;
@@ -16838,8 +16838,8 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
PartialDiagnostic FDiag = PDiag(DiagKind);
AssignmentAction ActionForDiag = Action;
- if (Action == AA_Passing_CFAudited)
- ActionForDiag = AA_Passing;
+ if (Action == AssignmentAction::Passing_CFAudited)
+ ActionForDiag = AssignmentAction::Passing;
FDiag << FirstType << SecondType << ActionForDiag
<< SrcExpr->getSourceRange();
@@ -16879,7 +16879,7 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
if (CheckInferredResultType)
ObjC().EmitRelatedResultTypeNote(SrcExpr);
- if (Action == AA_Returning && ConvTy == IncompatiblePointer)
+ if (Action == AssignmentAction::Returning && ConvTy == IncompatiblePointer)
ObjC().EmitRelatedResultTypeNoteForReturn(DstType);
if (Complained)
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index d8719ab26cc83f..b7531581d37ff0 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -2199,8 +2199,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
if (getLangOpts().CPlusPlus14) {
assert(Context.getTargetInfo().getIntWidth() && "Builtin type of size 0?");
- ConvertedSize = PerformImplicitConversion(*ArraySize, Context.getSizeType(),
- AA_Converting);
+ ConvertedSize = PerformImplicitConversion(
+ *ArraySize, Context.getSizeType(), AssignmentAction::Converting);
if (!ConvertedSize.isInvalid() &&
(*ArraySize)->getType()->getAs<RecordType>())
@@ -3851,7 +3851,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
Context.getQualifiedType(Pointee.getUnqualifiedType(), Qs));
Ex = ImpCastExprToType(Ex.get(), Unqual, CK_NoOp);
}
- Ex = PerformImplicitConversion(Ex.get(), ParamType, AA_Passing);
+ Ex = PerformImplicitConversion(Ex.get(), ParamType,
+ AssignmentAction::Passing);
if (Ex.isInvalid())
return ExprError();
}
@@ -4256,10 +4257,9 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
}
// Watch out for ellipsis conversion.
if (!ICS.UserDefined.EllipsisConversion) {
- ExprResult Res =
- PerformImplicitConversion(From, BeforeToType,
- ICS.UserDefined.Before, AA_Converting,
- CCK);
+ ExprResult Res = PerformImplicitConversion(
+ From, BeforeToType, ICS.UserDefined.Before,
+ AssignmentAction::Converting, CCK);
if (Res.isInvalid())
return ExprError();
From = Res.get();
@@ -4282,7 +4282,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
return From;
return PerformImplicitConversion(From, ToType, ICS.UserDefined.After,
- AA_Converting, CCK);
+ AssignmentAction::Converting, CCK);
}
case ImplicitConversionSequence::AmbiguousConversion:
@@ -4451,19 +4451,19 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
// target entity shall allow at least the exceptions allowed by the
// source value in the assignment or initialization.
switch (Action) {
- case AA_Assigning:
- case AA_Initializing:
+ case AssignmentAction::Assigning:
+ case AssignmentAction::Initializing:
// Note, function argument passing and returning are initialization.
- case AA_Passing:
- case AA_Returning:
- case AA_Sending:
- case AA_Passing_CFAudited:
+ case AssignmentAction::Passing:
+ case AssignmentAction::Returning:
+ case AssignmentAction::Sending:
+ case AssignmentAction::Passing_CFAudited:
if (CheckExceptionSpecCompatibility(From, ToType))
return ExprError();
break;
- case AA_Casting:
- case AA_Converting:
+ case AssignmentAction::Casting:
+ case AssignmentAction::Converting:
// Casts and implicit conversions are not initialization, so are not
// checked for exception specification mismatches.
break;
@@ -4577,9 +4577,10 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
case ICK_Writeback_Conversion:
case ICK_Pointer_Conversion: {
- if (SCS.IncompatibleObjC && Action != AA_Casting) {
+ if (SCS.IncompatibleObjC && Action != AssignmentAction::Casting) {
// Diagnose incompatible Objective-C conversions
- if (Action == AA_Initializing || Action == AA_Assigning)
+ if (Action == AssignmentAction::Initializing ||
+ Action == AssignmentAction::Assigning)
Diag(From->getBeginLoc(),
diag::ext_typecheck_convert_incompatible_pointer)
<< ToType << From->getType() << Action << From->getSourceRange()
@@ -4596,12 +4597,12 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
} else if (getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
!ObjC().CheckObjCARCUnavailableWeakConversion(ToType,
From->getType())) {
- if (Action == AA_Initializing)
+ if (Action == AssignmentAction::Initializing)
Diag(From->getBeginLoc(), diag::err_arc_weak_unavailable_assign);
else
Diag(From->getBeginLoc(), diag::err_arc_convesion_of_weak_unavailable)
- << (Action == AA_Casting) << From->getType() << ToType
- << From->getSourceRange();
+ << (Action == AssignmentAction::Casting) << From->getType()
+ << ToType << From->getSourceRange();
}
// Defer address space conversion to the third conversion.
@@ -6666,14 +6667,14 @@ static bool FindConditionalOverload(Sema &Self, ExprResult &LHS, ExprResult &RHS
// We found a match. Perform the conversions on the arguments and move on.
ExprResult LHSRes = Self.PerformImplicitConversion(
LHS.get(), Best->BuiltinParamTypes[0], Best->Conversions[0],
- Sema::AA_Converting);
+ AssignmentAction::Converting);
if (LHSRes.isInvalid())
break;
LHS = LHSRes;
ExprResult RHSRes = Self.PerformImplicitConversion(
RHS.get(), Best->BuiltinParamTypes[1], Best->Conversions[1],
- Sema::AA_Converting);
+ AssignmentAction::Converting);
if (RHSRes.isInvalid())
break;
RHS = RHSRes;
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 5a19a3505454ca..7dc17187524621 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6799,43 +6799,44 @@ InitializationSequence::~InitializationSequence() {
//===----------------------------------------------------------------------===//
// Perform initialization
//===----------------------------------------------------------------------===//
-static Sema::AssignmentAction
-getAssignmentAction(const InitializedEntity &Entity, bool Diagnose = false) {
+static AssignmentAction getAssignmentAction(const InitializedEntity &Entity,
+ bool Diagnose = false) {
switch(Entity.getKind()) {
case InitializedEntity::EK_Variable:
case InitializedEntity::EK_New:
case InitializedEntity::EK_Exception:
case InitializedEntity::EK_Base:
case InitializedEntity::EK_Delegating:
- return Sema::AA_Initializing;
+ return AssignmentAction::Initializing;
case InitializedEntity::EK_Parameter:
if (Entity.getDecl() &&
isa<ObjCMethodDecl>(Entity.getDecl()->getDeclContext()))
- return Sema::AA_Sending;
+ return AssignmentAction::Sending;
- return Sema::AA_Passing;
+ return AssignmentAction::Passing;
case InitializedEntity::EK_Parameter_CF_Audited:
if (Entity.getDecl() &&
isa<ObjCMethodDecl>(Entity.getDecl()->getDeclContext()))
- return Sema::AA_Sending;
+ return AssignmentAction::Sending;
- return !Diagnose ? Sema::AA_Passing : Sema::AA_Passing_CFAudited;
+ return !Diagnose ? AssignmentAction::Passing
+ : AssignmentAction::Passing_CFAudited;
case InitializedEntity::EK_Result:
case InitializedEntity::EK_StmtExprResult: // FIXME: Not quite right.
- return Sema::AA_Returning;
+ return AssignmentAction::Returning;
case InitializedEntity::EK_Temporary:
case InitializedEntity::EK_RelatedResult:
// FIXME: Can we tell apart casting vs. converting?
- return Sema::AA_Casting;
+ return AssignmentAction::Casting;
case InitializedEntity::EK_TemplateParameter:
// This is really initialization, but refer to it as conversion for
// consistency with CheckConvertedConstantExpression.
- return Sema::AA_Converting;
+ return AssignmentAction::Converting;
case InitializedEntity::EK_Member:
case InitializedEntity::EK_ParenAggInitMember:
@@ -6847,7 +6848,7 @@ getAssignmentAction(const InitializedEntity &Entity, bool Diagnose = false) {
case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
case InitializedEntity::EK_LambdaCapture:
case InitializedEntity::EK_CompoundLiteralInit:
- return Sema::AA_Initializing;
+ return AssignmentAction::Initializing;
}
llvm_unreachable("Invalid EntityKind!");
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 74c646f64b42f2..232222e674e6d1 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -7395,7 +7395,8 @@ SemaOpenMP::checkOpenMPDeclareVariantFunction(SemaOpenMP::DeclGroupPtrTy DG,
return std::nullopt;
}
VariantRefCast = SemaRef.PerformImplicitConversion(
- VariantRef, FnPtrType.getUnqualifiedType(), Sema::AA_Converting);
+ VariantRef, FnPtrType.getUnqualifiedType(),
+ AssignmentAction::Converting);
if (!VariantRefCast.isUsable())
return std::nullopt;
}
@@ -8415,9 +8416,10 @@ tryBuildCapture(Sema &SemaRef, Expr *Capture,
if (SemaRef.CurContext->isDependentContext() || Capture->containsErrors())
return Capture;
if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects))
- return SemaRef.PerformImplicitConversion(
- Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting,
- /*AllowExplicit=*/true);
+ return SemaRef.PerformImplicitConversion(Capture->IgnoreImpCasts(),
+ Capture->getType(),
+ AssignmentAction::Converting,
+ /*AllowExplicit=*/true);
auto I = Captures.find(Capture);
if (I != Captures.end())
return buildCapture(SemaRef, Capture, I->second, Name);
@@ -8517,7 +8519,7 @@ calculateNumIters(Sema &SemaRef, Scope *S, SourceLocation DefaultLoc,
SemaRef
.PerformImplicitConversion(
SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Upper).get(),
- CastType, Sema::AA_Converting)
+ CastType, AssignmentAction::Converting)
.get();
Lower = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Lower).get();
NewStep = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, NewStep.get());
@@ -8801,8 +8803,9 @@ Expr *OpenMPIterationSpaceChecker::buildNumIterations(
: Type->hasSignedIntegerRepresentation();
Type = C.getIntTypeForBitwidth(NewSize, IsSigned);
if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) {
- Diff = SemaRef.PerformImplicitConversion(
- Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true);
+ Diff = SemaRef.PerformImplicitConversion(Diff.get(), Type,
+ AssignmentAction::Converting,
+ /*AllowExplicit=*/true);
if (!Diff.isUsable())
return nullptr;
}
@@ -8819,8 +8822,8 @@ Expr *OpenMPIterationSpaceChecker::buildNumIterations(
NewSize, Type->hasSignedIntegerRepresentation() ||
C.getTypeSize(Type) < NewSize);
if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) ...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/106453
More information about the cfe-commits
mailing list