[clang] [clang][bytecode] Add an `ExplicitThisParam` flag to `Function` (PR #203672)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 12 22:09:03 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We unfortunately have to check this for every function call, so don't consult the decl every time here.
---
Full diff: https://github.com/llvm/llvm-project/pull/203672.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Function.cpp (+5)
- (modified) clang/lib/AST/ByteCode/Function.h (+8-11)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Function.cpp b/clang/lib/AST/ByteCode/Function.cpp
index e08e2790dbd4f..cd0f7eb125230 100644
--- a/clang/lib/AST/ByteCode/Function.cpp
+++ b/clang/lib/AST/ByteCode/Function.cpp
@@ -29,12 +29,15 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
Constexpr = F->isConstexpr();
if (const auto *CD = dyn_cast<CXXConstructorDecl>(F)) {
Virtual = CD->isVirtual();
+ ExplicitThisPointer = CD->isExplicitObjectMemberFunction();
Kind = CD->isCopyOrMoveConstructor() ? FunctionKind::CopyOrMoveCtor
: FunctionKind::Ctor;
} else if (const auto *CD = dyn_cast<CXXDestructorDecl>(F)) {
+ ExplicitThisPointer = CD->isExplicitObjectMemberFunction();
Virtual = CD->isVirtual();
Kind = FunctionKind::Dtor;
} else if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
+ ExplicitThisPointer = MD->isExplicitObjectMemberFunction();
Virtual = MD->isVirtual();
if (IsLambdaStaticInvoker)
Kind = FunctionKind::LambdaStaticInvoker;
@@ -43,9 +46,11 @@ Function::Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
else if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())
Kind = FunctionKind::CopyOrMoveOperator;
} else {
+ ExplicitThisPointer = false;
Virtual = false;
}
} else {
+ ExplicitThisPointer = false;
Variadic = false;
Virtual = false;
Immediate = false;
diff --git a/clang/lib/AST/ByteCode/Function.h b/clang/lib/AST/ByteCode/Function.h
index d9a286937cadd..2ef529b6d586b 100644
--- a/clang/lib/AST/ByteCode/Function.h
+++ b/clang/lib/AST/ByteCode/Function.h
@@ -233,6 +233,12 @@ class Function final {
bool isVariadic() const { return Variadic; }
+ bool isThisPointerExplicit() const { return ExplicitThisPointer; }
+
+ bool hasImplicitThisParam() const {
+ return hasThisPointer() && !ExplicitThisPointer;
+ }
+
unsigned getNumParams() const {
return ParamDescriptors.size() + hasThisPointer() + hasRVO();
}
@@ -247,17 +253,6 @@ class Function final {
return ArgSize - (align(primSize(PT_Ptr)) * (hasThisPointer() + hasRVO()));
}
- bool isThisPointerExplicit() const {
- if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(
- dyn_cast<const FunctionDecl *>(Source)))
- return MD->isExplicitObjectMemberFunction();
- return false;
- }
-
- bool hasImplicitThisParam() const {
- return hasThisPointer() && !isThisPointerExplicit();
- }
-
private:
/// Construct a function representing an actual function.
Function(Program &P, FunctionDeclTy Source, unsigned ArgSize,
@@ -315,6 +310,8 @@ class Function final {
/// as the first implicit argument
LLVM_PREFERRED_TYPE(bool)
unsigned HasThisPointer : 1;
+ LLVM_PREFERRED_TYPE(bool)
+ unsigned ExplicitThisPointer : 1;
/// Whether this function has Return Value Optimization, i.e.
/// the return value is constructed in the caller's stack frame.
/// This is done for functions that return non-primive values.
``````````
</details>
https://github.com/llvm/llvm-project/pull/203672
More information about the cfe-commits
mailing list