diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-04-22 16:50:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-22 16:50:42 +0200 |
commit | c2ae5723b5418fa0f5901f2c21c2c905fa48a498 (patch) | |
tree | c46a4273c12715cba6a8f5301a1b3bc30c6938a9 | |
parent | 980531cac0988e509425e64fbd279ee98e25307c (diff) | |
download | llvm-c2ae5723b5418fa0f5901f2c21c2c905fa48a498.zip llvm-c2ae5723b5418fa0f5901f2c21c2c905fa48a498.tar.gz llvm-c2ae5723b5418fa0f5901f2c21c2c905fa48a498.tar.bz2 |
[clang][bytecode] Allow reinterpret casts from/to the same pointer type (#136692)
-rw-r--r-- | clang/lib/AST/ByteCode/Compiler.cpp | 2 | ||||
-rw-r--r-- | clang/test/AST/ByteCode/cxx11.cpp | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 3e53f2a..7cba0e8 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 23582e9..4c69517 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); + }; +} |