diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index f56e0d1ba32b2..7453b60118eac 100644 --- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -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; } diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index c6cf7f7c99a59..1e61bc9924484 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1465,7 +1465,7 @@ const Function *ByteCodeExprGen::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; diff --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h index 422211708a77e..005cda7379c2d 100644 --- a/clang/lib/AST/Interp/Function.h +++ b/clang/lib/AST/Interp/Function.h @@ -157,14 +157,15 @@ class Function final { bool HasThisPointer, bool HasRVO); /// Sets the code of a function. - void setCode(unsigned NewFrameSize, std::vector &&NewCode, SourceMap &&NewSrcMap, - llvm::SmallVector &&NewScopes) { + void setCode(unsigned NewFrameSize, std::vector &&NewCode, + SourceMap &&NewSrcMap, llvm::SmallVector &&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; } diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 9c0d516865812..5113593d8d117 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -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; + } +};