[PATCH] D149837: [clang][Interp] Fix ignoring CompoundLiteralExprs

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 1 02:48:29 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0a36a157d97: [clang][Interp] Fix ignoring CompoundLiteralExprs (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D149837?vs=520153&id=545984#toc

Repository:
  rG LLVM Github Monorepo

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
@@ -897,9 +897,26 @@
     1 ? 0 : 1;
     __is_trivial(int);
 
+    (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
@@ -467,8 +467,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;
 }
@@ -944,12 +949,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;
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149837.545984.patch
Type: text/x-patch
Size: 1845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230801/4d961dec/attachment.bin>


More information about the cfe-commits mailing list