================
@@ -478,6 +480,43 @@ template <class Emitter> class SourceLocScope final {
   bool Enabled = false;
 };
 
+template <class Emitter> class StoredOpaqueValueScope final {
+public:
+  StoredOpaqueValueScope(ByteCodeExprGen<Emitter> *Ctx) : Ctx(Ctx) {}
+
+  bool VisitAndStoreOpaqueValue(const OpaqueValueExpr *Ove) {
+    assert(Ove && "OpaqueValueExpr is a nullptr!");
+    assert(!Ctx->OpaqueExprs.contains(Ove) &&
+           "OpaqueValueExpr already stored!");
+
+    std::optional<PrimType> CommonTy = Ctx->classify(Ove);
+    std::optional<unsigned> LocalIndex = Ctx->allocateLocalPrimitive(
+        Ove, *CommonTy, Ove->getType().isConstQualified());
+    if (!LocalIndex)
+      return false;
+
+    if (!Ctx->visit(Ove))
+      return false;
+
+    if (!Ctx->emitSetLocal(*CommonTy, *LocalIndex, Ove))
+      return false;
+
+    Ctx->OpaqueExprs.insert({Ove, *LocalIndex});
+    StoredValues.emplace_back(Ove);
+
+    return true;
+  }
+
+  ~StoredOpaqueValueScope() {
+    for (const auto *SV : StoredValues)
+      Ctx->OpaqueExprs.erase(SV);
+  }
+
+private:
+  ByteCodeExprGen<Emitter> *Ctx;
+  std::vector<const OpaqueValueExpr *> StoredValues;
----------------
tbaederr wrote:

Well you don't ever reuse the same `StoredOpaqueValueScope`, do you? The scope 
should add the value in its constructor and remove it in its destructor. So as 
long as we don't evaluate the same `OpaqueExpr` twice, we should be fine and no 
vector is needed.

https://github.com/llvm/llvm-project/pull/68039
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to