Skip to content

Conversation

@tbaederr
Copy link
Contributor

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Apr 22, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 22, 2025

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/136692.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Compiler.cpp (+2)
  • (modified) clang/test/AST/ByteCode/cxx11.cpp (+8)
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); + }; +} 
@tbaederr tbaederr merged commit c2ae572 into llvm:main Apr 22, 2025
15 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

2 participants