[clang] 05a113e - [clang][Interp][NFC] Handle discarded ArraySubscriptExprs

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 6 23:43:04 PST 2022


Author: Timm Bäder
Date: 2022-11-07T08:37:43+01:00
New Revision: 05a113e18852ab54f22516e9ec1b6aa39adc5b33

URL: https://github.com/llvm/llvm-project/commit/05a113e18852ab54f22516e9ec1b6aa39adc5b33
DIFF: https://github.com/llvm/llvm-project/commit/05a113e18852ab54f22516e9ec1b6aa39adc5b33.diff

LOG: [clang][Interp][NFC] Handle discarded ArraySubscriptExprs

This is not exactly a common case, so just pop the pointer at the end if
necessary.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 5362e9cb1ab0..f3f4ae774886 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -319,26 +319,26 @@ bool ByteCodeExprGen<Emitter>::VisitArraySubscriptExpr(
     const ArraySubscriptExpr *E) {
   const Expr *Base = E->getBase();
   const Expr *Index = E->getIdx();
+  PrimType IndexT = classifyPrim(Index->getType());
 
   // Take pointer of LHS, add offset from RHS, narrow result.
   // What's left on the stack after this is a pointer.
-  if (Optional<PrimType> IndexT = classify(Index->getType())) {
-    if (!this->visit(Base))
-      return false;
+  if (!this->visit(Base))
+    return false;
 
-    if (!this->visit(Index))
-      return false;
+  if (!this->visit(Index))
+    return false;
 
-    if (!this->emitAddOffset(*IndexT, E))
-      return false;
+  if (!this->emitAddOffset(IndexT, E))
+    return false;
 
-    if (!this->emitNarrowPtr(E))
-      return false;
+  if (!this->emitNarrowPtr(E))
+    return false;
 
-    return true;
-  }
+  if (DiscardResult)
+    return this->emitPopPtr(E);
 
-  return false;
+  return true;
 }
 
 template <class Emitter>


        


More information about the cfe-commits mailing list