Skip to content

Commit 49e9381

Browse files
authored
merge main into amd-staging (llvm#1411)
2 parents 60cc425 + 6e64c7e commit 49e9381

File tree

122 files changed

+896
-647
lines changed

Some content is hidden

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

122 files changed

+896
-647
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14660,7 +14660,8 @@ class Sema final : public SemaBase {
1466014660
bool First = true);
1466114661

1466214662
const NormalizedConstraint *getNormalizedAssociatedConstraints(
14663-
NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints);
14663+
const NamedDecl *ConstrainedDecl,
14664+
ArrayRef<const Expr *> AssociatedConstraints);
1466414665

1466514666
/// \brief Check whether the given declaration's associated constraints are
1466614667
/// at least as constrained than another declaration's according to the
@@ -14670,28 +14671,30 @@ class Sema final : public SemaBase {
1467014671
/// at least constrained than D2, and false otherwise.
1467114672
///
1467214673
/// \returns true if an error occurred, false otherwise.
14673-
bool IsAtLeastAsConstrained(NamedDecl *D1, MutableArrayRef<const Expr *> AC1,
14674-
NamedDecl *D2, MutableArrayRef<const Expr *> AC2,
14675-
bool &Result);
14674+
bool IsAtLeastAsConstrained(const NamedDecl *D1,
14675+
MutableArrayRef<const Expr *> AC1,
14676+
const NamedDecl *D2,
14677+
MutableArrayRef<const Expr *> AC2, bool &Result);
1467614678

1467714679
/// If D1 was not at least as constrained as D2, but would've been if a pair
1467814680
/// of atomic constraints involved had been declared in a concept and not
1467914681
/// repeated in two separate places in code.
1468014682
/// \returns true if such a diagnostic was emitted, false otherwise.
1468114683
bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic(
14682-
NamedDecl *D1, ArrayRef<const Expr *> AC1, NamedDecl *D2,
14684+
const NamedDecl *D1, ArrayRef<const Expr *> AC1, const NamedDecl *D2,
1468314685
ArrayRef<const Expr *> AC2);
1468414686

1468514687
private:
1468614688
/// Caches pairs of template-like decls whose associated constraints were
1468714689
/// checked for subsumption and whether or not the first's constraints did in
1468814690
/// fact subsume the second's.
14689-
llvm::DenseMap<std::pair<NamedDecl *, NamedDecl *>, bool> SubsumptionCache;
14691+
llvm::DenseMap<std::pair<const NamedDecl *, const NamedDecl *>, bool>
14692+
SubsumptionCache;
1469014693
/// Caches the normalized associated constraints of declarations (concepts or
1469114694
/// constrained declarations). If an error occurred while normalizing the
1469214695
/// associated constraints of the template or concept, nullptr will be cached
1469314696
/// here.
14694-
llvm::DenseMap<NamedDecl *, NormalizedConstraint *> NormalizationCache;
14697+
llvm::DenseMap<const NamedDecl *, NormalizedConstraint *> NormalizationCache;
1469514698

1469614699
llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &>
1469714700
SatisfactionCache;

clang/include/clang/Sema/SemaConcept.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ enum { ConstraintAlignment = 8 };
3131

3232
struct alignas(ConstraintAlignment) AtomicConstraint {
3333
const Expr *ConstraintExpr;
34-
NamedDecl *ConstraintDecl;
34+
const NamedDecl *ConstraintDecl;
3535
std::optional<ArrayRef<TemplateArgumentLoc>> ParameterMapping;
3636

37-
AtomicConstraint(const Expr *ConstraintExpr, NamedDecl *ConstraintDecl)
37+
AtomicConstraint(const Expr *ConstraintExpr, const NamedDecl *ConstraintDecl)
3838
: ConstraintExpr(ConstraintExpr), ConstraintDecl(ConstraintDecl) {};
3939

4040
bool hasMatchingParameterMapping(ASTContext &C,
@@ -114,9 +114,9 @@ struct NormalizedConstraint {
114114

115115
private:
116116
static std::optional<NormalizedConstraint>
117-
fromConstraintExprs(Sema &S, NamedDecl *D, ArrayRef<const Expr *> E);
117+
fromConstraintExprs(Sema &S, const NamedDecl *D, ArrayRef<const Expr *> E);
118118
static std::optional<NormalizedConstraint>
119-
fromConstraintExpr(Sema &S, NamedDecl *D, const Expr *E);
119+
fromConstraintExpr(Sema &S, const NamedDecl *D, const Expr *E);
120120
};
121121

122122
struct alignas(ConstraintAlignment) NormalizedConstraintPair {
@@ -137,7 +137,7 @@ struct alignas(ConstraintAlignment) FoldExpandedConstraint {
137137
};
138138

139139
const NormalizedConstraint *getNormalizedAssociatedConstraints(
140-
Sema &S, NamedDecl *ConstrainedDecl,
140+
Sema &S, const NamedDecl *ConstrainedDecl,
141141
ArrayRef<const Expr *> AssociatedConstraints);
142142

143143
/// \brief SubsumptionChecker establishes subsumption
@@ -149,8 +149,8 @@ class SubsumptionChecker {
149149

150150
SubsumptionChecker(Sema &SemaRef, SubsumptionCallable Callable = {});
151151

152-
std::optional<bool> Subsumes(NamedDecl *DP, ArrayRef<const Expr *> P,
153-
NamedDecl *DQ, ArrayRef<const Expr *> Q);
152+
std::optional<bool> Subsumes(const NamedDecl *DP, ArrayRef<const Expr *> P,
153+
const NamedDecl *DQ, ArrayRef<const Expr *> Q);
154154

155155
bool Subsumes(const NormalizedConstraint *P, const NormalizedConstraint *Q);
156156

clang/lib/AST/ASTContext.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14135,7 +14135,6 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
1413514135
CANONICAL_TYPE(IncompleteArray)
1413614136
CANONICAL_TYPE(HLSLAttributedResource)
1413714137
CANONICAL_TYPE(LValueReference)
14138-
CANONICAL_TYPE(MemberPointer)
1413914138
CANONICAL_TYPE(ObjCInterface)
1414014139
CANONICAL_TYPE(ObjCObject)
1414114140
CANONICAL_TYPE(ObjCObjectPointer)
@@ -14313,6 +14312,15 @@ static QualType getCommonSugarTypeNode(ASTContext &Ctx, const Type *X,
1431314312
return QualType();
1431414313
return Ctx.getUsingType(CD, Ctx.getQualifiedType(Underlying));
1431514314
}
14315+
case Type::MemberPointer: {
14316+
const auto *PX = cast<MemberPointerType>(X),
14317+
*PY = cast<MemberPointerType>(Y);
14318+
CXXRecordDecl *Cls = PX->getMostRecentCXXRecordDecl();
14319+
assert(Cls == PY->getMostRecentCXXRecordDecl());
14320+
return Ctx.getMemberPointerType(
14321+
::getCommonPointeeType(Ctx, PX, PY),
14322+
::getCommonQualifier(Ctx, PX, PY, /*IsSame=*/false), Cls);
14323+
}
1431614324
case Type::CountAttributed: {
1431714325
const auto *DX = cast<CountAttributedType>(X),
1431814326
*DY = cast<CountAttributedType>(Y);

clang/lib/Sema/SemaConcept.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ static ExprResult calculateConstraintSatisfaction(
453453
Sema::InstantiatingTemplate Inst(
454454
S, AtomicExpr->getBeginLoc(),
455455
Sema::InstantiatingTemplate::ConstraintSubstitution{},
456+
// FIXME: improve const-correctness of InstantiatingTemplate
456457
const_cast<NamedDecl *>(Template), Info,
457458
AtomicExpr->getSourceRange());
458459
if (Inst.isInvalid())
@@ -1435,9 +1436,9 @@ void Sema::DiagnoseUnsatisfiedConstraint(
14351436
}
14361437
}
14371438

1438-
const NormalizedConstraint *
1439-
Sema::getNormalizedAssociatedConstraints(
1440-
NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints) {
1439+
const NormalizedConstraint *Sema::getNormalizedAssociatedConstraints(
1440+
const NamedDecl *ConstrainedDecl,
1441+
ArrayRef<const Expr *> AssociatedConstraints) {
14411442
// In case the ConstrainedDecl comes from modules, it is necessary to use
14421443
// the canonical decl to avoid different atomic constraints with the 'same'
14431444
// declarations.
@@ -1461,7 +1462,7 @@ Sema::getNormalizedAssociatedConstraints(
14611462
}
14621463

14631464
const NormalizedConstraint *clang::getNormalizedAssociatedConstraints(
1464-
Sema &S, NamedDecl *ConstrainedDecl,
1465+
Sema &S, const NamedDecl *ConstrainedDecl,
14651466
ArrayRef<const Expr *> AssociatedConstraints) {
14661467
return S.getNormalizedAssociatedConstraints(ConstrainedDecl,
14671468
AssociatedConstraints);
@@ -1527,7 +1528,8 @@ substituteParameterMappings(Sema &S, NormalizedConstraint &N,
15271528
Sema::InstantiatingTemplate Inst(
15281529
S, InstLocBegin,
15291530
Sema::InstantiatingTemplate::ParameterMappingSubstitution{},
1530-
Atomic.ConstraintDecl, {InstLocBegin, InstLocEnd});
1531+
const_cast<NamedDecl *>(Atomic.ConstraintDecl),
1532+
{InstLocBegin, InstLocEnd});
15311533
if (Inst.isInvalid())
15321534
return true;
15331535
if (S.SubstTemplateArguments(*Atomic.ParameterMapping, MLTAL, SubstArgs))
@@ -1591,7 +1593,7 @@ NormalizedConstraint &NormalizedConstraint::getRHS() const {
15911593
}
15921594

15931595
std::optional<NormalizedConstraint>
1594-
NormalizedConstraint::fromConstraintExprs(Sema &S, NamedDecl *D,
1596+
NormalizedConstraint::fromConstraintExprs(Sema &S, const NamedDecl *D,
15951597
ArrayRef<const Expr *> E) {
15961598
assert(E.size() != 0);
15971599
auto Conjunction = fromConstraintExpr(S, D, E[0]);
@@ -1608,7 +1610,8 @@ NormalizedConstraint::fromConstraintExprs(Sema &S, NamedDecl *D,
16081610
}
16091611

16101612
std::optional<NormalizedConstraint>
1611-
NormalizedConstraint::fromConstraintExpr(Sema &S, NamedDecl *D, const Expr *E) {
1613+
NormalizedConstraint::fromConstraintExpr(Sema &S, const NamedDecl *D,
1614+
const Expr *E) {
16121615
assert(E != nullptr);
16131616

16141617
// C++ [temp.constr.normal]p1.1
@@ -1637,8 +1640,9 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, NamedDecl *D, const Expr *E) {
16371640
{
16381641
Sema::InstantiatingTemplate Inst(
16391642
S, CSE->getExprLoc(),
1640-
Sema::InstantiatingTemplate::ConstraintNormalization{}, D,
1641-
CSE->getSourceRange());
1643+
Sema::InstantiatingTemplate::ConstraintNormalization{},
1644+
// FIXME: improve const-correctness of InstantiatingTemplate
1645+
const_cast<NamedDecl *>(D), CSE->getSourceRange());
16421646
if (Inst.isInvalid())
16431647
return std::nullopt;
16441648
// C++ [temp.constr.normal]p1.1
@@ -1726,9 +1730,9 @@ bool FoldExpandedConstraint::AreCompatibleForSubsumption(
17261730
return false;
17271731
}
17281732

1729-
bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
1733+
bool Sema::IsAtLeastAsConstrained(const NamedDecl *D1,
17301734
MutableArrayRef<const Expr *> AC1,
1731-
NamedDecl *D2,
1735+
const NamedDecl *D2,
17321736
MutableArrayRef<const Expr *> AC2,
17331737
bool &Result) {
17341738
#ifndef NDEBUG
@@ -1755,7 +1759,7 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
17551759
return false;
17561760
}
17571761

1758-
std::pair<NamedDecl *, NamedDecl *> Key{D1, D2};
1762+
std::pair<const NamedDecl *, const NamedDecl *> Key{D1, D2};
17591763
auto CacheEntry = SubsumptionCache.find(Key);
17601764
if (CacheEntry != SubsumptionCache.end()) {
17611765
Result = CacheEntry->second;
@@ -1789,7 +1793,7 @@ bool Sema::IsAtLeastAsConstrained(NamedDecl *D1,
17891793
}
17901794

17911795
bool Sema::MaybeEmitAmbiguousAtomicConstraintsDiagnostic(
1792-
NamedDecl *D1, ArrayRef<const Expr *> AC1, NamedDecl *D2,
1796+
const NamedDecl *D1, ArrayRef<const Expr *> AC1, const NamedDecl *D2,
17931797
ArrayRef<const Expr *> AC2) {
17941798

17951799
if (isSFINAEContext())
@@ -2055,7 +2059,7 @@ FormulaType SubsumptionChecker::Normalize(const NormalizedConstraint &NC) {
20552059
FormulaType Res;
20562060

20572061
auto Add = [&, this](Clause C) {
2058-
// Sort each clause and remove duplicates for faster comparisons
2062+
// Sort each clause and remove duplicates for faster comparisons.
20592063
llvm::sort(C);
20602064
C.erase(llvm::unique(C), C.end());
20612065
AddUniqueClauseToFormula(Res, std::move(C));
@@ -2102,9 +2106,9 @@ void SubsumptionChecker::AddUniqueClauseToFormula(Formula &F, Clause C) {
21022106
F.push_back(C);
21032107
}
21042108

2105-
std::optional<bool> SubsumptionChecker::Subsumes(NamedDecl *DP,
2109+
std::optional<bool> SubsumptionChecker::Subsumes(const NamedDecl *DP,
21062110
ArrayRef<const Expr *> P,
2107-
NamedDecl *DQ,
2111+
const NamedDecl *DQ,
21082112
ArrayRef<const Expr *> Q) {
21092113
const NormalizedConstraint *PNormalized =
21102114
getNormalizedAssociatedConstraints(SemaRef, DP, P);

clang/test/SemaCXX/sugar-common-types.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,19 @@ namespace arrays {
186186
// expected-error@-1 {{lvalue of type 'const volatile volatile B1[1]' (aka 'const volatile volatile int[1]')}}
187187
} // namespace balanced_qualifiers
188188
} // namespace arrays
189+
190+
namespace member_pointers {
191+
template <class T> struct W {
192+
X1 a;
193+
Y1 b;
194+
};
195+
struct W1 : W<X2> {};
196+
struct W2 : W<Y2> {};
197+
198+
N t1 = 0 ? &W<X2>::a : &W<Y2>::b;
199+
// expected-error@-1 {{rvalue of type 'B1 W<B2>::*'}}
200+
201+
// FIXME: adjusted MemberPointer does not preserve qualifier
202+
N t3 = 0 ? &W1::a : &W2::b;
203+
// expected-error@-1 {{rvalue of type 'B1 W<void>::*'}}
204+
} // namespace member_pointers

libcxx/include/__config

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,25 +363,22 @@ typedef __char32_t char32_t;
363363
# endif
364364

365365
# if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) || (defined(__MINGW32__) && !defined(_LIBCPP_BUILDING_LIBRARY))
366-
# define _LIBCPP_DLL_VIS
367366
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
368367
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
369368
# define _LIBCPP_OVERRIDABLE_FUNC_VIS
370369
# define _LIBCPP_EXPORTED_FROM_ABI
371370
# elif defined(_LIBCPP_BUILDING_LIBRARY)
372-
# define _LIBCPP_DLL_VIS __declspec(dllexport)
373371
# if defined(__MINGW32__)
374-
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
372+
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllexport)
375373
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
376374
# else
377375
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
378-
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
376+
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __declspec(dllexport)
379377
# endif
380-
# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
378+
# define _LIBCPP_OVERRIDABLE_FUNC_VIS __declspec(dllexport)
381379
# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
382380
# else
383-
# define _LIBCPP_DLL_VIS __declspec(dllimport)
384-
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
381+
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __declspec(dllimport)
385382
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
386383
# define _LIBCPP_OVERRIDABLE_FUNC_VIS
387384
# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "llvm/ADT/DenseMap.h"
1919
#include "llvm/ADT/MapVector.h"
2020
#include "llvm/ADT/SmallVector.h"
21+
#include "llvm/Analysis/ProfileSummaryInfo.h"
22+
#include "llvm/Analysis/StaticDataProfileInfo.h"
2123
#include "llvm/BinaryFormat/Dwarf.h"
2224
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
2325
#include "llvm/CodeGen/MachineFunctionPass.h"
@@ -132,6 +134,12 @@ class AsmPrinter : public MachineFunctionPass {
132134
/// default, this is equal to CurrentFnSym.
133135
MCSymbol *CurrentFnSymForSize = nullptr;
134136

137+
/// Provides the profile information for constants.
138+
const StaticDataProfileInfo *SDPI = nullptr;
139+
140+
/// The profile summary information.
141+
const ProfileSummaryInfo *PSI = nullptr;
142+
135143
/// Map a basic block section ID to the begin and end symbols of that section
136144
/// which determine the section's range.
137145
struct MBBSectionRange {
@@ -330,6 +338,10 @@ class AsmPrinter : public MachineFunctionPass {
330338
DwarfUsesRelocationsAcrossSections = Enable;
331339
}
332340

341+
/// Returns a section suffix (hot or unlikely) for the constant if profiles
342+
/// are available. Returns empty string otherwise.
343+
StringRef getConstantSectionSuffix(const Constant *C) const;
344+
333345
//===------------------------------------------------------------------===//
334346
// XRay instrumentation implementation.
335347
//===------------------------------------------------------------------===//

llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
6666
const Constant *C,
6767
Align &Alignment) const override;
6868

69+
/// Similar to the function above, but append \p SectionSuffix to the section
70+
/// name.
71+
MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
72+
const Constant *C, Align &Alignment,
73+
StringRef SectionSuffix) const override;
74+
6975
MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
7076
const TargetMachine &TM) const override;
7177

llvm/include/llvm/Target/TargetLoweringObjectFile.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
104104
SectionKind Kind, const Constant *C,
105105
Align &Alignment) const;
106106

107+
/// Similar to the function above, but append \p SectionSuffix to the section
108+
/// name.
109+
virtual MCSection *getSectionForConstant(const DataLayout &DL,
110+
SectionKind Kind, const Constant *C,
111+
Align &Alignment,
112+
StringRef SectionSuffix) const;
113+
107114
virtual MCSection *
108115
getSectionForMachineBasicBlock(const Function &F,
109116
const MachineBasicBlock &MBB,

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2816,6 +2816,13 @@ namespace {
28162816

28172817
} // end anonymous namespace
28182818

2819+
StringRef AsmPrinter::getConstantSectionSuffix(const Constant *C) const {
2820+
if (TM.Options.EnableStaticDataPartitioning && C && SDPI && PSI)
2821+
return SDPI->getConstantSectionPrefix(C, PSI);
2822+
2823+
return "";
2824+
}
2825+
28192826
/// EmitConstantPool - Print to the current output stream assembly
28202827
/// representations of the constants in the constant pool MCP. This is
28212828
/// used to print out constants which have been "spilled to memory" by
@@ -2839,7 +2846,7 @@ void AsmPrinter::emitConstantPool() {
28392846
C = CPE.Val.ConstVal;
28402847

28412848
MCSection *S = getObjFileLowering().getSectionForConstant(
2842-
getDataLayout(), Kind, C, Alignment);
2849+
getDataLayout(), Kind, C, Alignment, getConstantSectionSuffix(C));
28432850

28442851
// The number of sections are small, just do a linear search from the
28452852
// last section to the first.

0 commit comments

Comments
 (0)