[clang] aeca2aa - [clang][bytecode] Fix CallPtr return type check (#129722)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 4 08:14:17 PST 2025
Author: Timm Baeder
Date: 2025-03-04T17:14:13+01:00
New Revision: aeca2aa19374d7f70f6f84a99510535b854ec15a
URL: https://github.com/llvm/llvm-project/commit/aeca2aa19374d7f70f6f84a99510535b854ec15a
DIFF: https://github.com/llvm/llvm-project/commit/aeca2aa19374d7f70f6f84a99510535b854ec15a.diff
LOG: [clang][bytecode] Fix CallPtr return type check (#129722)
CallExpr::getType() isn't enough here in some cases, we need to use
CallExpr::getCallReturnType().
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/memberpointers.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 9f641541ad4b6..a2090f3e85e08 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1515,7 +1515,7 @@ bool CallPtr(InterpState &S, CodePtr OpPC, uint32_t ArgSize,
// This happens when the call expression has been cast to
// something else, but we don't support that.
if (S.Ctx.classify(F->getDecl()->getReturnType()) !=
- S.Ctx.classify(CE->getType()))
+ S.Ctx.classify(CE->getCallReturnType(S.getASTContext())))
return false;
// Check argument nullability state.
diff --git a/clang/test/AST/ByteCode/memberpointers.cpp b/clang/test/AST/ByteCode/memberpointers.cpp
index ea4a725d3fd0d..db4a86ae03aff 100644
--- a/clang/test/AST/ByteCode/memberpointers.cpp
+++ b/clang/test/AST/ByteCode/memberpointers.cpp
@@ -226,3 +226,26 @@ namespace IndirectFields {
constexpr I i{12};
static_assert(ReadField<I, &I::a>(i) == 12, "");
}
+
+namespace CallExprTypeMismatch {
+ /// The call expression's getType() returns just S, not S&.
+ struct S {
+ constexpr S(int i_) : i(i_) {}
+ constexpr const S& identity() const { return *this; }
+ int i;
+ };
+
+ template<typename T, typename U>
+ constexpr void Call(T t, U u) {
+ ((&u)->*t)();
+ }
+
+ constexpr bool test() {
+ const S s{12};
+
+ Call(&S::identity, s);
+
+ return true;
+ }
+ static_assert(test(), "");
+}
More information about the cfe-commits
mailing list