Skip to content

Commit c2ae572

Browse files
authored
[clang][bytecode] Allow reinterpret casts from/to the same pointer type (#136692)
1 parent 980531c commit c2ae572

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,6 +2990,8 @@ bool Compiler<Emitter>::VisitCXXReinterpretCastExpr(
29902990
if (PointeeToT && PointeeFromT) {
29912991
if (isIntegralType(*PointeeFromT) && isIntegralType(*PointeeToT))
29922992
Fatal = false;
2993+
} else {
2994+
Fatal = SubExpr->getType().getTypePtr() != E->getType().getTypePtr();
29932995
}
29942996

29952997
if (!this->emitInvalidCast(CastKind::Reinterpret, Fatal, E))

clang/test/AST/ByteCode/cxx11.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,11 @@ namespace InitLinkToRVO {
185185
constexpr A make() { return A {}; }
186186
static_assert(make().z == 4, "");
187187
}
188+
189+
namespace DynamicCast {
190+
struct S { int x, y; } s;
191+
constexpr S* sptr = &s;
192+
struct Str {
193+
int b : reinterpret_cast<S*>(sptr) == reinterpret_cast<S*>(sptr);
194+
};
195+
}

0 commit comments

Comments
 (0)