Skip to content

Commit 5379a1b

Browse files
authored
merge main into amd-staging (llvm#702)
2 parents 808bf02 + 1b04b65 commit 5379a1b

File tree

366 files changed

+12517
-9529
lines changed

Some content is hidden

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

366 files changed

+12517
-9529
lines changed

clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ void IncludeModernizePPCallbacks::InclusionDirective(
199199
// 2. Insert `using namespace std;` to the beginning of TU.
200200
// 3. Do nothing and let the user deal with the migration himself.
201201
SourceLocation DiagLoc = FilenameRange.getBegin();
202-
if (CStyledHeaderToCxx.count(FileName) != 0) {
203-
IncludesToBeProcessed.emplace_back(
204-
IncludeMarker{CStyledHeaderToCxx[FileName], FileName,
205-
FilenameRange.getAsRange(), DiagLoc});
202+
if (auto It = CStyledHeaderToCxx.find(FileName);
203+
It != CStyledHeaderToCxx.end()) {
204+
IncludesToBeProcessed.emplace_back(IncludeMarker{
205+
It->second, FileName, FilenameRange.getAsRange(), DiagLoc});
206206
} else if (DeleteHeaders.count(FileName) != 0) {
207207
IncludesToBeProcessed.emplace_back(
208208
// NOLINTNEXTLINE(modernize-use-emplace) - false-positive

clang/include/clang/AST/ASTContext.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
287287
/// This is lazily created. This is intentionally not serialized.
288288
mutable llvm::DenseMap<const RecordDecl*, const ASTRecordLayout*>
289289
ASTRecordLayouts;
290-
mutable llvm::DenseMap<const ObjCContainerDecl*, const ASTRecordLayout*>
291-
ObjCLayouts;
290+
mutable llvm::DenseMap<const ObjCInterfaceDecl *, const ASTRecordLayout *>
291+
ObjCLayouts;
292292

293293
/// A cache from types to size and alignment information.
294294
using TypeInfoMap = llvm::DenseMap<const Type *, struct TypeInfo>;
@@ -500,6 +500,11 @@ class ASTContext : public RefCountedBase<ASTContext> {
500500
static constexpr unsigned GeneralTypesLog2InitSize = 9;
501501
static constexpr unsigned FunctionProtoTypesLog2InitSize = 12;
502502

503+
/// A mapping from an ObjC class to its subclasses.
504+
llvm::DenseMap<const ObjCInterfaceDecl *,
505+
SmallVector<const ObjCInterfaceDecl *, 4>>
506+
ObjCSubClasses;
507+
503508
ASTContext &this_() { return *this; }
504509

505510
public:
@@ -2671,13 +2676,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
26712676
void DumpRecordLayout(const RecordDecl *RD, raw_ostream &OS,
26722677
bool Simple = false) const;
26732678

2674-
/// Get or compute information about the layout of the specified
2675-
/// Objective-C implementation.
2676-
///
2677-
/// This may differ from the interface if synthesized ivars are present.
2678-
const ASTRecordLayout &
2679-
getASTObjCImplementationLayout(const ObjCImplementationDecl *D) const;
2680-
26812679
/// Get our current best idea for the key function of the
26822680
/// given record decl, or nullptr if there isn't one.
26832681
///
@@ -2716,7 +2714,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
27162714

27172715
/// Get the offset of an ObjCIvarDecl in bits.
27182716
uint64_t lookupFieldBitOffset(const ObjCInterfaceDecl *OID,
2719-
const ObjCImplementationDecl *ID,
27202717
const ObjCIvarDecl *Ivar) const;
27212718

27222719
/// Find the 'this' offset for the member path in a pointer-to-member
@@ -3174,7 +3171,12 @@ class ASTContext : public RefCountedBase<ASTContext> {
31743171
bool &CanUseFirst, bool &CanUseSecond,
31753172
SmallVectorImpl<FunctionProtoType::ExtParameterInfo> &NewParamInfos);
31763173

3177-
void ResetObjCLayout(const ObjCContainerDecl *CD);
3174+
void ResetObjCLayout(const ObjCInterfaceDecl *D);
3175+
3176+
void addObjCSubClass(const ObjCInterfaceDecl *D,
3177+
const ObjCInterfaceDecl *SubClass) {
3178+
ObjCSubClasses[D].push_back(SubClass);
3179+
}
31783180

31793181
//===--------------------------------------------------------------------===//
31803182
// Integer Predicates
@@ -3564,9 +3566,7 @@ OPT_LIST(V)
35643566
friend class DeclarationNameTable;
35653567
friend class DeclContext;
35663568

3567-
const ASTRecordLayout &
3568-
getObjCLayout(const ObjCInterfaceDecl *D,
3569-
const ObjCImplementationDecl *Impl) const;
3569+
const ASTRecordLayout &getObjCLayout(const ObjCInterfaceDecl *D) const;
35703570

35713571
/// A set of deallocations that should be performed when the
35723572
/// ASTContext is destroyed.

clang/lib/AST/ASTContext.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,11 @@ void ASTContext::cleanup() {
948948

949949
// ASTRecordLayout objects in ASTRecordLayouts must always be destroyed
950950
// because they can contain DenseMaps.
951-
for (llvm::DenseMap<const ObjCContainerDecl*,
952-
const ASTRecordLayout*>::iterator
953-
I = ObjCLayouts.begin(), E = ObjCLayouts.end(); I != E; )
951+
for (llvm::DenseMap<const ObjCInterfaceDecl *,
952+
const ASTRecordLayout *>::iterator
953+
I = ObjCLayouts.begin(),
954+
E = ObjCLayouts.end();
955+
I != E;)
954956
// Increment in loop to prevent using deallocated memory.
955957
if (auto *R = const_cast<ASTRecordLayout *>((I++)->second))
956958
R->Destroy(*this);
@@ -3092,13 +3094,7 @@ TypeSourceInfo *ASTContext::getTrivialTypeSourceInfo(QualType T,
30923094

30933095
const ASTRecordLayout &
30943096
ASTContext::getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const {
3095-
return getObjCLayout(D, nullptr);
3096-
}
3097-
3098-
const ASTRecordLayout &
3099-
ASTContext::getASTObjCImplementationLayout(
3100-
const ObjCImplementationDecl *D) const {
3101-
return getObjCLayout(D->getClassInterface(), D);
3097+
return getObjCLayout(D);
31023098
}
31033099

31043100
static auto getCanonicalTemplateArguments(const ASTContext &C,
@@ -8916,8 +8912,7 @@ static void EncodeBitField(const ASTContext *Ctx, std::string& S,
89168912
uint64_t Offset;
89178913

89188914
if (const auto *IVD = dyn_cast<ObjCIvarDecl>(FD)) {
8919-
Offset = Ctx->lookupFieldBitOffset(IVD->getContainingInterface(), nullptr,
8920-
IVD);
8915+
Offset = Ctx->lookupFieldBitOffset(IVD->getContainingInterface(), IVD);
89218916
} else {
89228917
const RecordDecl *RD = FD->getParent();
89238918
const ASTRecordLayout &RL = Ctx->getASTRecordLayout(RD);
@@ -11848,8 +11843,12 @@ bool ASTContext::mergeExtParameterInfo(
1184811843
return true;
1184911844
}
1185011845

11851-
void ASTContext::ResetObjCLayout(const ObjCContainerDecl *CD) {
11852-
ObjCLayouts[CD] = nullptr;
11846+
void ASTContext::ResetObjCLayout(const ObjCInterfaceDecl *D) {
11847+
if (ObjCLayouts.count(D)) {
11848+
ObjCLayouts[D] = nullptr;
11849+
for (auto *SubClass : ObjCSubClasses[D])
11850+
ResetObjCLayout(SubClass);
11851+
}
1185311852
}
1185411853

1185511854
/// mergeObjCGCQualifiers - This routine merges ObjC's GC attribute of 'LHS' and

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace interp {
2929
template <class Emitter> class DeclScope final : public LocalScope<Emitter> {
3030
public:
3131
DeclScope(Compiler<Emitter> *Ctx, const ValueDecl *VD)
32-
: LocalScope<Emitter>(Ctx, VD), Scope(Ctx->P, VD),
32+
: LocalScope<Emitter>(Ctx, VD), Scope(Ctx->P),
3333
OldInitializingDecl(Ctx->InitializingDecl) {
3434
Ctx->InitializingDecl = VD;
3535
Ctx->InitStack.push_back(InitLink::Decl(VD));
@@ -2707,7 +2707,8 @@ bool Compiler<Emitter>::VisitMaterializeTemporaryExpr(
27072707

27082708
// For everyhing else, use local variables.
27092709
if (SubExprT) {
2710-
unsigned LocalIndex = allocateLocalPrimitive(E, *SubExprT, /*IsConst=*/true,
2710+
bool IsConst = SubExpr->getType().isConstQualified();
2711+
unsigned LocalIndex = allocateLocalPrimitive(E, *SubExprT, IsConst,
27112712
/*IsExtended=*/true);
27122713
if (!this->visit(SubExpr))
27132714
return false;
@@ -3028,7 +3029,7 @@ bool Compiler<Emitter>::VisitCXXConstructExpr(const CXXConstructExpr *E) {
30283029

30293030
size_t NumElems = CAT->getZExtSize();
30303031
const Function *Func = getFunction(E->getConstructor());
3031-
if (!Func || !Func->isConstexpr())
3032+
if (!Func)
30323033
return false;
30333034

30343035
// FIXME(perf): We're calling the constructor once per array element here,

clang/lib/AST/ByteCode/Program.h

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,22 @@ class Program final {
132132
/// Context to manage declaration lifetimes.
133133
class DeclScope {
134134
public:
135-
DeclScope(Program &P, const ValueDecl *VD) : P(P) {
136-
P.startDeclaration(VD);
135+
DeclScope(Program &P) : P(P), PrevDecl(P.CurrentDeclaration) {
136+
++P.LastDeclaration;
137+
P.CurrentDeclaration = P.LastDeclaration;
137138
}
138-
~DeclScope() { P.endDeclaration(); }
139+
~DeclScope() { P.CurrentDeclaration = PrevDecl; }
139140

140141
private:
141142
Program &P;
143+
unsigned PrevDecl;
142144
};
143145

144146
/// Returns the current declaration ID.
145147
std::optional<unsigned> getCurrentDecl() const {
146148
if (CurrentDeclaration == NoDeclaration)
147-
return std::optional<unsigned>{};
148-
return LastDeclaration;
149+
return std::nullopt;
150+
return CurrentDeclaration;
149151
}
150152

151153
private:
@@ -218,21 +220,12 @@ class Program final {
218220
}
219221

220222
/// No declaration ID.
221-
static constexpr unsigned NoDeclaration = (unsigned)-1;
223+
static constexpr unsigned NoDeclaration = ~0u;
222224
/// Last declaration ID.
223225
unsigned LastDeclaration = 0;
224226
/// Current declaration ID.
225227
unsigned CurrentDeclaration = NoDeclaration;
226228

227-
/// Starts evaluating a declaration.
228-
void startDeclaration(const ValueDecl *Decl) {
229-
LastDeclaration += 1;
230-
CurrentDeclaration = LastDeclaration;
231-
}
232-
233-
/// Ends a global declaration.
234-
void endDeclaration() { CurrentDeclaration = NoDeclaration; }
235-
236229
public:
237230
/// Dumps the disassembled bytecode to \c llvm::errs().
238231
void dump() const;

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,22 +3481,10 @@ uint64_t ASTContext::getFieldOffset(const ValueDecl *VD) const {
34813481
}
34823482

34833483
uint64_t ASTContext::lookupFieldBitOffset(const ObjCInterfaceDecl *OID,
3484-
const ObjCImplementationDecl *ID,
34853484
const ObjCIvarDecl *Ivar) const {
34863485
Ivar = Ivar->getCanonicalDecl();
34873486
const ObjCInterfaceDecl *Container = Ivar->getContainingInterface();
3488-
3489-
// FIXME: We should eliminate the need to have ObjCImplementationDecl passed
3490-
// in here; it should never be necessary because that should be the lexical
3491-
// decl context for the ivar.
3492-
3493-
// If we know have an implementation (and the ivar is in it) then
3494-
// look up in the implementation layout.
3495-
const ASTRecordLayout *RL;
3496-
if (ID && declaresSameEntity(ID->getClassInterface(), Container))
3497-
RL = &getASTObjCImplementationLayout(ID);
3498-
else
3499-
RL = &getASTObjCInterfaceLayout(Container);
3487+
const ASTRecordLayout *RL = &getASTObjCInterfaceLayout(Container);
35003488

35013489
// Compute field index.
35023490
//
@@ -3522,8 +3510,7 @@ uint64_t ASTContext::lookupFieldBitOffset(const ObjCInterfaceDecl *OID,
35223510
/// \param Impl - If given, also include the layout of the interface's
35233511
/// implementation. This may differ by including synthesized ivars.
35243512
const ASTRecordLayout &
3525-
ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
3526-
const ObjCImplementationDecl *Impl) const {
3513+
ASTContext::getObjCLayout(const ObjCInterfaceDecl *D) const {
35273514
// Retrieve the definition
35283515
if (D->hasExternalLexicalStorage() && !D->getDefinition())
35293516
getExternalSource()->CompleteType(const_cast<ObjCInterfaceDecl*>(D));
@@ -3532,22 +3519,9 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
35323519
"Invalid interface decl!");
35333520

35343521
// Look up this layout, if already laid out, return what we have.
3535-
const ObjCContainerDecl *Key =
3536-
Impl ? (const ObjCContainerDecl*) Impl : (const ObjCContainerDecl*) D;
3537-
if (const ASTRecordLayout *Entry = ObjCLayouts[Key])
3522+
if (const ASTRecordLayout *Entry = ObjCLayouts[D])
35383523
return *Entry;
35393524

3540-
// Add in synthesized ivar count if laying out an implementation.
3541-
if (Impl) {
3542-
unsigned SynthCount = CountNonClassIvars(D);
3543-
// If there aren't any synthesized ivars then reuse the interface
3544-
// entry. Note we can't cache this because we simply free all
3545-
// entries later; however we shouldn't look up implementations
3546-
// frequently.
3547-
if (SynthCount == 0)
3548-
return getObjCLayout(D, nullptr);
3549-
}
3550-
35513525
ItaniumRecordLayoutBuilder Builder(*this, /*EmptySubobjects=*/nullptr);
35523526
Builder.Layout(D);
35533527

@@ -3557,7 +3531,7 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
35573531
/*RequiredAlignment : used by MS-ABI)*/
35583532
Builder.Alignment, Builder.getDataSize(), Builder.FieldOffsets);
35593533

3560-
ObjCLayouts[Key] = NewEntry;
3534+
ObjCLayouts[D] = NewEntry;
35613535

35623536
return *NewEntry;
35633537
}

clang/lib/Analysis/LiveVariables.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -664,18 +664,18 @@ void LiveVariables::dumpExprLiveness(const SourceManager &M) {
664664
}
665665

666666
void LiveVariablesImpl::dumpExprLiveness(const SourceManager &M) {
667-
auto ByBeginLoc = [&M](const Expr *L, const Expr *R) {
668-
return M.isBeforeInTranslationUnit(L->getBeginLoc(), R->getBeginLoc());
667+
const ASTContext &Ctx = analysisContext.getASTContext();
668+
auto ByIDs = [&Ctx](const Expr *L, const Expr *R) {
669+
return L->getID(Ctx) < R->getID(Ctx);
669670
};
670671

671672
// Don't iterate over blockEndsToLiveness directly because it's not sorted.
672673
for (const CFGBlock *B : *analysisContext.getCFG()) {
673-
674674
llvm::errs() << "\n[ B" << B->getBlockID()
675675
<< " (live expressions at block exit) ]\n";
676676
std::vector<const Expr *> LiveExprs;
677677
llvm::append_range(LiveExprs, blocksEndToLiveness[B].liveExprs);
678-
llvm::sort(LiveExprs, ByBeginLoc);
678+
llvm::sort(LiveExprs, ByIDs);
679679
for (const Expr *E : LiveExprs) {
680680
llvm::errs() << "\n";
681681
E->dump();

clang/lib/CodeGen/CGObjCGNU.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,9 +1826,11 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
18261826
Context.getASTObjCInterfaceLayout(SuperClassDecl).getSize().getQuantity();
18271827
// Instance size is negative for classes that have not yet had their ivar
18281828
// layout calculated.
1829-
classFields.addInt(LongTy,
1830-
0 - (Context.getASTObjCImplementationLayout(OID).getSize().getQuantity() -
1831-
superInstanceSize));
1829+
classFields.addInt(
1830+
LongTy, 0 - (Context.getASTObjCInterfaceLayout(OID->getClassInterface())
1831+
.getSize()
1832+
.getQuantity() -
1833+
superInstanceSize));
18321834

18331835
if (classDecl->all_declared_ivar_begin() == nullptr)
18341836
classFields.addNullPointer(PtrTy);
@@ -3639,8 +3641,9 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
36393641
}
36403642

36413643
// Get the size of instances.
3642-
int instanceSize =
3643-
Context.getASTObjCImplementationLayout(OID).getSize().getQuantity();
3644+
int instanceSize = Context.getASTObjCInterfaceLayout(OID->getClassInterface())
3645+
.getSize()
3646+
.getQuantity();
36443647

36453648
// Collect information about instance variables.
36463649
SmallVector<llvm::Constant*, 16> IvarNames;

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,8 +3439,9 @@ void CGObjCMac::GenerateClass(const ObjCImplementationDecl *ID) {
34393439
else if ((hasMRCWeak = hasMRCWeakIvars(CGM, ID)))
34403440
Flags |= FragileABI_Class_HasMRCWeakIvars;
34413441

3442-
CharUnits Size =
3443-
CGM.getContext().getASTObjCImplementationLayout(ID).getSize();
3442+
CharUnits Size = CGM.getContext()
3443+
.getASTObjCInterfaceLayout(ID->getClassInterface())
3444+
.getSize();
34443445

34453446
// FIXME: Set CXX-structors flag.
34463447
if (ID->getClassInterface()->getVisibility() == HiddenVisibility)
@@ -6330,7 +6331,7 @@ void CGObjCNonFragileABIMac::GetClassSizeInfo(const ObjCImplementationDecl *OID,
63306331
uint32_t &InstanceStart,
63316332
uint32_t &InstanceSize) {
63326333
const ASTRecordLayout &RL =
6333-
CGM.getContext().getASTObjCImplementationLayout(OID);
6334+
CGM.getContext().getASTObjCInterfaceLayout(OID->getClassInterface());
63346335

63356336
// InstanceSize is really instance end.
63366337
InstanceSize = RL.getDataSize().getQuantity();

clang/lib/CodeGen/CGObjCRuntime.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,22 @@ using namespace CodeGen;
3131
uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
3232
const ObjCInterfaceDecl *OID,
3333
const ObjCIvarDecl *Ivar) {
34-
return CGM.getContext().lookupFieldBitOffset(OID, nullptr, Ivar) /
34+
return CGM.getContext().lookupFieldBitOffset(OID, Ivar) /
3535
CGM.getContext().getCharWidth();
3636
}
3737

3838
uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
3939
const ObjCImplementationDecl *OID,
4040
const ObjCIvarDecl *Ivar) {
41-
return CGM.getContext().lookupFieldBitOffset(OID->getClassInterface(), OID,
42-
Ivar) /
41+
return CGM.getContext().lookupFieldBitOffset(OID->getClassInterface(), Ivar) /
4342
CGM.getContext().getCharWidth();
4443
}
4544

4645
unsigned CGObjCRuntime::ComputeBitfieldBitOffset(
4746
CodeGen::CodeGenModule &CGM,
4847
const ObjCInterfaceDecl *ID,
4948
const ObjCIvarDecl *Ivar) {
50-
return CGM.getContext().lookupFieldBitOffset(ID, ID->getImplementation(),
51-
Ivar);
49+
return CGM.getContext().lookupFieldBitOffset(ID, Ivar);
5250
}
5351

5452
LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
@@ -86,7 +84,7 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
8684
// non-synthesized ivars but we may be called for synthesized ivars. However,
8785
// a synthesized ivar can never be a bit-field, so this is safe.
8886
uint64_t FieldBitOffset =
89-
CGF.CGM.getContext().lookupFieldBitOffset(OID, nullptr, Ivar);
87+
CGF.CGM.getContext().lookupFieldBitOffset(OID, Ivar);
9088
uint64_t BitOffset = FieldBitOffset % CGF.CGM.getContext().getCharWidth();
9189
uint64_t AlignmentBits = CGF.CGM.getTarget().getCharAlign();
9290
uint64_t BitFieldSize = Ivar->getBitWidthValue();

0 commit comments

Comments
 (0)