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;
 }


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;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to