Skip to content

Commit 6d83d9c

Browse files
authored
merge main into amd-staging (llvm#1475)
2 parents 9558fc4 + 0e3884f commit 6d83d9c

File tree

59 files changed

+1632
-245
lines changed

Some content is hidden

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

59 files changed

+1632
-245
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ Bug Fixes to Attribute Support
381381
Bug Fixes to C++ Support
382382
^^^^^^^^^^^^^^^^^^^^^^^^
383383

384+
- Clang now supports implicitly defined comparison operators for friend declarations. (#GH132249)
384385
- Clang now diagnoses copy constructors taking the class by value in template instantiations. (#GH130866)
385386
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
386387
- Clang now prints the correct instantiation context for diagnostics suppressed

clang/include/clang/AST/ASTContext.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,10 +1795,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
17951795
QualType Wrapped, QualType Contained,
17961796
const HLSLAttributedResourceType::Attributes &Attrs);
17971797

1798-
QualType
1799-
getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
1800-
unsigned Index,
1801-
std::optional<unsigned> PackIndex) const;
1798+
QualType getSubstTemplateTypeParmType(QualType Replacement,
1799+
Decl *AssociatedDecl, unsigned Index,
1800+
std::optional<unsigned> PackIndex,
1801+
bool Final) const;
18021802
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl,
18031803
unsigned Index, bool Final,
18041804
const TemplateArgument &ArgPack);
@@ -2393,10 +2393,11 @@ class ASTContext : public RefCountedBase<ASTContext> {
23932393
TemplateName
23942394
getDependentTemplateName(const DependentTemplateStorage &Name) const;
23952395

2396-
TemplateName
2397-
getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl,
2398-
unsigned Index,
2399-
std::optional<unsigned> PackIndex) const;
2396+
TemplateName getSubstTemplateTemplateParm(TemplateName replacement,
2397+
Decl *AssociatedDecl,
2398+
unsigned Index,
2399+
std::optional<unsigned> PackIndex,
2400+
bool Final) const;
24002401
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack,
24012402
Decl *AssociatedDecl,
24022403
unsigned Index,

clang/include/clang/AST/ExprCXX.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4514,7 +4514,9 @@ class SubstNonTypeTemplateParmExpr : public Expr {
45144514
llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndRef;
45154515

45164516
unsigned Index : 15;
4517-
unsigned PackIndex : 16;
4517+
unsigned PackIndex : 15;
4518+
LLVM_PREFERRED_TYPE(bool)
4519+
unsigned Final : 1;
45184520

45194521
explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
45204522
: Expr(SubstNonTypeTemplateParmExprClass, Empty) {}
@@ -4523,11 +4525,12 @@ class SubstNonTypeTemplateParmExpr : public Expr {
45234525
SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind,
45244526
SourceLocation Loc, Expr *Replacement,
45254527
Decl *AssociatedDecl, unsigned Index,
4526-
std::optional<unsigned> PackIndex, bool RefParam)
4528+
std::optional<unsigned> PackIndex, bool RefParam,
4529+
bool Final)
45274530
: Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary),
45284531
Replacement(Replacement),
45294532
AssociatedDeclAndRef(AssociatedDecl, RefParam), Index(Index),
4530-
PackIndex(PackIndex ? *PackIndex + 1 : 0) {
4533+
PackIndex(PackIndex ? *PackIndex + 1 : 0), Final(Final) {
45314534
assert(AssociatedDecl != nullptr);
45324535
SubstNonTypeTemplateParmExprBits.NameLoc = Loc;
45334536
setDependence(computeDependence(this));
@@ -4555,6 +4558,10 @@ class SubstNonTypeTemplateParmExpr : public Expr {
45554558
return PackIndex - 1;
45564559
}
45574560

4561+
// This substitution is Final, which means the substitution is fully
4562+
// sugared: it doesn't need to be resugared later.
4563+
bool getFinal() const { return Final; }
4564+
45584565
NonTypeTemplateParmDecl *getParameter() const;
45594566

45604567
bool isReferenceParameter() const { return AssociatedDeclAndRef.getInt(); }
@@ -4598,7 +4605,10 @@ class SubstNonTypeTemplateParmPackExpr : public Expr {
45984605
const TemplateArgument *Arguments;
45994606

46004607
/// The number of template arguments in \c Arguments.
4601-
unsigned NumArguments : 16;
4608+
unsigned NumArguments : 15;
4609+
4610+
LLVM_PREFERRED_TYPE(bool)
4611+
unsigned Final : 1;
46024612

46034613
unsigned Index : 16;
46044614

@@ -4612,7 +4622,8 @@ class SubstNonTypeTemplateParmPackExpr : public Expr {
46124622
SubstNonTypeTemplateParmPackExpr(QualType T, ExprValueKind ValueKind,
46134623
SourceLocation NameLoc,
46144624
const TemplateArgument &ArgPack,
4615-
Decl *AssociatedDecl, unsigned Index);
4625+
Decl *AssociatedDecl, unsigned Index,
4626+
bool Final);
46164627

46174628
/// A template-like entity which owns the whole pattern being substituted.
46184629
/// This will own a set of template parameters.
@@ -4622,6 +4633,10 @@ class SubstNonTypeTemplateParmPackExpr : public Expr {
46224633
/// This should match the result of `getParameterPack()->getIndex()`.
46234634
unsigned getIndex() const { return Index; }
46244635

4636+
// This substitution will be Final, which means the substitution will be fully
4637+
// sugared: it doesn't need to be resugared later.
4638+
bool getFinal() const { return Final; }
4639+
46254640
/// Retrieve the non-type template parameter pack being substituted.
46264641
NonTypeTemplateParmDecl *getParameterPack() const;
46274642

clang/include/clang/AST/PropertiesBase.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,9 @@ let Class = PropertyTypeCase<TemplateName, "SubstTemplateTemplateParm"> in {
730730
def : Property<"packIndex", Optional<UInt32>> {
731731
let Read = [{ parm->getPackIndex() }];
732732
}
733+
def : Property<"final", Bool> { let Read = [{ parm->getFinal() }]; }
733734
def : Creator<[{
734-
return ctx.getSubstTemplateTemplateParm(replacement, associatedDecl, index, packIndex);
735+
return ctx.getSubstTemplateTemplateParm(replacement, associatedDecl, index, packIndex, final);
735736
}]>;
736737
}
737738
let Class = PropertyTypeCase<TemplateName, "SubstTemplateTemplateParmPack"> in {

clang/include/clang/AST/TemplateName.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,11 @@ class SubstTemplateTemplateParmStorage
414414

415415
SubstTemplateTemplateParmStorage(TemplateName Replacement,
416416
Decl *AssociatedDecl, unsigned Index,
417-
std::optional<unsigned> PackIndex)
417+
std::optional<unsigned> PackIndex,
418+
bool Final)
418419
: UncommonTemplateNameStorage(SubstTemplateTemplateParm, Index,
419-
PackIndex ? *PackIndex + 1 : 0),
420+
((PackIndex ? *PackIndex + 1 : 0) << 1) |
421+
Final),
420422
Replacement(Replacement), AssociatedDecl(AssociatedDecl) {
421423
assert(AssociatedDecl != nullptr);
422424
}
@@ -430,10 +432,15 @@ class SubstTemplateTemplateParmStorage
430432
/// This should match the result of `getParameter()->getIndex()`.
431433
unsigned getIndex() const { return Bits.Index; }
432434

435+
// This substitution is Final, which means the substitution is fully
436+
// sugared: it doesn't need to be resugared later.
437+
bool getFinal() const { return Bits.Data & 1; }
438+
433439
std::optional<unsigned> getPackIndex() const {
434-
if (Bits.Data == 0)
440+
auto Data = Bits.Data >> 1;
441+
if (Data == 0)
435442
return std::nullopt;
436-
return Bits.Data - 1;
443+
return Data - 1;
437444
}
438445

439446
TemplateTemplateParmDecl *getParameter() const;
@@ -443,7 +450,7 @@ class SubstTemplateTemplateParmStorage
443450

444451
static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Replacement,
445452
Decl *AssociatedDecl, unsigned Index,
446-
std::optional<unsigned> PackIndex);
453+
std::optional<unsigned> PackIndex, bool Final);
447454
};
448455

449456
class DeducedTemplateStorage : public UncommonTemplateNameStorage,

clang/include/clang/AST/Type.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,12 +2158,15 @@ class alignas(TypeAlignment) Type : public ExtQualsTypeCommonBase {
21582158
// The index of the template parameter this substitution represents.
21592159
unsigned Index : 15;
21602160

2161+
LLVM_PREFERRED_TYPE(bool)
2162+
unsigned Final : 1;
2163+
21612164
/// Represents the index within a pack if this represents a substitution
21622165
/// from a pack expansion. This index starts at the end of the pack and
21632166
/// increments towards the beginning.
21642167
/// Positive non-zero number represents the index + 1.
21652168
/// Zero means this is not substituted from an expansion.
2166-
unsigned PackIndex : 16;
2169+
unsigned PackIndex : 15;
21672170
};
21682171

21692172
class SubstTemplateTypeParmPackTypeBitfields {
@@ -6397,7 +6400,8 @@ class SubstTemplateTypeParmType final
63976400
Decl *AssociatedDecl;
63986401

63996402
SubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
6400-
unsigned Index, std::optional<unsigned> PackIndex);
6403+
unsigned Index, std::optional<unsigned> PackIndex,
6404+
bool Final);
64016405

64026406
public:
64036407
/// Gets the type that was substituted for the template
@@ -6420,6 +6424,10 @@ class SubstTemplateTypeParmType final
64206424
/// This should match the result of `getReplacedParameter()->getIndex()`.
64216425
unsigned getIndex() const { return SubstTemplateTypeParmTypeBits.Index; }
64226426

6427+
// This substitution is Final, which means the substitution is fully
6428+
// sugared: it doesn't need to be resugared later.
6429+
unsigned getFinal() const { return SubstTemplateTypeParmTypeBits.Final; }
6430+
64236431
std::optional<unsigned> getPackIndex() const {
64246432
if (SubstTemplateTypeParmTypeBits.PackIndex == 0)
64256433
return std::nullopt;
@@ -6431,17 +6439,12 @@ class SubstTemplateTypeParmType final
64316439

64326440
void Profile(llvm::FoldingSetNodeID &ID) {
64336441
Profile(ID, getReplacementType(), getAssociatedDecl(), getIndex(),
6434-
getPackIndex());
6442+
getPackIndex(), getFinal());
64356443
}
64366444

64376445
static void Profile(llvm::FoldingSetNodeID &ID, QualType Replacement,
64386446
const Decl *AssociatedDecl, unsigned Index,
6439-
std::optional<unsigned> PackIndex) {
6440-
Replacement.Profile(ID);
6441-
ID.AddPointer(AssociatedDecl);
6442-
ID.AddInteger(Index);
6443-
ID.AddInteger(PackIndex ? *PackIndex - 1 : 0);
6444-
}
6447+
std::optional<unsigned> PackIndex, bool Final);
64456448

64466449
static bool classof(const Type *T) {
64476450
return T->getTypeClass() == SubstTemplateTypeParm;
@@ -6488,7 +6491,8 @@ class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode {
64886491
/// This should match the result of `getReplacedParameter()->getIndex()`.
64896492
unsigned getIndex() const { return SubstTemplateTypeParmPackTypeBits.Index; }
64906493

6491-
// When true the substitution will be 'Final' (subst node won't be placed).
6494+
// This substitution will be Final, which means the substitution will be fully
6495+
// sugared: it doesn't need to be resugared later.
64926496
bool getFinal() const;
64936497

64946498
unsigned getNumArgs() const {

clang/include/clang/AST/TypeProperties.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,11 +842,11 @@ let Class = SubstTemplateTypeParmType in {
842842
def : Property<"PackIndex", Optional<UInt32>> {
843843
let Read = [{ node->getPackIndex() }];
844844
}
845+
def : Property<"Final", Bool> { let Read = [{ node->getFinal() }]; }
845846

846-
// The call to getCanonicalType here existed in ASTReader.cpp, too.
847847
def : Creator<[{
848848
return ctx.getSubstTemplateTypeParmType(
849-
replacementType, associatedDecl, Index, PackIndex);
849+
replacementType, associatedDecl, Index, PackIndex, Final);
850850
}]>;
851851
}
852852

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,17 +697,24 @@ def UnaryOp : CIR_Op<"unary", [Pure, SameOperandsAndResultType]> {
697697
It requires one input operand and has one result, both types
698698
should be the same.
699699

700+
If the `nsw` (no signed wrap) attribute is present, the result is poison if
701+
signed overflow occurs.
702+
700703
```mlir
701704
%7 = cir.unary(inc, %1) : i32 -> i32
702-
%8 = cir.unary(dec, %2) : i32 -> i32
705+
%8 = cir.unary(dec, %2) nsw : i32 -> i32
703706
```
704707
}];
705708

706709
let results = (outs CIR_AnyType:$result);
707-
let arguments = (ins Arg<UnaryOpKind, "unary op kind">:$kind, Arg<CIR_AnyType>:$input);
710+
let arguments = (ins Arg<UnaryOpKind, "unary op kind">:$kind,
711+
Arg<CIR_AnyType>:$input,
712+
UnitAttr:$no_signed_wrap);
708713

709714
let assemblyFormat = [{
710-
`(` $kind `,` $input `)` `:` type($input) `,` type($result) attr-dict
715+
`(` $kind `,` $input `)`
716+
(`nsw` $no_signed_wrap^)?
717+
`:` type($input) `,` type($result) attr-dict
711718
}];
712719

713720
let hasVerifier = 1;
@@ -961,9 +968,21 @@ def BinOp : CIR_Op<"binop", [Pure,
961968
It requires two input operands and has one result, all types
962969
should be the same.
963970

971+
If the `nsw` (no signed wrap) or `nuw` (no unsigned wrap) attributes are
972+
present, the result is poison if signed or unsigned overflow occurs
973+
(respectively).
974+
975+
If the `sat` (saturated) attribute is present, the result is clamped to
976+
the maximum value representatable by the type if it would otherwise
977+
exceed that value and is clamped to the minimum representable value if
978+
it would otherwise be below that value.
979+
964980
```mlir
965-
%7 = cir.binop(add, %1, %2) : !s32i
966-
%7 = cir.binop(mul, %1, %2) : !u8i
981+
%5 = cir.binop(add, %1, %2) : !s32i
982+
%6 = cir.binop(mul, %1, %2) : !u8i
983+
%7 = cir.binop(add, %1, %2) nsw : !s32i
984+
%8 = cir.binop(add, %3, %4) nuw : !u32i
985+
%9 = cir.binop(add, %1, %2) sat : !s32i
967986
```
968987
}];
969988

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ struct MissingFeatures {
7676
static bool opScopeCleanupRegion() { return false; }
7777

7878
// Unary operator handling
79-
static bool opUnarySignedOverflow() { return false; }
8079
static bool opUnaryPromotionType() { return false; }
8180

8281
// Clang early optimizations or things defered to LLVM lowering.

clang/lib/AST/ASTContext.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5447,10 +5447,10 @@ QualType ASTContext::getHLSLAttributedResourceType(
54475447
/// Retrieve a substitution-result type.
54485448
QualType ASTContext::getSubstTemplateTypeParmType(
54495449
QualType Replacement, Decl *AssociatedDecl, unsigned Index,
5450-
std::optional<unsigned> PackIndex) const {
5450+
std::optional<unsigned> PackIndex, bool Final) const {
54515451
llvm::FoldingSetNodeID ID;
54525452
SubstTemplateTypeParmType::Profile(ID, Replacement, AssociatedDecl, Index,
5453-
PackIndex);
5453+
PackIndex, Final);
54545454
void *InsertPos = nullptr;
54555455
SubstTemplateTypeParmType *SubstParm =
54565456
SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
@@ -5460,7 +5460,7 @@ QualType ASTContext::getSubstTemplateTypeParmType(
54605460
!Replacement.isCanonical()),
54615461
alignof(SubstTemplateTypeParmType));
54625462
SubstParm = new (Mem) SubstTemplateTypeParmType(Replacement, AssociatedDecl,
5463-
Index, PackIndex);
5463+
Index, PackIndex, Final);
54645464
Types.push_back(SubstParm);
54655465
SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
54665466
}
@@ -10090,18 +10090,18 @@ ASTContext::getDependentTemplateName(const DependentTemplateStorage &S) const {
1009010090

1009110091
TemplateName ASTContext::getSubstTemplateTemplateParm(
1009210092
TemplateName Replacement, Decl *AssociatedDecl, unsigned Index,
10093-
std::optional<unsigned> PackIndex) const {
10093+
std::optional<unsigned> PackIndex, bool Final) const {
1009410094
llvm::FoldingSetNodeID ID;
1009510095
SubstTemplateTemplateParmStorage::Profile(ID, Replacement, AssociatedDecl,
10096-
Index, PackIndex);
10096+
Index, PackIndex, Final);
1009710097

1009810098
void *insertPos = nullptr;
1009910099
SubstTemplateTemplateParmStorage *subst
1010010100
= SubstTemplateTemplateParms.FindNodeOrInsertPos(ID, insertPos);
1010110101

1010210102
if (!subst) {
1010310103
subst = new (*this) SubstTemplateTemplateParmStorage(
10104-
Replacement, AssociatedDecl, Index, PackIndex);
10104+
Replacement, AssociatedDecl, Index, PackIndex, Final);
1010510105
SubstTemplateTemplateParms.InsertNode(subst, insertPos);
1010610106
}
1010710107

@@ -14202,7 +14202,8 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
1420214202
if (PackIndex != SY->getPackIndex())
1420314203
return QualType();
1420414204
return Ctx.getSubstTemplateTypeParmType(Ctx.getQualifiedType(Underlying),
14205-
CD, Index, PackIndex);
14205+
CD, Index, PackIndex,
14206+
SX->getFinal() && SY->getFinal());
1420614207
}
1420714208
case Type::ObjCTypeParam:
1420814209
// FIXME: Try to merge these.

0 commit comments

Comments
 (0)