Skip to content

Conversation

@tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Mar 4, 2025

CallExpr::getType() isn't enough here in some cases, we need to use CallExpr::getCallReturnType().

CallExpr::getType() isn't enough here in some cases, we need to use
CallExpr::getCallReturnType().
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

CallExpr::getType() isn't enough here in some cases, we need to use CallExpr::getCallReturnType().


Full diff: https://github.com/llvm/llvm-project/pull/129722.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Interp.cpp (+1-1)
  • (modified) clang/test/AST/ByteCode/memberpointers.cpp (+23)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index bf9fdb6a690db..951823fa5f82f 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1512,7 +1512,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(), "");
+}

@tbaederr tbaederr merged commit aeca2aa into llvm:main Mar 4, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants