Skip to content

Commit 160693d

Browse files
committed
[clang][Interp][NFC] allocateLocalPrimitive never fails
It returns the local offset, not an std::optional.
1 parent 611d5ae commit 160693d

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,11 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
308308
// Location for the SubExpr.
309309
// Since SubExpr is of complex type, visiting it results in a pointer
310310
// anyway, so we just create a temporary pointer variable.
311-
std::optional<unsigned> SubExprOffset = allocateLocalPrimitive(
311+
unsigned SubExprOffset = allocateLocalPrimitive(
312312
SubExpr, PT_Ptr, /*IsConst=*/true, /*IsExtended=*/false);
313-
if (!SubExprOffset)
314-
return false;
315-
316313
if (!this->visit(SubExpr))
317314
return false;
318-
if (!this->emitSetLocal(PT_Ptr, *SubExprOffset, CE))
315+
if (!this->emitSetLocal(PT_Ptr, SubExprOffset, CE))
319316
return false;
320317

321318
PrimType SourceElemT = classifyComplexElementType(SubExpr->getType());
@@ -324,7 +321,7 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
324321
PrimType DestElemT = classifyPrim(DestElemType);
325322
// Cast both elements individually.
326323
for (unsigned I = 0; I != 2; ++I) {
327-
if (!this->emitGetLocal(PT_Ptr, *SubExprOffset, CE))
324+
if (!this->emitGetLocal(PT_Ptr, SubExprOffset, CE))
328325
return false;
329326
if (!this->emitArrayElemPop(SourceElemT, I, CE))
330327
return false;
@@ -1245,22 +1242,19 @@ bool ByteCodeExprGen<Emitter>::VisitOpaqueValueExpr(const OpaqueValueExpr *E) {
12451242
// At this point we either have the evaluated source expression or a pointer
12461243
// to an object on the stack. We want to create a local variable that stores
12471244
// this value.
1248-
std::optional<unsigned> LocalIndex =
1249-
allocateLocalPrimitive(E, SubExprT, /*IsConst=*/true);
1250-
if (!LocalIndex)
1251-
return false;
1252-
if (!this->emitSetLocal(SubExprT, *LocalIndex, E))
1245+
unsigned LocalIndex = allocateLocalPrimitive(E, SubExprT, /*IsConst=*/true);
1246+
if (!this->emitSetLocal(SubExprT, LocalIndex, E))
12531247
return false;
12541248

12551249
// Here the local variable is created but the value is removed from the stack,
12561250
// so we put it back if the caller needs it.
12571251
if (!DiscardResult) {
1258-
if (!this->emitGetLocal(SubExprT, *LocalIndex, E))
1252+
if (!this->emitGetLocal(SubExprT, LocalIndex, E))
12591253
return false;
12601254
}
12611255

12621256
// This is cleaned up when the local variable is destroyed.
1263-
OpaqueExprs.insert({E, *LocalIndex});
1257+
OpaqueExprs.insert({E, LocalIndex});
12641258

12651259
return true;
12661260
}
@@ -1654,14 +1648,13 @@ bool ByteCodeExprGen<Emitter>::VisitMaterializeTemporaryExpr(
16541648

16551649
// For everyhing else, use local variables.
16561650
if (SubExprT) {
1657-
if (std::optional<unsigned> LocalIndex = allocateLocalPrimitive(
1658-
SubExpr, *SubExprT, /*IsConst=*/true, /*IsExtended=*/true)) {
1659-
if (!this->visit(SubExpr))
1660-
return false;
1661-
if (!this->emitSetLocal(*SubExprT, *LocalIndex, E))
1662-
return false;
1663-
return this->emitGetPtrLocal(*LocalIndex, E);
1664-
}
1651+
unsigned LocalIndex = allocateLocalPrimitive(
1652+
SubExpr, *SubExprT, /*IsConst=*/true, /*IsExtended=*/true);
1653+
if (!this->visit(SubExpr))
1654+
return false;
1655+
if (!this->emitSetLocal(*SubExprT, LocalIndex, E))
1656+
return false;
1657+
return this->emitGetPtrLocal(LocalIndex, E);
16651658
} else {
16661659
const Expr *Inner = E->getSubExpr()->skipRValueSubobjectAdjustments();
16671660

0 commit comments

Comments
 (0)