Skip to content

Commit c4c7d35

Browse files
committed
merge main into amd-staging
merge to just before flang-new rename Change-Id: I9bf2314b8f8f615cd050a52204186411cca35bd2
2 parents f0facc9 + f1eac77 commit c4c7d35

File tree

67 files changed

+2663
-1128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2663
-1128
lines changed

bolt/lib/Profile/YAMLProfileReader.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,7 @@ size_t YAMLProfileReader::matchWithNameSimilarity(BinaryContext &BC) {
643643
// equal number of blocks.
644644
if (NamespaceToProfiledBFSizesIt->second.count(BF->size()) == 0)
645645
continue;
646-
auto NamespaceToBFsIt = NamespaceToBFs.find(Namespace);
647-
if (NamespaceToBFsIt == NamespaceToBFs.end())
648-
NamespaceToBFs[Namespace] = {BF};
649-
else
650-
NamespaceToBFsIt->second.push_back(BF);
646+
NamespaceToBFs[Namespace].push_back(BF);
651647
}
652648

653649
// Iterates through all profiled functions and binary functions belonging to

clang/docs/ReleaseNotes.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ C++23 Feature Support
179179
C++20 Feature Support
180180
^^^^^^^^^^^^^^^^^^^^^
181181

182+
C++17 Feature Support
183+
^^^^^^^^^^^^^^^^^^^^^
184+
- The implementation of the relaxed template template argument matching rules is
185+
more complete and reliable, and should provide more accurate diagnostics.
182186

183187
Resolutions to C++ Defect Reports
184188
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -205,7 +209,8 @@ Resolutions to C++ Defect Reports
205209
(`CWG2351: void{} <https://cplusplus.github.io/CWG/issues/2351.html>`_).
206210

207211
- Clang now has improved resolution to CWG2398, allowing class templates to have
208-
default arguments deduced when partial ordering.
212+
default arguments deduced when partial ordering, and better backwards compatibility
213+
in overload resolution.
209214

210215
- Clang now allows comparing unequal object pointers that have been cast to ``void *``
211216
in constant expressions. These comparisons always worked in non-constant expressions.
@@ -356,6 +361,10 @@ Improvements to Clang's diagnostics
356361

357362
- Clang now diagnoses when the result of a [[nodiscard]] function is discarded after being cast in C. Fixes #GH104391.
358363

364+
- Clang now properly explains the reason a template template argument failed to
365+
match a template template parameter, in terms of the C++17 relaxed matching rules
366+
instead of the old ones.
367+
359368
- Don't emit duplicated dangling diagnostics. (#GH93386).
360369

361370
- Improved diagnostic when trying to befriend a concept. (#GH45182).
@@ -465,6 +474,8 @@ Bug Fixes to C++ Support
465474
- Correctly check constraints of explicit instantiations of member functions. (#GH46029)
466475
- When performing partial ordering of function templates, clang now checks that
467476
the deduction was consistent. Fixes (#GH18291).
477+
- Fixes to several issues in partial ordering of template template parameters, which
478+
were documented in the test suite.
468479
- Fixed an assertion failure about a constraint of a friend function template references to a value with greater
469480
template depth than the friend function template. (#GH98258)
470481
- Clang now rebuilds the template parameters of out-of-line declarations and specializations in the context
@@ -503,6 +514,8 @@ Bug Fixes to C++ Support
503514
- Clang now instantiates the correct lambda call operator when a lambda's class type is
504515
merged across modules. (#GH110401)
505516
- Fix a crash when parsing a pseudo destructor involving an invalid type. (#GH111460)
517+
- Fixed an assertion failure when invoking recovery call expressions with explicit attributes
518+
and undeclared templates. (#GH107047, #GH49093)
506519

507520
Bug Fixes to AST Handling
508521
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/DeclBase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@ class alignas(8) Decl {
687687
/// Whether this declaration comes from a named module.
688688
bool isInNamedModule() const;
689689

690+
/// Whether this declaration comes from a header unit.
691+
bool isFromHeaderUnit() const;
692+
690693
/// Return true if this declaration has an attribute which acts as
691694
/// definition of the entity, such as 'alias' or 'ifunc'.
692695
bool hasDefiningAttr() const;

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,6 +5262,13 @@ def note_template_arg_refers_here_func : Note<
52625262
def err_template_arg_template_params_mismatch : Error<
52635263
"template template argument has different template parameters than its "
52645264
"corresponding template template parameter">;
5265+
def note_template_arg_template_params_mismatch : Note<
5266+
"template template argument has different template parameters than its "
5267+
"corresponding template template parameter">;
5268+
def err_non_deduced_mismatch : Error<
5269+
"could not match %diff{$ against $|types}0,1">;
5270+
def err_inconsistent_deduction : Error<
5271+
"conflicting deduction %diff{$ against $|types}0,1 for parameter">;
52655272
def err_template_arg_not_integral_or_enumeral : Error<
52665273
"non-type template argument of type %0 must have an integral or enumeration"
52675274
" type">;

clang/include/clang/Sema/Overload.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ class Sema;
925925

926926
bool TookAddressOfOverload : 1;
927927

928+
/// Have we matched any packs on the parameter side, versus any non-packs on
929+
/// the argument side, in a context where the opposite matching is also
930+
/// allowed?
931+
bool HasMatchedPackOnParmToNonPackOnArg : 1;
932+
928933
/// True if the candidate was found using ADL.
929934
CallExpr::ADLCallKind IsADLCandidate : 1;
930935

@@ -999,8 +1004,9 @@ class Sema;
9991004
friend class OverloadCandidateSet;
10001005
OverloadCandidate()
10011006
: IsSurrogate(false), IgnoreObjectArgument(false),
1002-
TookAddressOfOverload(false), IsADLCandidate(CallExpr::NotADL),
1003-
RewriteKind(CRK_None) {}
1007+
TookAddressOfOverload(false),
1008+
HasMatchedPackOnParmToNonPackOnArg(false),
1009+
IsADLCandidate(CallExpr::NotADL), RewriteKind(CRK_None) {}
10041010
};
10051011

10061012
/// OverloadCandidateSet - A set of overload candidates, used in C++

clang/include/clang/Sema/Sema.h

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,9 +4457,10 @@ class Sema final : public SemaBase {
44574457
SourceLocation *ArgLocation = nullptr);
44584458

44594459
/// Determine if type T is a valid subject for a nonnull and similar
4460-
/// attributes. By default, we look through references (the behavior used by
4461-
/// nonnull), but if the second parameter is true, then we treat a reference
4462-
/// type as valid.
4460+
/// attributes. Dependent types are considered valid so they can be checked
4461+
/// during instantiation time. By default, we look through references (the
4462+
/// behavior used by nonnull), but if the second parameter is true, then we
4463+
/// treat a reference type as valid.
44634464
bool isValidPointerAttrType(QualType T, bool RefOkay = false);
44644465

44654466
/// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular
@@ -10132,7 +10133,8 @@ class Sema final : public SemaBase {
1013210133
ADLCallKind IsADLCandidate = ADLCallKind::NotADL,
1013310134
ConversionSequenceList EarlyConversions = std::nullopt,
1013410135
OverloadCandidateParamOrder PO = {},
10135-
bool AggregateCandidateDeduction = false);
10136+
bool AggregateCandidateDeduction = false,
10137+
bool HasMatchedPackOnParmToNonPackOnArg = false);
1013610138

1013710139
/// Add all of the function declarations in the given function set to
1013810140
/// the overload candidate set.
@@ -10167,7 +10169,8 @@ class Sema final : public SemaBase {
1016710169
bool SuppressUserConversions = false,
1016810170
bool PartialOverloading = false,
1016910171
ConversionSequenceList EarlyConversions = std::nullopt,
10170-
OverloadCandidateParamOrder PO = {});
10172+
OverloadCandidateParamOrder PO = {},
10173+
bool HasMatchedPackOnParmToNonPackOnArg = false);
1017110174

1017210175
/// Add a C++ member function template as a candidate to the candidate
1017310176
/// set, using template argument deduction to produce an appropriate member
@@ -10213,7 +10216,8 @@ class Sema final : public SemaBase {
1021310216
CXXConversionDecl *Conversion, DeclAccessPair FoundDecl,
1021410217
CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
1021510218
OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit,
10216-
bool AllowExplicit, bool AllowResultConversion = true);
10219+
bool AllowExplicit, bool AllowResultConversion = true,
10220+
bool HasMatchedPackOnParmToNonPackOnArg = false);
1021710221

1021810222
/// Adds a conversion function template specialization
1021910223
/// candidate to the overload set, using template argument deduction
@@ -11636,7 +11640,8 @@ class Sema final : public SemaBase {
1163611640
SourceLocation RAngleLoc, unsigned ArgumentPackIndex,
1163711641
SmallVectorImpl<TemplateArgument> &SugaredConverted,
1163811642
SmallVectorImpl<TemplateArgument> &CanonicalConverted,
11639-
CheckTemplateArgumentKind CTAK);
11643+
CheckTemplateArgumentKind CTAK, bool PartialOrdering,
11644+
bool *MatchedPackOnParmToNonPackOnArg);
1164011645

1164111646
/// Check that the given template arguments can be provided to
1164211647
/// the given template, converting the arguments along the way.
@@ -11683,7 +11688,8 @@ class Sema final : public SemaBase {
1168311688
SmallVectorImpl<TemplateArgument> &SugaredConverted,
1168411689
SmallVectorImpl<TemplateArgument> &CanonicalConverted,
1168511690
bool UpdateArgsWithConversions = true,
11686-
bool *ConstraintsNotSatisfied = nullptr, bool PartialOrderingTTP = false);
11691+
bool *ConstraintsNotSatisfied = nullptr, bool PartialOrderingTTP = false,
11692+
bool *MatchedPackOnParmToNonPackOnArg = nullptr);
1168711693

1168811694
bool CheckTemplateTypeArgument(
1168911695
TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg,
@@ -11717,7 +11723,9 @@ class Sema final : public SemaBase {
1171711723
/// It returns true if an error occurred, and false otherwise.
1171811724
bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param,
1171911725
TemplateParameterList *Params,
11720-
TemplateArgumentLoc &Arg, bool IsDeduced);
11726+
TemplateArgumentLoc &Arg,
11727+
bool PartialOrdering,
11728+
bool *MatchedPackOnParmToNonPackOnArg);
1172111729

1172211730
void NoteTemplateLocation(const NamedDecl &Decl,
1172311731
std::optional<SourceRange> ParamRange = {});
@@ -12228,8 +12236,8 @@ class Sema final : public SemaBase {
1222812236
SmallVectorImpl<DeducedTemplateArgument> &Deduced,
1222912237
unsigned NumExplicitlySpecified, FunctionDecl *&Specialization,
1223012238
sema::TemplateDeductionInfo &Info,
12231-
SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr,
12232-
bool PartialOverloading = false,
12239+
SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs,
12240+
bool PartialOverloading, bool PartialOrdering,
1223312241
llvm::function_ref<bool()> CheckNonDependent = [] { return false; });
1223412242

1223512243
/// Perform template argument deduction from a function call
@@ -12263,7 +12271,8 @@ class Sema final : public SemaBase {
1226312271
TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args,
1226412272
FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info,
1226512273
bool PartialOverloading, bool AggregateDeductionCandidate,
12266-
QualType ObjectType, Expr::Classification ObjectClassification,
12274+
bool PartialOrdering, QualType ObjectType,
12275+
Expr::Classification ObjectClassification,
1226712276
llvm::function_ref<bool(ArrayRef<QualType>)> CheckNonDependent);
1226812277

1226912278
/// Deduce template arguments when taking the address of a function
@@ -12416,8 +12425,9 @@ class Sema final : public SemaBase {
1241612425
sema::TemplateDeductionInfo &Info);
1241712426

1241812427
bool isTemplateTemplateParameterAtLeastAsSpecializedAs(
12419-
TemplateParameterList *PParam, TemplateDecl *AArg,
12420-
const DefaultArguments &DefaultArgs, SourceLocation Loc, bool IsDeduced);
12428+
TemplateParameterList *PParam, TemplateDecl *PArg, TemplateDecl *AArg,
12429+
const DefaultArguments &DefaultArgs, SourceLocation ArgLoc,
12430+
bool PartialOrdering, bool *MatchedPackOnParmToNonPackOnArg);
1242112431

1242212432
/// Mark which template parameters are used in a given expression.
1242312433
///
@@ -12726,6 +12736,9 @@ class Sema final : public SemaBase {
1272612736

1272712737
/// We are instantiating a type alias template declaration.
1272812738
TypeAliasTemplateInstantiation,
12739+
12740+
/// We are performing partial ordering for template template parameters.
12741+
PartialOrderingTTP,
1272912742
} Kind;
1273012743

1273112744
/// Was the enclosing context a non-instantiation SFINAE context?
@@ -12947,6 +12960,12 @@ class Sema final : public SemaBase {
1294712960
TemplateDecl *Entity, BuildingDeductionGuidesTag,
1294812961
SourceRange InstantiationRange = SourceRange());
1294912962

12963+
struct PartialOrderingTTP {};
12964+
/// \brief Note that we are partial ordering template template parameters.
12965+
InstantiatingTemplate(Sema &SemaRef, SourceLocation ArgLoc,
12966+
PartialOrderingTTP, TemplateDecl *PArg,
12967+
SourceRange InstantiationRange = SourceRange());
12968+
1295012969
/// Note that we have finished instantiating this template.
1295112970
void Clear();
1295212971

@@ -13407,7 +13426,8 @@ class Sema final : public SemaBase {
1340713426
bool InstantiateClassTemplateSpecialization(
1340813427
SourceLocation PointOfInstantiation,
1340913428
ClassTemplateSpecializationDecl *ClassTemplateSpec,
13410-
TemplateSpecializationKind TSK, bool Complain = true);
13429+
TemplateSpecializationKind TSK, bool Complain = true,
13430+
bool PrimaryHasMatchedPackOnParmToNonPackOnArg = false);
1341113431

1341213432
/// Instantiates the definitions of all of the member
1341313433
/// of the given class, which is an instantiation of a class template

clang/include/clang/Sema/TemplateDeduction.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ class TemplateDeductionInfo {
5151
/// Have we suppressed an error during deduction?
5252
bool HasSFINAEDiagnostic = false;
5353

54+
/// Have we matched any packs on the parameter side, versus any non-packs on
55+
/// the argument side, in a context where the opposite matching is also
56+
/// allowed?
57+
bool MatchedPackOnParmToNonPackOnArg = false;
58+
5459
/// The template parameter depth for which we're performing deduction.
5560
unsigned DeducedDepth;
5661

@@ -87,6 +92,14 @@ class TemplateDeductionInfo {
8792
return DeducedDepth;
8893
}
8994

95+
bool hasMatchedPackOnParmToNonPackOnArg() const {
96+
return MatchedPackOnParmToNonPackOnArg;
97+
}
98+
99+
void setMatchedPackOnParmToNonPackOnArg() {
100+
MatchedPackOnParmToNonPackOnArg = true;
101+
}
102+
90103
/// Get the number of explicitly-specified arguments.
91104
unsigned getNumExplicitArgs() const {
92105
return ExplicitArgs;

clang/include/clang/Serialization/ASTReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2527,7 +2527,7 @@ class BitsUnpacker {
25272527

25282528
inline bool shouldSkipCheckingODR(const Decl *D) {
25292529
return D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
2530-
D->isFromGlobalModule();
2530+
(D->isFromGlobalModule() || D->isFromHeaderUnit());
25312531
}
25322532

25332533
} // namespace clang

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3406,7 +3406,7 @@ bool Compiler<Emitter>::VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
34063406
if (!this->visit(Arg))
34073407
return false;
34083408

3409-
return this->emitFree(E->isArrayForm(), E);
3409+
return this->emitFree(E->isArrayForm(), E->isGlobalDelete(), E);
34103410
}
34113411

34123412
template <class Emitter>

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ static bool runRecordDestructor(InterpState &S, CodePtr OpPC,
964964
return true;
965965
}
966966

967-
bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
967+
static bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
968968
assert(B);
969969
const Descriptor *Desc = B->getDescriptor();
970970

@@ -989,6 +989,89 @@ bool RunDestructors(InterpState &S, CodePtr OpPC, const Block *B) {
989989
return runRecordDestructor(S, OpPC, Pointer(const_cast<Block *>(B)), Desc);
990990
}
991991

992+
bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
993+
bool IsGlobalDelete) {
994+
if (!CheckDynamicMemoryAllocation(S, OpPC))
995+
return false;
996+
997+
const Expr *Source = nullptr;
998+
const Block *BlockToDelete = nullptr;
999+
{
1000+
// Extra scope for this so the block doesn't have this pointer
1001+
// pointing to it when we destroy it.
1002+
Pointer Ptr = S.Stk.pop<Pointer>();
1003+
1004+
// Deleteing nullptr is always fine.
1005+
if (Ptr.isZero())
1006+
return true;
1007+
1008+
// Remove base casts.
1009+
while (Ptr.isBaseClass())
1010+
Ptr = Ptr.getBase();
1011+
1012+
if (!Ptr.isRoot() || Ptr.isOnePastEnd() || Ptr.isArrayElement()) {
1013+
const SourceInfo &Loc = S.Current->getSource(OpPC);
1014+
S.FFDiag(Loc, diag::note_constexpr_delete_subobject)
1015+
<< Ptr.toDiagnosticString(S.getASTContext()) << Ptr.isOnePastEnd();
1016+
return false;
1017+
}
1018+
1019+
Source = Ptr.getDeclDesc()->asExpr();
1020+
BlockToDelete = Ptr.block();
1021+
1022+
if (!CheckDeleteSource(S, OpPC, Source, Ptr))
1023+
return false;
1024+
1025+
// For a class type with a virtual destructor, the selected operator delete
1026+
// is the one looked up when building the destructor.
1027+
QualType AllocType = Ptr.getType();
1028+
if (!DeleteIsArrayForm && !IsGlobalDelete) {
1029+
auto getVirtualOperatorDelete = [](QualType T) -> const FunctionDecl * {
1030+
if (const CXXRecordDecl *RD = T->getAsCXXRecordDecl())
1031+
if (const CXXDestructorDecl *DD = RD->getDestructor())
1032+
return DD->isVirtual() ? DD->getOperatorDelete() : nullptr;
1033+
return nullptr;
1034+
};
1035+
1036+
AllocType->dump();
1037+
if (const FunctionDecl *VirtualDelete =
1038+
getVirtualOperatorDelete(AllocType);
1039+
VirtualDelete &&
1040+
!VirtualDelete->isReplaceableGlobalAllocationFunction()) {
1041+
S.FFDiag(S.Current->getSource(OpPC),
1042+
diag::note_constexpr_new_non_replaceable)
1043+
<< isa<CXXMethodDecl>(VirtualDelete) << VirtualDelete;
1044+
return false;
1045+
}
1046+
}
1047+
}
1048+
assert(Source);
1049+
assert(BlockToDelete);
1050+
1051+
// Invoke destructors before deallocating the memory.
1052+
if (!RunDestructors(S, OpPC, BlockToDelete))
1053+
return false;
1054+
1055+
DynamicAllocator &Allocator = S.getAllocator();
1056+
const Descriptor *BlockDesc = BlockToDelete->getDescriptor();
1057+
std::optional<DynamicAllocator::Form> AllocForm =
1058+
Allocator.getAllocationForm(Source);
1059+
1060+
if (!Allocator.deallocate(Source, BlockToDelete, S)) {
1061+
// Nothing has been deallocated, this must be a double-delete.
1062+
const SourceInfo &Loc = S.Current->getSource(OpPC);
1063+
S.FFDiag(Loc, diag::note_constexpr_double_delete);
1064+
return false;
1065+
}
1066+
1067+
assert(AllocForm);
1068+
DynamicAllocator::Form DeleteForm = DeleteIsArrayForm
1069+
? DynamicAllocator::Form::Array
1070+
: DynamicAllocator::Form::NonArray;
1071+
return CheckNewDeleteForms(S, OpPC, *AllocForm, DeleteForm, BlockDesc,
1072+
Source);
1073+
}
1074+
9921075
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED,
9931076
const APSInt &Value) {
9941077
llvm::APInt Min;

0 commit comments

Comments
 (0)