tbaeder updated this revision to Diff 520153.
tbaeder marked an inline comment as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149837/new/

https://reviews.llvm.org/D149837

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


Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -875,9 +875,26 @@
     sizeof(A);
     alignof(A);
 
+    (int){1};
+    (int[]){1,2,3};
+
     return 0;
   }
 
+  constexpr int oh_my(int x) {
+    (int){ x++ };
+    return x;
+  }
+  static_assert(oh_my(0) == 1, "");
+
+  constexpr int oh_my2(int x) {
+    int y{x++};
+    return x;
+  }
+
+  static_assert(oh_my2(0) == 1, "");
+
+
   /// Ignored comma expressions still have their
   /// expressions evaluated.
   constexpr int Comma(int start) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -527,8 +527,13 @@
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
   for (const Expr *Init : E->inits()) {
-    if (!this->visit(Init))
-      return false;
+    if (DiscardResult) {
+      if (!this->discard(Init))
+        return false;
+    } else {
+      if (!this->visit(Init))
+        return false;
+    }
   }
   return true;
 }
@@ -1024,12 +1029,16 @@
   // Otherwise, use a local variable.
   if (T) {
     // For primitive types, we just visit the initializer.
-    return this->visit(Init);
+    return DiscardResult ? this->discard(Init) : this->visit(Init);
   } else {
     if (std::optional<unsigned> LocalIndex = allocateLocal(Init)) {
       if (!this->emitGetPtrLocal(*LocalIndex, E))
         return false;
-      return this->visitInitializer(Init);
+      if (!this->visitInitializer(Init))
+        return false;
+      if (DiscardResult)
+        return this->emitPopPtr(E);
+      return true;
     }
   }
 


Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -875,9 +875,26 @@
     sizeof(A);
     alignof(A);
 
+    (int){1};
+    (int[]){1,2,3};
+
     return 0;
   }
 
+  constexpr int oh_my(int x) {
+    (int){ x++ };
+    return x;
+  }
+  static_assert(oh_my(0) == 1, "");
+
+  constexpr int oh_my2(int x) {
+    int y{x++};
+    return x;
+  }
+
+  static_assert(oh_my2(0) == 1, "");
+
+
   /// Ignored comma expressions still have their
   /// expressions evaluated.
   constexpr int Comma(int start) {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -527,8 +527,13 @@
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
   for (const Expr *Init : E->inits()) {
-    if (!this->visit(Init))
-      return false;
+    if (DiscardResult) {
+      if (!this->discard(Init))
+        return false;
+    } else {
+      if (!this->visit(Init))
+        return false;
+    }
   }
   return true;
 }
@@ -1024,12 +1029,16 @@
   // Otherwise, use a local variable.
   if (T) {
     // For primitive types, we just visit the initializer.
-    return this->visit(Init);
+    return DiscardResult ? this->discard(Init) : this->visit(Init);
   } else {
     if (std::optional<unsigned> LocalIndex = allocateLocal(Init)) {
       if (!this->emitGetPtrLocal(*LocalIndex, E))
         return false;
-      return this->visitInitializer(Init);
+      if (!this->visitInitializer(Init))
+        return false;
+      if (DiscardResult)
+        return this->emitPopPtr(E);
+      return true;
     }
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to