https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/136407

Return Invalid() here instead of just false to match the diagnostic output of 
the current interpreter.

>From 1446ab0c9e4c6b32d330777221b2f5ebc63beb02 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com>
Date: Sat, 19 Apr 2025 07:57:42 +0200
Subject: [PATCH] [clang][bytecode] Diagnose failed MemberPtrPtr casts
 differently

Return Invalid() here instead of just false to match the diagnostic
output of the current interpreter.
---
 clang/lib/AST/ByteCode/Interp.h            |  2 +-
 clang/test/AST/ByteCode/memberpointers.cpp | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 49e2326186bf8..866d8e4bf2251 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1932,7 +1932,7 @@ inline bool CastMemberPtrPtr(InterpState &S, CodePtr 
OpPC) {
     S.Stk.push<Pointer>(*Ptr);
     return true;
   }
-  return false;
+  return Invalid(S, OpPC);
 }
 
 
//===----------------------------------------------------------------------===//
diff --git a/clang/test/AST/ByteCode/memberpointers.cpp 
b/clang/test/AST/ByteCode/memberpointers.cpp
index db4a86ae03aff..5d622187e97f2 100644
--- a/clang/test/AST/ByteCode/memberpointers.cpp
+++ b/clang/test/AST/ByteCode/memberpointers.cpp
@@ -249,3 +249,21 @@ namespace CallExprTypeMismatch {
   }
   static_assert(test(), "");
 }
+
+namespace CastMemberPtrPtrFailed{
+  struct S {
+    constexpr S() {}
+    constexpr int f() const;
+    constexpr int g() const;
+  };
+  struct T : S {
+    constexpr T(int n) : S(), n(n) {}
+    int n;
+  };
+
+  constexpr int S::g() const {
+    return this->*(int(S::*))&T::n; // both-note {{subexpression}}
+  }
+  static_assert(S().g(), ""); // both-error {{constant expression}} \
+                              // both-note {{in call to 'S().g()'}}
+}

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to