Skip to content

Commit 8ba0d0f

Browse files
authored
[clang][bytcode][NFC] Use UnsignedOrNone for global ids (#157328)
1 parent 93c2eec commit 8ba0d0f

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,7 +2912,8 @@ bool Compiler<Emitter>::VisitMaterializeTemporaryExpr(
29122912
OptPrimType SubExprT = classify(SubExpr);
29132913
bool IsStatic = E->getStorageDuration() == SD_Static;
29142914
if (IsStatic) {
2915-
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
2915+
2916+
UnsignedOrNone GlobalIndex = P.createGlobal(E);
29162917
if (!GlobalIndex)
29172918
return false;
29182919

@@ -3001,7 +3002,7 @@ bool Compiler<Emitter>::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
30013002
if (T && !E->isLValue())
30023003
return this->delegate(Init);
30033004

3004-
std::optional<unsigned> GlobalIndex = P.createGlobal(E);
3005+
UnsignedOrNone GlobalIndex = P.createGlobal(E);
30053006
if (!GlobalIndex)
30063007
return false;
30073008

@@ -3345,7 +3346,7 @@ bool Compiler<Emitter>::VisitSourceLocExpr(const SourceLocExpr *E) {
33453346

33463347
auto *UGCD = cast<UnnamedGlobalConstantDecl>(BaseDecl);
33473348

3348-
std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(UGCD);
3349+
UnsignedOrNone GlobalIndex = P.getOrCreateGlobal(UGCD);
33493350
if (!GlobalIndex)
33503351
return false;
33513352

@@ -3868,7 +3869,7 @@ bool Compiler<Emitter>::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {
38683869
if (!RD->isCompleteDefinition())
38693870
return this->emitDummyPtr(GuidDecl, E);
38703871

3871-
std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(GuidDecl);
3872+
UnsignedOrNone GlobalIndex = P.getOrCreateGlobal(GuidDecl);
38723873
if (!GlobalIndex)
38733874
return false;
38743875
if (!this->emitGetPtrGlobal(*GlobalIndex, E))
@@ -4860,7 +4861,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD,
48604861
DeclScope<Emitter> LocalScope(this, VD);
48614862

48624863
// We've already seen and initialized this global.
4863-
if (std::optional<unsigned> GlobalIndex = P.getGlobal(VD)) {
4864+
if (UnsignedOrNone GlobalIndex = P.getGlobal(VD)) {
48644865
if (P.getPtrGlobal(*GlobalIndex).isInitialized())
48654866
return checkDecl();
48664867

@@ -4869,7 +4870,7 @@ VarCreationState Compiler<Emitter>::visitVarDecl(const VarDecl *VD,
48694870
return Init && checkDecl() && initGlobal(*GlobalIndex);
48704871
}
48714872

4872-
std::optional<unsigned> GlobalIndex = P.createGlobal(VD, Init);
4873+
UnsignedOrNone GlobalIndex = P.createGlobal(VD, Init);
48734874

48744875
if (!GlobalIndex)
48754876
return false;
@@ -6802,7 +6803,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
68026803
return F && this->emitGetFnPtr(F, E);
68036804
}
68046805
if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(D)) {
6805-
if (std::optional<unsigned> Index = P.getOrCreateGlobal(D)) {
6806+
if (UnsignedOrNone Index = P.getOrCreateGlobal(D)) {
68066807
if (!this->emitGetPtrGlobal(*Index, E))
68076808
return false;
68086809
if (OptPrimType T = classify(E->getType())) {

clang/lib/AST/ByteCode/EvalEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo &Info) {
331331
/// This is what we do here.
332332
void EvalEmitter::updateGlobalTemporaries() {
333333
for (const auto &[E, Temp] : S.SeenGlobalTemporaries) {
334-
if (std::optional<unsigned> GlobalIndex = P.getGlobal(E)) {
334+
if (UnsignedOrNone GlobalIndex = P.getGlobal(E)) {
335335
const Pointer &Ptr = P.getPtrGlobal(*GlobalIndex);
336336
APValue *Cached = Temp->getOrCreateValue(true);
337337

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Pointer Program::getPtrGlobal(unsigned Idx) const {
111111
return Pointer(Globals[Idx]->block());
112112
}
113113

114-
std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
114+
UnsignedOrNone Program::getGlobal(const ValueDecl *VD) {
115115
if (auto It = GlobalIndices.find(VD); It != GlobalIndices.end())
116116
return It->second;
117117

@@ -131,14 +131,14 @@ std::optional<unsigned> Program::getGlobal(const ValueDecl *VD) {
131131
return std::nullopt;
132132
}
133133

134-
std::optional<unsigned> Program::getGlobal(const Expr *E) {
134+
UnsignedOrNone Program::getGlobal(const Expr *E) {
135135
if (auto It = GlobalIndices.find(E); It != GlobalIndices.end())
136136
return It->second;
137137
return std::nullopt;
138138
}
139139

140-
std::optional<unsigned> Program::getOrCreateGlobal(const ValueDecl *VD,
141-
const Expr *Init) {
140+
UnsignedOrNone Program::getOrCreateGlobal(const ValueDecl *VD,
141+
const Expr *Init) {
142142
if (auto Idx = getGlobal(VD))
143143
return Idx;
144144

@@ -195,8 +195,7 @@ unsigned Program::getOrCreateDummy(const DeclTy &D) {
195195
return I;
196196
}
197197

198-
std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
199-
const Expr *Init) {
198+
UnsignedOrNone Program::createGlobal(const ValueDecl *VD, const Expr *Init) {
200199
bool IsStatic, IsExtern;
201200
bool IsWeak = VD->isWeak();
202201
if (const auto *Var = dyn_cast<VarDecl>(VD)) {
@@ -213,7 +212,7 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
213212

214213
// Register all previous declarations as well. For extern blocks, just replace
215214
// the index with the new variable.
216-
std::optional<unsigned> Idx =
215+
UnsignedOrNone Idx =
217216
createGlobal(VD, VD->getType(), IsStatic, IsExtern, IsWeak, Init);
218217
if (!Idx)
219218
return std::nullopt;
@@ -240,7 +239,7 @@ std::optional<unsigned> Program::createGlobal(const ValueDecl *VD,
240239
return *Idx;
241240
}
242241

243-
std::optional<unsigned> Program::createGlobal(const Expr *E) {
242+
UnsignedOrNone Program::createGlobal(const Expr *E) {
244243
if (auto Idx = getGlobal(E))
245244
return Idx;
246245
if (auto Idx = createGlobal(E, E->getType(), /*isStatic=*/true,
@@ -251,9 +250,9 @@ std::optional<unsigned> Program::createGlobal(const Expr *E) {
251250
return std::nullopt;
252251
}
253252

254-
std::optional<unsigned> Program::createGlobal(const DeclTy &D, QualType Ty,
255-
bool IsStatic, bool IsExtern,
256-
bool IsWeak, const Expr *Init) {
253+
UnsignedOrNone Program::createGlobal(const DeclTy &D, QualType Ty,
254+
bool IsStatic, bool IsExtern, bool IsWeak,
255+
const Expr *Init) {
257256
// Create a descriptor for the global.
258257
Descriptor *Desc;
259258
const bool IsConst = Ty.isConstQualified();

clang/lib/AST/ByteCode/Program.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,21 @@ class Program final {
7878
}
7979

8080
/// Finds a global's index.
81-
std::optional<unsigned> getGlobal(const ValueDecl *VD);
82-
std::optional<unsigned> getGlobal(const Expr *E);
81+
UnsignedOrNone getGlobal(const ValueDecl *VD);
82+
UnsignedOrNone getGlobal(const Expr *E);
8383

8484
/// Returns or creates a global an creates an index to it.
85-
std::optional<unsigned> getOrCreateGlobal(const ValueDecl *VD,
86-
const Expr *Init = nullptr);
85+
UnsignedOrNone getOrCreateGlobal(const ValueDecl *VD,
86+
const Expr *Init = nullptr);
8787

8888
/// Returns or creates a dummy value for unknown declarations.
8989
unsigned getOrCreateDummy(const DeclTy &D);
9090

9191
/// Creates a global and returns its index.
92-
std::optional<unsigned> createGlobal(const ValueDecl *VD, const Expr *Init);
92+
UnsignedOrNone createGlobal(const ValueDecl *VD, const Expr *Init);
9393

9494
/// Creates a global from a lifetime-extended temporary.
95-
std::optional<unsigned> createGlobal(const Expr *E);
95+
UnsignedOrNone createGlobal(const Expr *E);
9696

9797
/// Creates a new function from a code range.
9898
template <typename... Ts>
@@ -165,9 +165,9 @@ class Program final {
165165
private:
166166
friend class DeclScope;
167167

168-
std::optional<unsigned> createGlobal(const DeclTy &D, QualType Ty,
169-
bool IsStatic, bool IsExtern,
170-
bool IsWeak, const Expr *Init = nullptr);
168+
UnsignedOrNone createGlobal(const DeclTy &D, QualType Ty, bool IsStatic,
169+
bool IsExtern, bool IsWeak,
170+
const Expr *Init = nullptr);
171171

172172
/// Reference to the VM context.
173173
Context &Ctx;

0 commit comments

Comments
 (0)