Author: Timm Bäder Date: 2023-03-31T07:27:04+02:00 New Revision: 30f96a8fb4511bed31a75863d4abec51c3d967a8
URL: https://github.com/llvm/llvm-project/commit/30f96a8fb4511bed31a75863d4abec51c3d967a8 DIFF: https://github.com/llvm/llvm-project/commit/30f96a8fb4511bed31a75863d4abec51c3d967a8.diff LOG: [clang][Interp] Properly identify not-yet-defined functions 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 Added: Modified: clang/lib/AST/Interp/ByteCodeEmitter.cpp clang/lib/AST/Interp/ByteCodeExprGen.cpp clang/lib/AST/Interp/Function.h clang/test/AST/Interp/functions.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp index f56e0d1ba32b..7453b60118ea 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 c6cf7f7c99a5..1e61bc992448 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -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; diff --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h index 422211708a77..005cda7379c2 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<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; } diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 9c0d51686581..5113593d8d11 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; + } +}; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits