[PATCH] D155710: [clang][Interp] Create a new local varible in VisitCXXDefaultArgExpr

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 19 07:22:47 PDT 2023


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

  If the argument is of composite type, we need a pointer to return.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155710

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
@@ -879,3 +879,27 @@
   }
 }
 
+namespace CompositeDefaultArgs {
+  struct Foo {
+    int a;
+    int b;
+    constexpr Foo() : a(12), b(13) {}
+  };
+
+  class Bar {
+  public:
+    bool B = false;
+
+    constexpr int someFunc(Foo F = Foo()) {
+      this->B = true;
+      return 5;
+    }
+  };
+
+  constexpr bool testMe() {
+    Bar B;
+    B.someFunc();
+    return B.B;
+  }
+  static_assert(testMe(), "");
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2105,7 +2105,18 @@
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitCXXDefaultArgExpr(
     const CXXDefaultArgExpr *E) {
-  return this->visit(E->getExpr());
+  const Expr *SubExpr = E->getExpr();
+
+  if (std::optional<PrimType> T = classify(E->getExpr()))
+    return this->visit(SubExpr);
+
+  if (std::optional<unsigned> LocalIndex =
+          allocateLocal(SubExpr, /*IsExtended=*/true)) {
+    if (!this->emitGetPtrLocal(*LocalIndex, E))
+      return false;
+    return this->visitInitializer(SubExpr);
+  }
+  return false;
 }
 
 template <class Emitter>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155710.542015.patch
Type: text/x-patch
Size: 1392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230719/11c41de5/attachment-0001.bin>


More information about the cfe-commits mailing list