Author: Timm Bäder Date: 2023-03-02T08:17:48+01:00 New Revision: bf6c1344ec1898d27760e135b77ad2676f88a697
URL: https://github.com/llvm/llvm-project/commit/bf6c1344ec1898d27760e135b77ad2676f88a697 DIFF: https://github.com/llvm/llvm-project/commit/bf6c1344ec1898d27760e135b77ad2676f88a697.diff LOG: [clang][Interp] Handle defined functions without a body This happens when explicitly defaulting a constructor, for example. Differential Revision: https://reviews.llvm.org/D140776 Added: Modified: clang/lib/AST/Interp/ByteCodeEmitter.cpp clang/test/AST/Interp/records.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index be56348beca7..f56e0d1ba32b 100644 --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -22,11 +22,6 @@ using Error = llvm::Error; Expected<Function *> ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) { - // Function is not defined at all or not yet. We will - // create a Function instance but not compile the body. That - // will (maybe) happen later. - bool HasBody = FuncDecl->hasBody(FuncDecl); - // Create a handle over the emitted code. Function *Func = P.getFunction(FuncDecl); if (!Func) { @@ -74,7 +69,9 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) { } 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. diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp index 027f881f4d80..fcf4b578d7d3 100644 --- a/clang/test/AST/Interp/records.cpp +++ b/clang/test/AST/Interp/records.cpp @@ -325,3 +325,9 @@ namespace DeriveFailures { // 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(); +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits