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.

  They might appear freestanding, not as part of an initializer. In that
  case, we need to create a temporary variable and return a pointer to it.

The test case added doesn't work yet since passing structs by value to 
functions is broken right now, I will fix that in a follow-up patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153693

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
@@ -895,3 +895,10 @@
 #endif
 
 }
+
+#if 0
+constexpr bool BPand(BoolPair bp) {
+  return bp.first && bp.second;
+}
+static_assert(BPand(BoolPair{true, false}) == false, "");
+#endif
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -525,16 +525,27 @@
 
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
-  for (const Expr *Init : E->inits()) {
-    if (DiscardResult) {
-      if (!this->discard(Init))
-        return false;
-    } else {
-      if (!this->visit(Init))
-        return false;
-    }
+  if (std::optional<PrimType> T = classify(E->getType())) {
+    assert(E->getNumInits() == 1);
+    return DiscardResult ? this->discard(E->inits()[0])
+                         : this->visit(E->inits()[0]);
   }
-  return true;
+
+  if (std::optional<unsigned> LocalIndex = allocateLocal(E, false)) {
+    if (!this->emitGetPtrLocal(*LocalIndex, E))
+      return false;
+
+    if (!this->visitInitializer(E))
+      return false;
+
+    if (DiscardResult)
+      return this->emitPopPtr(E);
+    return true;
+  }
+
+  // TODO: Array, complex, etc. types might appear here as well.
+
+  return false;
 }
 
 template <class Emitter>


Index: clang/test/AST/Interp/records.cpp
===================================================================
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -895,3 +895,10 @@
 #endif
 
 }
+
+#if 0
+constexpr bool BPand(BoolPair bp) {
+  return bp.first && bp.second;
+}
+static_assert(BPand(BoolPair{true, false}) == false, "");
+#endif
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -525,16 +525,27 @@
 
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitInitListExpr(const InitListExpr *E) {
-  for (const Expr *Init : E->inits()) {
-    if (DiscardResult) {
-      if (!this->discard(Init))
-        return false;
-    } else {
-      if (!this->visit(Init))
-        return false;
-    }
+  if (std::optional<PrimType> T = classify(E->getType())) {
+    assert(E->getNumInits() == 1);
+    return DiscardResult ? this->discard(E->inits()[0])
+                         : this->visit(E->inits()[0]);
   }
-  return true;
+
+  if (std::optional<unsigned> LocalIndex = allocateLocal(E, false)) {
+    if (!this->emitGetPtrLocal(*LocalIndex, E))
+      return false;
+
+    if (!this->visitInitializer(E))
+      return false;
+
+    if (DiscardResult)
+      return this->emitPopPtr(E);
+    return true;
+  }
+
+  // TODO: Array, complex, etc. types might appear here as well.
+
+  return false;
 }
 
 template <class Emitter>
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D153693: [clang][Inter... Timm Bäder via Phabricator via cfe-commits

Reply via email to