Skip to content

Commit 35afd93

Browse files
author
git apple-llvm automerger
committed
Merge commit '001cc3427511' from llvm.org/main into next
2 parents 4198e61 + 001cc34 commit 35afd93

25 files changed

+105
-125
lines changed

clang/include/clang/Basic/Diagnostic.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,22 @@ operator<<(const StreamingDiagnostic &DB, T *DC) {
14421442
return DB;
14431443
}
14441444

1445+
// Convert scope enums to their underlying type, so that we don't have
1446+
// clutter the emitting code with `llvm::to_underlying()`.
1447+
// We also need to disable implicit conversion for the first argument,
1448+
// because classes that derive from StreamingDiagnostic define their own
1449+
// templated operator<< that accept a wide variety of types, leading
1450+
// to ambiguity.
1451+
template <typename T, typename U>
1452+
inline std::enable_if_t<
1453+
std::is_same_v<std::remove_const_t<T>, StreamingDiagnostic> &&
1454+
llvm::is_scoped_enum_v<std::remove_reference_t<U>>,
1455+
const StreamingDiagnostic &>
1456+
operator<<(const T &DB, U &&SE) {
1457+
DB << llvm::to_underlying(SE);
1458+
return DB;
1459+
}
1460+
14451461
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
14461462
SourceLocation L) {
14471463
DB.AddSourceRange(CharSourceRange::getTokenRange(L));

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,6 @@ enum class AssignmentAction {
222222
Casting,
223223
Passing_CFAudited
224224
};
225-
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
226-
const AssignmentAction &AA) {
227-
DB << llvm::to_underlying(AA);
228-
return DB;
229-
}
230225

231226
namespace threadSafety {
232227
class BeforeSet;
@@ -16028,12 +16023,6 @@ void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation,
1602816023
llvm::StringRef StackSlotLabel,
1602916024
AlignPackInfo Value);
1603016025

16031-
inline const StreamingDiagnostic &
16032-
operator<<(const StreamingDiagnostic &DB, Sema::StringEvaluationContext Ctx) {
16033-
DB << llvm::to_underlying(Ctx);
16034-
return DB;
16035-
}
16036-
1603716026
} // end namespace clang
1603816027

1603916028
#endif

clang/lib/AST/ODRDiagsEmitter.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,8 @@ bool ODRDiagsEmitter::diagnoseSubMismatchObjCMethod(
461461
}
462462
if (FirstMethod->getImplementationControl() !=
463463
SecondMethod->getImplementationControl()) {
464-
DiagError(ControlLevel)
465-
<< llvm::to_underlying(FirstMethod->getImplementationControl());
466-
DiagNote(ControlLevel) << llvm::to_underlying(
467-
SecondMethod->getImplementationControl());
464+
DiagError(ControlLevel) << FirstMethod->getImplementationControl();
465+
DiagNote(ControlLevel) << SecondMethod->getImplementationControl();
468466
return true;
469467
}
470468
if (FirstMethod->isThisDeclarationADesignatedInitializer() !=

clang/lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,7 @@ Parser::DeclGroupPtrTy Parser::ParseDeclGroup(ParsingDeclSpec &DS,
26852685
if (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate &&
26862686
D.isFirstDeclarator()) {
26872687
Diag(CommaLoc, diag::err_multiple_template_declarators)
2688-
<< llvm::to_underlying(TemplateInfo.Kind);
2688+
<< TemplateInfo.Kind;
26892689
}
26902690

26912691
// Parse the next declarator.

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3482,7 +3482,7 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
34823482
if (TemplateInfo.Kind != ParsedTemplateKind::NonTemplate &&
34833483
DeclaratorInfo.isFirstDeclarator()) {
34843484
Diag(CommaLoc, diag::err_multiple_template_declarators)
3485-
<< llvm::to_underlying(TemplateInfo.Kind);
3485+
<< TemplateInfo.Kind;
34863486
}
34873487

34883488
// Parse the next declarator.

clang/lib/Parse/ParsePragma.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,8 @@ void PragmaClangSectionHandler::HandlePragma(Preprocessor &PP,
23412341
SourceLocation PragmaLocation = Tok.getLocation();
23422342
PP.Lex(Tok); // eat ['bss'|'data'|'rodata'|'text']
23432343
if (Tok.isNot(tok::equal)) {
2344-
PP.Diag(Tok.getLocation(), diag::err_pragma_clang_section_expected_equal) << llvm::to_underlying(SecKind);
2344+
PP.Diag(Tok.getLocation(), diag::err_pragma_clang_section_expected_equal)
2345+
<< SecKind;
23452346
return;
23462347
}
23472348

clang/lib/Parse/Parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void Parser::ConsumeExtraSemi(ExtraSemiKind Kind, DeclSpec::TST TST) {
226226

227227
if (Kind != ExtraSemiKind::AfterMemberFunctionDefinition || HadMultipleSemis)
228228
Diag(StartLoc, diag::ext_extra_semi)
229-
<< llvm::to_underlying(Kind)
229+
<< Kind
230230
<< DeclSpec::getSpecifierName(
231231
TST, Actions.getASTContext().getPrintingPolicy())
232232
<< FixItHint::CreateRemoval(SourceRange(StartLoc, EndLoc));

clang/lib/Sema/SemaAccess.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,24 +1670,21 @@ Sema::AccessResult Sema::CheckConstructorAccess(SourceLocation UseLoc,
16701670
case InitializedEntity::EK_Base:
16711671
PD = PDiag(diag::err_access_base_ctor);
16721672
PD << Entity.isInheritedVirtualBase()
1673-
<< Entity.getBaseSpecifier()->getType()
1674-
<< llvm::to_underlying(getSpecialMember(Constructor));
1673+
<< Entity.getBaseSpecifier()->getType() << getSpecialMember(Constructor);
16751674
break;
16761675

16771676
case InitializedEntity::EK_Member:
16781677
case InitializedEntity::EK_ParenAggInitMember: {
16791678
const FieldDecl *Field = cast<FieldDecl>(Entity.getDecl());
16801679
PD = PDiag(diag::err_access_field_ctor);
1681-
PD << Field->getType()
1682-
<< llvm::to_underlying(getSpecialMember(Constructor));
1680+
PD << Field->getType() << getSpecialMember(Constructor);
16831681
break;
16841682
}
16851683

16861684
case InitializedEntity::EK_LambdaCapture: {
16871685
StringRef VarName = Entity.getCapturedVarName();
16881686
PD = PDiag(diag::err_access_lambda_capture);
1689-
PD << VarName << Entity.getType()
1690-
<< llvm::to_underlying(getSpecialMember(Constructor));
1687+
PD << VarName << Entity.getType() << getSpecialMember(Constructor);
16911688
break;
16921689
}
16931690

clang/lib/Sema/SemaCUDA.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,7 @@ bool SemaCUDA::inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
450450
if (Diagnose) {
451451
Diag(ClassDecl->getLocation(),
452452
diag::note_implicit_member_target_infer_collision)
453-
<< (unsigned)CSM << llvm::to_underlying(*InferredTarget)
454-
<< llvm::to_underlying(BaseMethodTarget);
453+
<< (unsigned)CSM << *InferredTarget << BaseMethodTarget;
455454
}
456455
MemberDecl->addAttr(
457456
CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
@@ -496,8 +495,7 @@ bool SemaCUDA::inferTargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl,
496495
if (Diagnose) {
497496
Diag(ClassDecl->getLocation(),
498497
diag::note_implicit_member_target_infer_collision)
499-
<< (unsigned)CSM << llvm::to_underlying(*InferredTarget)
500-
<< llvm::to_underlying(FieldMethodTarget);
498+
<< (unsigned)CSM << *InferredTarget << FieldMethodTarget;
501499
}
502500
MemberDecl->addAttr(
503501
CUDAInvalidTargetAttr::CreateImplicit(getASTContext()));
@@ -713,7 +711,7 @@ void SemaCUDA::checkAllowedInitializer(VarDecl *VD) {
713711
if (InitFnTarget != CUDAFunctionTarget::Host &&
714712
InitFnTarget != CUDAFunctionTarget::HostDevice) {
715713
Diag(VD->getLocation(), diag::err_ref_bad_target_global_initializer)
716-
<< llvm::to_underlying(InitFnTarget) << InitFn;
714+
<< InitFnTarget << InitFn;
717715
Diag(InitFn->getLocation(), diag::note_previous_decl) << InitFn;
718716
VD->setInvalidDecl();
719717
}
@@ -952,8 +950,8 @@ bool SemaCUDA::CheckCall(SourceLocation Loc, FunctionDecl *Callee) {
952950

953951
SemaDiagnosticBuilder(DiagKind, Loc, diag::err_ref_bad_target, Caller,
954952
SemaRef)
955-
<< llvm::to_underlying(IdentifyTarget(Callee)) << /*function*/ 0 << Callee
956-
<< llvm::to_underlying(IdentifyTarget(Caller));
953+
<< IdentifyTarget(Callee) << /*function*/ 0 << Callee
954+
<< IdentifyTarget(Caller);
957955
if (!Callee->getBuiltinID())
958956
SemaDiagnosticBuilder(DiagKind, Callee->getLocation(),
959957
diag::note_previous_decl, Caller, SemaRef)
@@ -1049,8 +1047,7 @@ void SemaCUDA::checkTargetOverload(FunctionDecl *NewFD,
10491047
(NewTarget == CUDAFunctionTarget::Global) ||
10501048
(OldTarget == CUDAFunctionTarget::Global)) {
10511049
Diag(NewFD->getLocation(), diag::err_cuda_ovl_target)
1052-
<< llvm::to_underlying(NewTarget) << NewFD->getDeclName()
1053-
<< llvm::to_underlying(OldTarget) << OldFD;
1050+
<< NewTarget << NewFD->getDeclName() << OldTarget << OldFD;
10541051
Diag(OldFD->getLocation(), diag::note_previous_declaration);
10551052
NewFD->setInvalidDecl();
10561053
break;
@@ -1060,7 +1057,7 @@ void SemaCUDA::checkTargetOverload(FunctionDecl *NewFD,
10601057
(NewTarget == CUDAFunctionTarget::Device &&
10611058
OldTarget == CUDAFunctionTarget::Host)) {
10621059
Diag(NewFD->getLocation(), diag::warn_offload_incompatible_redeclare)
1063-
<< llvm::to_underlying(NewTarget) << llvm::to_underlying(OldTarget);
1060+
<< NewTarget << OldTarget;
10641061
Diag(OldFD->getLocation(), diag::note_previous_declaration);
10651062
}
10661063
}

clang/lib/Sema/SemaChecking.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8384,8 +8384,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
83848384
} else {
83858385
EmitFormatDiagnostic(
83868386
S.PDiag(diag::warn_non_pod_vararg_with_format_string)
8387-
<< S.getLangOpts().CPlusPlus11 << ExprTy
8388-
<< llvm::to_underlying(CallType)
8387+
<< S.getLangOpts().CPlusPlus11 << ExprTy << CallType
83898388
<< AT.getRepresentativeTypeName(S.Context) << CSR
83908389
<< E->getSourceRange(),
83918390
E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
@@ -8399,16 +8398,15 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
83998398
else if (ExprTy->isObjCObjectType())
84008399
EmitFormatDiagnostic(
84018400
S.PDiag(diag::err_cannot_pass_objc_interface_to_vararg_format)
8402-
<< S.getLangOpts().CPlusPlus11 << ExprTy
8403-
<< llvm::to_underlying(CallType)
8401+
<< S.getLangOpts().CPlusPlus11 << ExprTy << CallType
84048402
<< AT.getRepresentativeTypeName(S.Context) << CSR
84058403
<< E->getSourceRange(),
84068404
E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
84078405
else
84088406
// FIXME: If this is an initializer list, suggest removing the braces
84098407
// or inserting a cast to the target type.
84108408
S.Diag(E->getBeginLoc(), diag::err_cannot_pass_to_vararg_format)
8411-
<< isa<InitListExpr>(E) << ExprTy << llvm::to_underlying(CallType)
8409+
<< isa<InitListExpr>(E) << ExprTy << CallType
84128410
<< AT.getRepresentativeTypeName(S.Context) << E->getSourceRange();
84138411
break;
84148412
}

clang/lib/Sema/SemaDecl.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4730,13 +4730,13 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
47304730
} else {
47314731
Diag(NewMethod->getLocation(),
47324732
diag::err_definition_of_implicitly_declared_member)
4733-
<< New << llvm::to_underlying(getSpecialMember(OldMethod));
4733+
<< New << getSpecialMember(OldMethod);
47344734
return true;
47354735
}
47364736
} else if (OldMethod->getFirstDecl()->isExplicitlyDefaulted() && !isFriend) {
47374737
Diag(NewMethod->getLocation(),
47384738
diag::err_definition_of_explicitly_defaulted_member)
4739-
<< llvm::to_underlying(getSpecialMember(OldMethod));
4739+
<< getSpecialMember(OldMethod);
47404740
return true;
47414741
}
47424742
}
@@ -5955,7 +5955,7 @@ Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS,
59555955
if (DS.isModulePrivateSpecified() &&
59565956
Tag && Tag->getDeclContext()->isFunctionOrMethod())
59575957
Diag(DS.getModulePrivateSpecLoc(), diag::err_module_private_local_class)
5958-
<< llvm::to_underlying(Tag->getTagKind())
5958+
<< Tag->getTagKind()
59595959
<< FixItHint::CreateRemoval(DS.getModulePrivateSpecLoc());
59605960

59615961
ActOnDocumentableDecl(TagD);
@@ -8519,15 +8519,14 @@ NamedDecl *Sema::ActOnVariableDeclarator(
85198519
// data members.
85208520
Diag(D.getIdentifierLoc(),
85218521
diag::err_static_data_member_not_allowed_in_local_class)
8522-
<< Name << RD->getDeclName()
8523-
<< llvm::to_underlying(RD->getTagKind());
8522+
<< Name << RD->getDeclName() << RD->getTagKind();
85248523
} else if (AnonStruct) {
85258524
// C++ [class.static.data]p4: Unnamed classes and classes contained
85268525
// directly or indirectly within unnamed classes shall not contain
85278526
// static data members.
85288527
Diag(D.getIdentifierLoc(),
85298528
diag::err_static_data_member_not_allowed_in_anon_struct)
8530-
<< Name << llvm::to_underlying(AnonStruct->getTagKind());
8529+
<< Name << AnonStruct->getTagKind();
85318530
Invalid = true;
85328531
} else if (RD->isUnion()) {
85338532
// C++98 [class.union]p1: If a union contains a static data member,
@@ -18758,7 +18757,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1875818757

1875918758
// A tag 'foo::bar' must already exist.
1876018759
Diag(NameLoc, diag::err_not_tag_in_scope)
18761-
<< llvm::to_underlying(Kind) << Name << DC << SS.getRange();
18760+
<< Kind << Name << DC << SS.getRange();
1876218761
Name = nullptr;
1876318762
Invalid = true;
1876418763
goto CreateNewDecl;
@@ -19216,7 +19215,7 @@ Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc,
1921619215
!Previous.isForRedeclaration()) {
1921719216
NonTagKind NTK = getNonTagTypeDeclKind(PrevDecl, Kind);
1921819217
Diag(NameLoc, diag::err_tag_reference_non_tag)
19219-
<< PrevDecl << NTK << llvm::to_underlying(Kind);
19218+
<< PrevDecl << NTK << Kind;
1922019219
Diag(PrevDecl->getLocation(), diag::note_declared_at);
1922119220
Invalid = true;
1922219221

@@ -20121,8 +20120,7 @@ bool Sema::CheckNontrivialField(FieldDecl *FD) {
2012120120
getLangOpts().CPlusPlus11
2012220121
? diag::warn_cxx98_compat_nontrivial_union_or_anon_struct_member
2012320122
: diag::err_illegal_union_or_anon_struct_member)
20124-
<< FD->getParent()->isUnion() << FD->getDeclName()
20125-
<< llvm::to_underlying(member);
20123+
<< FD->getParent()->isUnion() << FD->getDeclName() << member;
2012620124
DiagnoseNontrivial(RDecl, member);
2012720125
return !getLangOpts().CPlusPlus11;
2012820126
}
@@ -20462,8 +20460,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
2046220460
unsigned DiagID = 0;
2046320461
if (!Record->isUnion() && !IsLastField) {
2046420462
Diag(FD->getLocation(), diag::err_flexible_array_not_at_end)
20465-
<< FD->getDeclName() << FD->getType()
20466-
<< llvm::to_underlying(Record->getTagKind());
20463+
<< FD->getDeclName() << FD->getType() << Record->getTagKind();
2046720464
Diag((*(i + 1))->getLocation(), diag::note_next_field_declaration);
2046820465
FD->setInvalidDecl();
2046920466
EnclosingDecl->setInvalidDecl();
@@ -20479,18 +20476,18 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl,
2047920476

2048020477
if (DiagID)
2048120478
Diag(FD->getLocation(), DiagID)
20482-
<< FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
20479+
<< FD->getDeclName() << Record->getTagKind();
2048320480
// While the layout of types that contain virtual bases is not specified
2048420481
// by the C++ standard, both the Itanium and Microsoft C++ ABIs place
2048520482
// virtual bases after the derived members. This would make a flexible
2048620483
// array member declared at the end of an object not adjacent to the end
2048720484
// of the type.
2048820485
if (CXXRecord && CXXRecord->getNumVBases() != 0)
2048920486
Diag(FD->getLocation(), diag::err_flexible_array_virtual_base)
20490-
<< FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
20487+
<< FD->getDeclName() << Record->getTagKind();
2049120488
if (!getLangOpts().C99)
2049220489
Diag(FD->getLocation(), diag::ext_c99_flexible_array_member)
20493-
<< FD->getDeclName() << llvm::to_underlying(Record->getTagKind());
20490+
<< FD->getDeclName() << Record->getTagKind();
2049420491

2049520492
// If the element type has a non-trivial destructor, we would not
2049620493
// implicitly destroy the elements, so disallow it for now.

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5218,7 +5218,7 @@ static void handleSharedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
52185218
}
52195219
if (S.getLangOpts().CUDA && VD->hasLocalStorage() &&
52205220
S.CUDA().DiagIfHostCode(AL.getLoc(), diag::err_cuda_host_shared)
5221-
<< llvm::to_underlying(S.CUDA().CurrentTarget()))
5221+
<< S.CUDA().CurrentTarget())
52225222
return;
52235223
D->addAttr(::new (S.Context) CUDASharedAttr(S.Context, AL));
52245224
}

0 commit comments

Comments
 (0)