[PATCH] D153653: [clang][Interp] Make CXXTemporaryObjectExprs leave a value behind

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 23 11:14:10 PDT 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  visitLocalInitializer() pops the pointer from the stack again, but we
  might be called in a situation where the caller would actually like to
  use the value.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153653

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===================================================================
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -880,3 +880,13 @@
   }
 }
 
+namespace TemporaryObjectExpr {
+  struct F {
+    int a;
+    constexpr F() : a(12) {}
+  };
+  constexpr int foo(F f) {
+    return 0;
+  }
+  static_assert(foo(F()) == 0, "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1011,10 +1011,17 @@
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitCXXTemporaryObjectExpr(
     const CXXTemporaryObjectExpr *E) {
-
   if (std::optional<unsigned> LocalIndex =
           allocateLocal(E, /*IsExtended=*/false)) {
-    return this->visitLocalInitializer(E, *LocalIndex);
+    if (!this->emitGetPtrLocal(*LocalIndex, E))
+      return false;
+
+    if (!this->visitInitializer(E))
+      return false;
+
+    if (DiscardResult)
+      return this->emitPopPtr(E);
+    return true;
   }
   return false;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153653.534026.patch
Type: text/x-patch
Size: 1146 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230623/0e7069b3/attachment.bin>


More information about the cfe-commits mailing list