Skip to content

Commit

Permalink
[clang][Interp][NFC] Ignore ArraySubScriptExpr like the other exprs
Browse files Browse the repository at this point in the history
Instead of evaluating the entire thing and then pop'ing the value from
the stack, just pass the discard() on.
  • Loading branch information
tbaederr committed Aug 1, 2023
1 parent d01aec4 commit 0d2e9b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 5 additions & 8 deletions clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ bool ByteCodeExprGen<Emitter>::VisitArraySubscriptExpr(
const ArraySubscriptExpr *E) {
const Expr *Base = E->getBase();
const Expr *Index = E->getIdx();
PrimType IndexT = classifyPrim(Index->getType());

if (DiscardResult)
return this->discard(Base) && this->discard(Index);

// Take pointer of LHS, add offset from RHS.
// What's left on the stack after this is a pointer.
Expand All @@ -455,13 +457,8 @@ bool ByteCodeExprGen<Emitter>::VisitArraySubscriptExpr(
if (!this->visit(Index))
return false;

if (!this->emitArrayElemPtrPop(IndexT, E))
return false;

if (DiscardResult)
return this->emitPopPtr(E);

return true;
PrimType IndexT = classifyPrim(Index->getType());
return this->emitArrayElemPtrPop(IndexT, E);
}

template <class Emitter>
Expand Down
2 changes: 2 additions & 0 deletions clang/test/AST/Interp/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,8 @@ namespace DiscardExprs {

(int){1};
(int[]){1,2,3};
int arr[] = {1,2,3};
arr[0];

return 0;
}
Expand Down

0 comments on commit 0d2e9b6

Please sign in to comment.