[clang] 0d2e9b6 - [clang][Interp][NFC] Ignore ArraySubScriptExpr like the other exprs
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 1 03:14:39 PDT 2023
Author: Timm Bäder
Date: 2023-08-01T12:14:20+02:00
New Revision: 0d2e9b6e4627c3c9f4956b212c761248f18f6eae
URL: https://github.com/llvm/llvm-project/commit/0d2e9b6e4627c3c9f4956b212c761248f18f6eae
DIFF: https://github.com/llvm/llvm-project/commit/0d2e9b6e4627c3c9f4956b212c761248f18f6eae.diff
LOG: [clang][Interp][NFC] Ignore ArraySubScriptExpr like the other exprs
Instead of evaluating the entire thing and then pop'ing the value from
the stack, just pass the discard() on.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/literals.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 8fbcc9ae3eec98..79b0a3857d075c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -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.
@@ -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>
diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index d4ade51b1d71c3..b8467b86c4c906 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -899,6 +899,8 @@ namespace DiscardExprs {
(int){1};
(int[]){1,2,3};
+ int arr[] = {1,2,3};
+ arr[0];
return 0;
}
More information about the cfe-commits
mailing list