Skip to content

Commit 5497f53

Browse files
committed
[NFC][Sema] Move Sema::AssignmentAction into its own scoped enum
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 llvm#106321. It was requested in llvm#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 to all downstream forks in advanced. Note the AA_ prefix has been dropped from the enum value names as they are now redundant.
1 parent 1601879 commit 5497f53

12 files changed

+142
-117
lines changed

clang/include/clang/Sema/Sema.h

+18-13
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,24 @@ class SemaPPCallbacks;
204204
class TemplateDeductionInfo;
205205
} // namespace sema
206206

207+
// AssignmentAction - This is used by all the assignment diagnostic functions
208+
// to represent what is actually causing the operation
209+
enum class AssignmentAction {
210+
Assigning,
211+
Passing,
212+
Returning,
213+
Converting,
214+
Initializing,
215+
Sending,
216+
Casting,
217+
Passing_CFAudited
218+
};
219+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
220+
const AssignmentAction &AA) {
221+
DB << llvm::to_underlying(AA);
222+
return DB;
223+
}
224+
207225
namespace threadSafety {
208226
class BeforeSet;
209227
void threadSafetyCleanup(BeforeSet *Cache);
@@ -6490,19 +6508,6 @@ class Sema final : public SemaBase {
64906508
/// cleanup that are created by the current full expression.
64916509
SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects;
64926510

6493-
// AssignmentAction - This is used by all the assignment diagnostic functions
6494-
// to represent what is actually causing the operation
6495-
enum AssignmentAction {
6496-
AA_Assigning,
6497-
AA_Passing,
6498-
AA_Returning,
6499-
AA_Converting,
6500-
AA_Initializing,
6501-
AA_Sending,
6502-
AA_Casting,
6503-
AA_Passing_CFAudited
6504-
};
6505-
65066511
/// Determine whether the use of this declaration is valid, without
65076512
/// emitting diagnostics.
65086513
bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid);

clang/lib/Sema/SemaARM.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,8 @@ bool SemaARM::CheckNeonBuiltinFunctionCall(const TargetInfo &TI,
795795
if (RHS.isInvalid())
796796
return true;
797797
if (SemaRef.DiagnoseAssignmentResult(ConvTy, Arg->getBeginLoc(), LHSTy,
798-
RHSTy, RHS.get(), Sema::AA_Assigning))
798+
RHSTy, RHS.get(),
799+
AssignmentAction::Assigning))
799800
return true;
800801
}
801802

@@ -921,7 +922,7 @@ bool SemaARM::CheckARMBuiltinExclusiveCall(unsigned BuiltinID,
921922
CastNeeded = CK_BitCast;
922923
Diag(DRE->getBeginLoc(), diag::ext_typecheck_convert_discards_qualifiers)
923924
<< PointerArg->getType() << Context.getPointerType(AddrType)
924-
<< Sema::AA_Passing << PointerArg->getSourceRange();
925+
<< AssignmentAction::Passing << PointerArg->getSourceRange();
925926
}
926927

927928
// Finally, do the cast and replace the argument with the corrected version.

clang/lib/Sema/SemaCast.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,7 @@ void CastOperation::checkAddressSpaceCast(QualType SrcType, QualType DestType) {
26732673
? DestPPointee.getAddressSpace() != SrcPPointee.getAddressSpace()
26742674
: !DestPPointee.isAddressSpaceOverlapping(SrcPPointee)) {
26752675
Self.Diag(OpRange.getBegin(), DiagID)
2676-
<< SrcType << DestType << Sema::AA_Casting
2676+
<< SrcType << DestType << AssignmentAction::Casting
26772677
<< SrcExpr.get()->getSourceRange();
26782678
if (!Nested)
26792679
SrcExpr = ExprError();
@@ -3213,7 +3213,7 @@ void CastOperation::CheckCStyleCast() {
32133213
!CastQuals.compatiblyIncludesObjCLifetime(ExprQuals)) {
32143214
Self.Diag(SrcExpr.get()->getBeginLoc(),
32153215
diag::err_typecheck_incompatible_ownership)
3216-
<< SrcType << DestType << Sema::AA_Casting
3216+
<< SrcType << DestType << AssignmentAction::Casting
32173217
<< SrcExpr.get()->getSourceRange();
32183218
return;
32193219
}

clang/lib/Sema/SemaChecking.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -4880,7 +4880,8 @@ bool Sema::BuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs,
48804880
if (Arg->isTypeDependent())
48814881
return false;
48824882

4883-
ExprResult Res = PerformImplicitConversion(Arg, Context.IntTy, AA_Passing);
4883+
ExprResult Res = PerformImplicitConversion(Arg, Context.IntTy,
4884+
AssignmentAction::Passing);
48844885

48854886
if (Res.isInvalid())
48864887
return true;

clang/lib/Sema/SemaDeclCXX.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -10871,7 +10871,8 @@ bool Sema::CheckDestructor(CXXDestructorDecl *Destructor) {
1087110871
ExprResult This =
1087210872
ActOnCXXThis(OperatorDelete->getParamDecl(0)->getLocation());
1087310873
assert(!This.isInvalid() && "couldn't form 'this' expr in dtor?");
10874-
This = PerformImplicitConversion(This.get(), ParamType, AA_Passing);
10874+
This = PerformImplicitConversion(This.get(), ParamType,
10875+
AssignmentAction::Passing);
1087510876
if (This.isInvalid()) {
1087610877
// FIXME: Register this as a context note so that it comes out
1087710878
// in the right order.

clang/lib/Sema/SemaExpr.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -9586,7 +9586,7 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS,
95869586
QualType RHSType = RHS.get()->getType();
95879587
if (Diagnose) {
95889588
RHS = PerformImplicitConversion(RHS.get(), LHSType.getUnqualifiedType(),
9589-
AA_Assigning);
9589+
AssignmentAction::Assigning);
95909590
} else {
95919591
ImplicitConversionSequence ICS =
95929592
TryImplicitConversion(RHS.get(), LHSType.getUnqualifiedType(),
@@ -9598,7 +9598,7 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS,
95989598
if (ICS.isFailure())
95999599
return Incompatible;
96009600
RHS = PerformImplicitConversion(RHS.get(), LHSType.getUnqualifiedType(),
9601-
ICS, AA_Assigning);
9601+
ICS, AssignmentAction::Assigning);
96029602
}
96039603
if (RHS.isInvalid())
96049604
return Incompatible;
@@ -13654,8 +13654,8 @@ QualType Sema::CheckAssignmentOperands(Expr *LHSExpr, ExprResult &RHS,
1365413654
ConvTy = CheckAssignmentConstraints(Loc, LHSType, RHSType);
1365513655
}
1365613656

13657-
if (DiagnoseAssignmentResult(ConvTy, Loc, LHSType, RHSType,
13658-
RHS.get(), AA_Assigning))
13657+
if (DiagnoseAssignmentResult(ConvTy, Loc, LHSType, RHSType, RHS.get(),
13658+
AssignmentAction::Assigning))
1365913659
return QualType();
1366013660

1366113661
CheckForNullPointerDereference(*this, LHSExpr);
@@ -16663,7 +16663,7 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
1666316663
MayHaveConvFixit = true;
1666416664
break;
1666516665
case IncompatiblePointer:
16666-
if (Action == AA_Passing_CFAudited) {
16666+
if (Action == AssignmentAction::Passing_CFAudited) {
1666716667
DiagKind = diag::err_arc_typecheck_convert_incompatible_pointer;
1666816668
} else if (getLangOpts().CPlusPlus) {
1666916669
DiagKind = diag::err_typecheck_convert_incompatible_pointer;
@@ -16817,19 +16817,19 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
1681716817

1681816818
QualType FirstType, SecondType;
1681916819
switch (Action) {
16820-
case AA_Assigning:
16821-
case AA_Initializing:
16820+
case AssignmentAction::Assigning:
16821+
case AssignmentAction::Initializing:
1682216822
// The destination type comes first.
1682316823
FirstType = DstType;
1682416824
SecondType = SrcType;
1682516825
break;
1682616826

16827-
case AA_Returning:
16828-
case AA_Passing:
16829-
case AA_Passing_CFAudited:
16830-
case AA_Converting:
16831-
case AA_Sending:
16832-
case AA_Casting:
16827+
case AssignmentAction::Returning:
16828+
case AssignmentAction::Passing:
16829+
case AssignmentAction::Passing_CFAudited:
16830+
case AssignmentAction::Converting:
16831+
case AssignmentAction::Sending:
16832+
case AssignmentAction::Casting:
1683316833
// The source type comes first.
1683416834
FirstType = SrcType;
1683516835
SecondType = DstType;
@@ -16838,8 +16838,8 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
1683816838

1683916839
PartialDiagnostic FDiag = PDiag(DiagKind);
1684016840
AssignmentAction ActionForDiag = Action;
16841-
if (Action == AA_Passing_CFAudited)
16842-
ActionForDiag = AA_Passing;
16841+
if (Action == AssignmentAction::Passing_CFAudited)
16842+
ActionForDiag = AssignmentAction::Passing;
1684316843

1684416844
FDiag << FirstType << SecondType << ActionForDiag
1684516845
<< SrcExpr->getSourceRange();
@@ -16879,7 +16879,7 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
1687916879
if (CheckInferredResultType)
1688016880
ObjC().EmitRelatedResultTypeNote(SrcExpr);
1688116881

16882-
if (Action == AA_Returning && ConvTy == IncompatiblePointer)
16882+
if (Action == AssignmentAction::Returning && ConvTy == IncompatiblePointer)
1688316883
ObjC().EmitRelatedResultTypeNoteForReturn(DstType);
1688416884

1688516885
if (Complained)

clang/lib/Sema/SemaExprCXX.cpp

+24-23
Original file line numberDiff line numberDiff line change
@@ -2199,8 +2199,8 @@ ExprResult Sema::BuildCXXNew(SourceRange Range, bool UseGlobal,
21992199
if (getLangOpts().CPlusPlus14) {
22002200
assert(Context.getTargetInfo().getIntWidth() && "Builtin type of size 0?");
22012201

2202-
ConvertedSize = PerformImplicitConversion(*ArraySize, Context.getSizeType(),
2203-
AA_Converting);
2202+
ConvertedSize = PerformImplicitConversion(
2203+
*ArraySize, Context.getSizeType(), AssignmentAction::Converting);
22042204

22052205
if (!ConvertedSize.isInvalid() &&
22062206
(*ArraySize)->getType()->getAs<RecordType>())
@@ -3851,7 +3851,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
38513851
Context.getQualifiedType(Pointee.getUnqualifiedType(), Qs));
38523852
Ex = ImpCastExprToType(Ex.get(), Unqual, CK_NoOp);
38533853
}
3854-
Ex = PerformImplicitConversion(Ex.get(), ParamType, AA_Passing);
3854+
Ex = PerformImplicitConversion(Ex.get(), ParamType,
3855+
AssignmentAction::Passing);
38553856
if (Ex.isInvalid())
38563857
return ExprError();
38573858
}
@@ -4256,10 +4257,9 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
42564257
}
42574258
// Watch out for ellipsis conversion.
42584259
if (!ICS.UserDefined.EllipsisConversion) {
4259-
ExprResult Res =
4260-
PerformImplicitConversion(From, BeforeToType,
4261-
ICS.UserDefined.Before, AA_Converting,
4262-
CCK);
4260+
ExprResult Res = PerformImplicitConversion(
4261+
From, BeforeToType, ICS.UserDefined.Before,
4262+
AssignmentAction::Converting, CCK);
42634263
if (Res.isInvalid())
42644264
return ExprError();
42654265
From = Res.get();
@@ -4282,7 +4282,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
42824282
return From;
42834283

42844284
return PerformImplicitConversion(From, ToType, ICS.UserDefined.After,
4285-
AA_Converting, CCK);
4285+
AssignmentAction::Converting, CCK);
42864286
}
42874287

42884288
case ImplicitConversionSequence::AmbiguousConversion:
@@ -4451,19 +4451,19 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
44514451
// target entity shall allow at least the exceptions allowed by the
44524452
// source value in the assignment or initialization.
44534453
switch (Action) {
4454-
case AA_Assigning:
4455-
case AA_Initializing:
4454+
case AssignmentAction::Assigning:
4455+
case AssignmentAction::Initializing:
44564456
// Note, function argument passing and returning are initialization.
4457-
case AA_Passing:
4458-
case AA_Returning:
4459-
case AA_Sending:
4460-
case AA_Passing_CFAudited:
4457+
case AssignmentAction::Passing:
4458+
case AssignmentAction::Returning:
4459+
case AssignmentAction::Sending:
4460+
case AssignmentAction::Passing_CFAudited:
44614461
if (CheckExceptionSpecCompatibility(From, ToType))
44624462
return ExprError();
44634463
break;
44644464

4465-
case AA_Casting:
4466-
case AA_Converting:
4465+
case AssignmentAction::Casting:
4466+
case AssignmentAction::Converting:
44674467
// Casts and implicit conversions are not initialization, so are not
44684468
// checked for exception specification mismatches.
44694469
break;
@@ -4577,9 +4577,10 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
45774577

45784578
case ICK_Writeback_Conversion:
45794579
case ICK_Pointer_Conversion: {
4580-
if (SCS.IncompatibleObjC && Action != AA_Casting) {
4580+
if (SCS.IncompatibleObjC && Action != AssignmentAction::Casting) {
45814581
// Diagnose incompatible Objective-C conversions
4582-
if (Action == AA_Initializing || Action == AA_Assigning)
4582+
if (Action == AssignmentAction::Initializing ||
4583+
Action == AssignmentAction::Assigning)
45834584
Diag(From->getBeginLoc(),
45844585
diag::ext_typecheck_convert_incompatible_pointer)
45854586
<< ToType << From->getType() << Action << From->getSourceRange()
@@ -4596,12 +4597,12 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
45964597
} else if (getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
45974598
!ObjC().CheckObjCARCUnavailableWeakConversion(ToType,
45984599
From->getType())) {
4599-
if (Action == AA_Initializing)
4600+
if (Action == AssignmentAction::Initializing)
46004601
Diag(From->getBeginLoc(), diag::err_arc_weak_unavailable_assign);
46014602
else
46024603
Diag(From->getBeginLoc(), diag::err_arc_convesion_of_weak_unavailable)
4603-
<< (Action == AA_Casting) << From->getType() << ToType
4604-
<< From->getSourceRange();
4604+
<< (Action == AssignmentAction::Casting) << From->getType()
4605+
<< ToType << From->getSourceRange();
46054606
}
46064607

46074608
// Defer address space conversion to the third conversion.
@@ -6666,14 +6667,14 @@ static bool FindConditionalOverload(Sema &Self, ExprResult &LHS, ExprResult &RHS
66666667
// We found a match. Perform the conversions on the arguments and move on.
66676668
ExprResult LHSRes = Self.PerformImplicitConversion(
66686669
LHS.get(), Best->BuiltinParamTypes[0], Best->Conversions[0],
6669-
Sema::AA_Converting);
6670+
AssignmentAction::Converting);
66706671
if (LHSRes.isInvalid())
66716672
break;
66726673
LHS = LHSRes;
66736674

66746675
ExprResult RHSRes = Self.PerformImplicitConversion(
66756676
RHS.get(), Best->BuiltinParamTypes[1], Best->Conversions[1],
6676-
Sema::AA_Converting);
6677+
AssignmentAction::Converting);
66776678
if (RHSRes.isInvalid())
66786679
break;
66796680
RHS = RHSRes;

clang/lib/Sema/SemaInit.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -6799,43 +6799,44 @@ InitializationSequence::~InitializationSequence() {
67996799
//===----------------------------------------------------------------------===//
68006800
// Perform initialization
68016801
//===----------------------------------------------------------------------===//
6802-
static Sema::AssignmentAction
6803-
getAssignmentAction(const InitializedEntity &Entity, bool Diagnose = false) {
6802+
static AssignmentAction getAssignmentAction(const InitializedEntity &Entity,
6803+
bool Diagnose = false) {
68046804
switch(Entity.getKind()) {
68056805
case InitializedEntity::EK_Variable:
68066806
case InitializedEntity::EK_New:
68076807
case InitializedEntity::EK_Exception:
68086808
case InitializedEntity::EK_Base:
68096809
case InitializedEntity::EK_Delegating:
6810-
return Sema::AA_Initializing;
6810+
return AssignmentAction::Initializing;
68116811

68126812
case InitializedEntity::EK_Parameter:
68136813
if (Entity.getDecl() &&
68146814
isa<ObjCMethodDecl>(Entity.getDecl()->getDeclContext()))
6815-
return Sema::AA_Sending;
6815+
return AssignmentAction::Sending;
68166816

6817-
return Sema::AA_Passing;
6817+
return AssignmentAction::Passing;
68186818

68196819
case InitializedEntity::EK_Parameter_CF_Audited:
68206820
if (Entity.getDecl() &&
68216821
isa<ObjCMethodDecl>(Entity.getDecl()->getDeclContext()))
6822-
return Sema::AA_Sending;
6822+
return AssignmentAction::Sending;
68236823

6824-
return !Diagnose ? Sema::AA_Passing : Sema::AA_Passing_CFAudited;
6824+
return !Diagnose ? AssignmentAction::Passing
6825+
: AssignmentAction::Passing_CFAudited;
68256826

68266827
case InitializedEntity::EK_Result:
68276828
case InitializedEntity::EK_StmtExprResult: // FIXME: Not quite right.
6828-
return Sema::AA_Returning;
6829+
return AssignmentAction::Returning;
68296830

68306831
case InitializedEntity::EK_Temporary:
68316832
case InitializedEntity::EK_RelatedResult:
68326833
// FIXME: Can we tell apart casting vs. converting?
6833-
return Sema::AA_Casting;
6834+
return AssignmentAction::Casting;
68346835

68356836
case InitializedEntity::EK_TemplateParameter:
68366837
// This is really initialization, but refer to it as conversion for
68376838
// consistency with CheckConvertedConstantExpression.
6838-
return Sema::AA_Converting;
6839+
return AssignmentAction::Converting;
68396840

68406841
case InitializedEntity::EK_Member:
68416842
case InitializedEntity::EK_ParenAggInitMember:
@@ -6847,7 +6848,7 @@ getAssignmentAction(const InitializedEntity &Entity, bool Diagnose = false) {
68476848
case InitializedEntity::EK_LambdaToBlockConversionBlockElement:
68486849
case InitializedEntity::EK_LambdaCapture:
68496850
case InitializedEntity::EK_CompoundLiteralInit:
6850-
return Sema::AA_Initializing;
6851+
return AssignmentAction::Initializing;
68516852
}
68526853

68536854
llvm_unreachable("Invalid EntityKind!");

0 commit comments

Comments
 (0)