Skip to content

Commit

Permalink
[clang][Interp] Handle defined functions without a body
Browse files Browse the repository at this point in the history
This happens when explicitly defaulting a constructor, for example.

Differential Revision: https://reviews.llvm.org/D140776
  • Loading branch information
tbaederr committed Mar 2, 2023
1 parent 5230f6c commit bf6c134
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 3 additions & 6 deletions clang/lib/AST/Interp/ByteCodeEmitter.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions clang/test/AST/Interp/records.cpp
Expand Up @@ -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();
};

0 comments on commit bf6c134

Please sign in to comment.