Skip to content

Commit 103469b

Browse files
committed
[clang][Interp] Implement more easy _Complex unary operators
1 parent 1dd104d commit 103469b

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,16 +3138,17 @@ bool ByteCodeExprGen<Emitter>::VisitComplexUnaryOperator(
31383138
return this->discard(SubExpr);
31393139

31403140
std::optional<PrimType> ResT = classify(E);
3141+
auto prepareResult = [=]() -> bool {
3142+
if (!ResT && !Initializing) {
3143+
std::optional<unsigned> LocalIndex =
3144+
allocateLocal(SubExpr, /*IsExtended=*/false);
3145+
if (!LocalIndex)
3146+
return false;
3147+
return this->emitGetPtrLocal(*LocalIndex, E);
3148+
}
31413149

3142-
// Prepare storage for result.
3143-
if (!ResT && !Initializing) {
3144-
std::optional<unsigned> LocalIndex =
3145-
allocateLocal(SubExpr, /*IsExtended=*/false);
3146-
if (!LocalIndex)
3147-
return false;
3148-
if (!this->emitGetPtrLocal(*LocalIndex, E))
3149-
return false;
3150-
}
3150+
return true;
3151+
};
31513152

31523153
// The offset of the temporary, if we created one.
31533154
unsigned SubExprOffset = ~0u;
@@ -3167,6 +3168,8 @@ bool ByteCodeExprGen<Emitter>::VisitComplexUnaryOperator(
31673168

31683169
switch (E->getOpcode()) {
31693170
case UO_Minus:
3171+
if (!prepareResult())
3172+
return false;
31703173
if (!createTemp())
31713174
return false;
31723175
for (unsigned I = 0; I != 2; ++I) {
@@ -3179,7 +3182,9 @@ bool ByteCodeExprGen<Emitter>::VisitComplexUnaryOperator(
31793182
}
31803183
break;
31813184

3182-
case UO_AddrOf:
3185+
case UO_Plus: // +x
3186+
case UO_AddrOf: // &x
3187+
case UO_Deref: // *x
31833188
return this->delegate(SubExpr);
31843189

31853190
case UO_LNot:

0 commit comments

Comments
 (0)