Skip to content

Commit

Permalink
[clang][Interp] Properly identify not-yet-defined functions
Browse files Browse the repository at this point in the history
Since we now handle functions without a body as well, we can't just use
getHasBody() anymore. Funtions that haven't been defined yet are those
that don't have a body *and* aren't valid.

Also, just pass the information about whether the Function has a body or
not along from the FunctionDecl.

Differential Revision: https://reviews.llvm.org/D141591
  • Loading branch information
tbaederr committed Mar 31, 2023
1 parent 3834b04 commit 30f96a8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/ByteCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {

// Set the function's code.
Func->setCode(NextLocalOffset, std::move(Code), std::move(SrcMap),
std::move(Scopes));
std::move(Scopes), FuncDecl->hasBody());
Func->setIsFullyCompiled(true);
return Func;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ const Function *ByteCodeExprGen<Emitter>::getFunction(const FunctionDecl *FD) {
assert(FD);
const Function *Func = P.getFunction(FD);
bool IsBeingCompiled = Func && !Func->isFullyCompiled();
bool WasNotDefined = Func && !Func->hasBody();
bool WasNotDefined = Func && !Func->isConstexpr() && !Func->hasBody();

if (IsBeingCompiled)
return Func;
Expand Down
7 changes: 4 additions & 3 deletions clang/lib/AST/Interp/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ class Function final {
bool HasThisPointer, bool HasRVO);

/// Sets the code of a function.
void setCode(unsigned NewFrameSize, std::vector<char> &&NewCode, SourceMap &&NewSrcMap,
llvm::SmallVector<Scope, 2> &&NewScopes) {
void setCode(unsigned NewFrameSize, std::vector<char> &&NewCode,
SourceMap &&NewSrcMap, llvm::SmallVector<Scope, 2> &&NewScopes,
bool NewHasBody) {
FrameSize = NewFrameSize;
Code = std::move(NewCode);
SrcMap = std::move(NewSrcMap);
Scopes = std::move(NewScopes);
IsValid = true;
HasBody = true;
HasBody = NewHasBody;
}

void setIsFullyCompiled(bool FC) { IsFullyCompiled = FC; }
Expand Down
18 changes: 18 additions & 0 deletions clang/test/AST/Interp/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,21 @@ namespace FunctionReturnType {
}

}

struct F {
constexpr bool ok() const {
return okRecurse();
}
constexpr bool okRecurse() const {
return true;
}
};

struct BodylessMemberFunction {
constexpr int first() const {
return second();
}
constexpr int second() const {
return 1;
}
};

0 comments on commit 30f96a8

Please sign in to comment.