tbaeder updated this revision to Diff 489020. tbaeder added a comment. Just get the information whether the `Function` has a body directly from the `FunctionDecl`. This fixes referencing member functions that are defined later.
CHANGES SINCE LAST ACTION https://reviews.llvm.org/D141591/new/ https://reviews.llvm.org/D141591 Files: clang/lib/AST/Interp/ByteCodeEmitter.cpp clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/Function.h clang/test/AST/Interp/functions.cpp Index: clang/test/AST/Interp/functions.cpp =================================================================== --- clang/test/AST/Interp/functions.cpp +++ clang/test/AST/Interp/functions.cpp @@ -154,3 +154,21 @@ } } + +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; + } +}; Index: clang/lib/AST/Interp/Function.h =================================================================== --- clang/lib/AST/Interp/Function.h +++ clang/lib/AST/Interp/Function.h @@ -150,14 +150,15 @@ 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; } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1483,7 +1483,7 @@ 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; Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -91,7 +91,7 @@ // 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; }
Index: clang/test/AST/Interp/functions.cpp =================================================================== --- clang/test/AST/Interp/functions.cpp +++ clang/test/AST/Interp/functions.cpp @@ -154,3 +154,21 @@ } } + +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; + } +}; Index: clang/lib/AST/Interp/Function.h =================================================================== --- clang/lib/AST/Interp/Function.h +++ clang/lib/AST/Interp/Function.h @@ -150,14 +150,15 @@ 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; } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1483,7 +1483,7 @@ 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; Index: clang/lib/AST/Interp/ByteCodeEmitter.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeEmitter.cpp +++ clang/lib/AST/Interp/ByteCodeEmitter.cpp @@ -91,7 +91,7 @@ // 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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits