[clang][bytecode] Fix CallPtr return type check (#129722)

CallExpr::getType() isn't enough here in some cases, we need to use
CallExpr::getCallReturnType().
This commit is contained in:
Timm Baeder 2025-03-04 17:14:13 +01:00 committed by GitHub
parent 0247a75072
commit aeca2aa193
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -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.

View File

@ -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(), "");
}