Skip to content

Commit 60eb9b2

Browse files
authored
[clang][bytecode] Fix reinterpret casts of two non-primitive types (#107564)
We don't want to allow e.g. cast from a record to an array or the other way arround.
1 parent 1d2da21 commit 60eb9b2

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,8 +2579,15 @@ bool Compiler<Emitter>::VisitCXXReinterpretCastExpr(
25792579
const CXXReinterpretCastExpr *E) {
25802580
const Expr *SubExpr = E->getSubExpr();
25812581

2582-
bool TypesMatch = classify(E) == classify(SubExpr);
2583-
if (!this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/!TypesMatch, E))
2582+
bool Fatal = false;
2583+
std::optional<PrimType> FromT = classify(SubExpr);
2584+
std::optional<PrimType> ToT = classify(E);
2585+
if (!FromT || !ToT)
2586+
Fatal = true;
2587+
else
2588+
Fatal = (ToT != FromT);
2589+
2590+
if (!this->emitInvalidCast(CastKind::Reinterpret, Fatal, E))
25842591
return false;
25852592

25862593
return this->delegate(SubExpr);

0 commit comments

Comments
 (0)