[clang] [clang][Interp] Bail out from type-punning casts (PR #163809)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 16 08:52:13 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang/lib/AST/ByteCode/Compiler.cpp clang/lib/AST/ByteCode/Compiler.h --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index c30262dd8..62d744a16 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -213,8 +213,7 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
const Expr *SubExpr = CE->getSubExpr();
if (isPunningDereference(SubExpr))
- return this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/true,
- CE);
+ return this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/true, CE);
if (DiscardResult)
return this->delegate(SubExpr);
@@ -5516,8 +5515,7 @@ bool Compiler<Emitter>::maybeEmitDeferredVarInit(const VarDecl *VD) {
}
template <class Emitter>
-bool Compiler<Emitter>::isPunningDereference(const Expr *E)
-{
+bool Compiler<Emitter>::isPunningDereference(const Expr *E) {
E = E->IgnoreParenImpCasts();
const auto *UO = dyn_cast<UnaryOperator>(E);
@@ -5531,22 +5529,22 @@ bool Compiler<Emitter>::isPunningDereference(const Expr *E)
// Only consider reinterpret-ish casts
switch (Cast->getCastKind()) {
- case CK_BitCast:
- case CK_PointerToIntegral:
- case CK_IntegralToPointer:
- case CK_AddressSpaceConversion:
- break;
- default:
- return false; // CK_NoOp etc. are fine
+ case CK_BitCast:
+ case CK_PointerToIntegral:
+ case CK_IntegralToPointer:
+ case CK_AddressSpaceConversion:
+ break;
+ default:
+ return false; // CK_NoOp etc. are fine
}
QualType DestPtrTy = Cast->getType();
- QualType SrcPtrTy = Cast->getSubExpr()->getType();
+ QualType SrcPtrTy = Cast->getSubExpr()->getType();
if (!DestPtrTy->isPointerType() || !SrcPtrTy->isPointerType())
return true; // super fishy, treat it as a pun
QualType DestPointee = DestPtrTy->getPointeeType();
- QualType SrcPointee = SrcPtrTy->getPointeeType();
+ QualType SrcPointee = SrcPtrTy->getPointeeType();
// If pointee types differ (ignoring qualifiers), its a pun
if (!Ctx.getASTContext().hasSameUnqualifiedType(DestPointee, SrcPointee))
``````````
</details>
https://github.com/llvm/llvm-project/pull/163809
More information about the cfe-commits
mailing list