https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/230420
Since we have stuff like LocOverride, we can't rely on the expression we emitted the InvalidCast op for to be a CastExpr. >From 7ed8bdaf77e2caab5baedd4d205c5f1fc4938e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Fri, 9 Oct 2026 11:06:53 +0200 Subject: [PATCH] [clang][bytecode] Fix a crash in InvalidCast op Since we have stuff like LocOverride, we can't rely on the expression we emitted the InvalidCast op for to be a CastExpr. --- clang/lib/AST/ByteCode/Interp.cpp | 7 ++++--- clang/test/AST/ByteCode/cxx17.cpp | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index d7a6d160228b92..21e5d3e617fe78 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -3342,10 +3342,11 @@ bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind, bool Fatal) { return !Fatal; case CastKind::Volatile: if (!S.checkingPotentialConstantExpression()) { - const auto *E = cast<CastExpr>(S.Current->getExpr(OpPC)); - if (S.getLangOpts().CPlusPlus) + const auto *E = S.Current->getExpr(OpPC); + const auto *CE = dyn_cast<CastExpr>(E); + if (CE && S.getLangOpts().CPlusPlus) S.FFDiag(E, diag::note_constexpr_access_volatile_type) - << AK_Read << E->getSubExpr()->getType(); + << AK_Read << CE->getSubExpr()->getType(); else S.FFDiag(E); } diff --git a/clang/test/AST/ByteCode/cxx17.cpp b/clang/test/AST/ByteCode/cxx17.cpp index 9168f0d34d872f..c4927f675d28ea 100644 --- a/clang/test/AST/ByteCode/cxx17.cpp +++ b/clang/test/AST/ByteCode/cxx17.cpp @@ -194,3 +194,14 @@ namespace InitListBaseInit { static_assert(b.a.m == 43); static_assert(b.i == 0); } + +namespace NonCastExprInvalidCast { + struct S1 { + volatile unsigned int x : 16; + volatile unsigned int y : 16; + }; + void fS1() { + S1 s1; + auto [a, b] = s1; + } +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
