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

None

>From dfd494236fd57172cfddfd0db6789321e1662ccb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com>
Date: Tue, 22 Apr 2025 14:17:42 +0200
Subject: [PATCH] [clang][bytecode] Allow reinterpret casts from/to the same
 pointer type

---
 clang/lib/AST/ByteCode/Compiler.cpp | 2 ++
 clang/test/AST/ByteCode/cxx11.cpp   | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 3e53f2a2c8557..7cba0e8a4da19 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2990,6 +2990,8 @@ bool Compiler<Emitter>::VisitCXXReinterpretCastExpr(
     if (PointeeToT && PointeeFromT) {
       if (isIntegralType(*PointeeFromT) && isIntegralType(*PointeeToT))
         Fatal = false;
+    } else {
+      Fatal = SubExpr->getType().getTypePtr() != E->getType().getTypePtr();
     }
 
     if (!this->emitInvalidCast(CastKind::Reinterpret, Fatal, E))
diff --git a/clang/test/AST/ByteCode/cxx11.cpp 
b/clang/test/AST/ByteCode/cxx11.cpp
index 23582e9ab556a..4c69517304ea7 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -185,3 +185,11 @@ namespace InitLinkToRVO {
   constexpr A make() { return A {}; }
   static_assert(make().z == 4, "");
 }
+
+namespace DynamicCast {
+  struct S { int x, y; } s;
+  constexpr S* sptr = &s;
+  struct Str {
+    int b : reinterpret_cast<S*>(sptr) == reinterpret_cast<S*>(sptr);
+  };
+}

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

Reply via email to