Author: Timm Baeder Date: 2025-04-22T16:50:42+02:00 New Revision: c2ae5723b5418fa0f5901f2c21c2c905fa48a498
URL: https://github.com/llvm/llvm-project/commit/c2ae5723b5418fa0f5901f2c21c2c905fa48a498 DIFF: https://github.com/llvm/llvm-project/commit/c2ae5723b5418fa0f5901f2c21c2c905fa48a498.diff LOG: [clang][bytecode] Allow reinterpret casts from/to the same pointer type (#136692) Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/test/AST/ByteCode/cxx11.cpp Removed: ################################################################################ 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