[clang] c784abf - [clang][Interp] Delay compiling functions that don't have a body yet
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 12 08:49:47 PDT 2024
Author: Timm Bäder
Date: 2024-07-12T17:32:39+02:00
New Revision: c784abf2007a98c5fea64a84b56fa21974983d90
URL: https://github.com/llvm/llvm-project/commit/c784abf2007a98c5fea64a84b56fa21974983d90
DIFF: https://github.com/llvm/llvm-project/commit/c784abf2007a98c5fea64a84b56fa21974983d90.diff
LOG: [clang][Interp] Delay compiling functions that don't have a body yet
Sometimes, isDefined() returns true, even though the function doesn't
have a body yet, but will have one later. This is for example the case
when referring to a class member function via a member pointer before
the member function has been fully parsed. Reject them at first and
compile them later.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/test/AST/Interp/memberpointers.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 918cd66c9a976..ae777d555e916 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -147,7 +147,8 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
assert(Func);
// For not-yet-defined functions, we only create a Function instance and
// compile their body later.
- if (!FuncDecl->isDefined()) {
+ if (!FuncDecl->isDefined() ||
+ (FuncDecl->willHaveBody() && !FuncDecl->hasBody())) {
Func->setDefined(false);
return Func;
}
diff --git a/clang/test/AST/Interp/memberpointers.cpp b/clang/test/AST/Interp/memberpointers.cpp
index 178d2e23f1266..f38e948638631 100644
--- a/clang/test/AST/Interp/memberpointers.cpp
+++ b/clang/test/AST/Interp/memberpointers.cpp
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -std=c++14 -fexperimental-new-constant-interpreter -verify=expected,both %s
+// RUN: %clang_cc1 -std=c++23 -fexperimental-new-constant-interpreter -verify=expected,both %s
// RUN: %clang_cc1 -std=c++14 -verify=ref,both %s
+// RUN: %clang_cc1 -std=c++23 -verify=ref,both %s
namespace MemberPointers {
struct A {
More information about the cfe-commits
mailing list