[PATCH] D140776: [clang][Interp] Handle defined functions without a body

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 30 02:52:05 PST 2022


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.

Turns out that this happens when explicitly defaulting a constructor or destructor.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140776

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.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
@@ -325,3 +325,9 @@
                                        // expected-error {{must be initialized by a constant expression}}
                                        // FIXME: Missing reason for rejection.
 };
+
+namespace EmptyCtor {
+  struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
+  constexpr piecewise_construct_t piecewise_construct =
+    piecewise_construct_t();
+};
Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -73,7 +73,9 @@
   }
 
   assert(Func);
-  if (!HasBody)
+  // For not-yet-defined functions, we only create a Function instance and
+  // compile their body later.
+  if (!FuncDecl->isDefined())
     return Func;
 
   // Compile the function body.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140776.485682.patch
Type: text/x-patch
Size: 1050 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221230/b25a7f13/attachment.bin>


More information about the cfe-commits mailing list