Author: Timm Baeder Date: 2026-10-09T12:21:54+02:00 New Revision: ed4aed21f36b4afc0bfbbd04d1e0b7177edbd33a
URL: https://github.com/llvm/llvm-project/commit/ed4aed21f36b4afc0bfbbd04d1e0b7177edbd33a DIFF: https://github.com/llvm/llvm-project/commit/ed4aed21f36b4afc0bfbbd04d1e0b7177edbd33a.diff LOG: [clang][bytecode] Fix a crash in InvalidCast op (#230420) Since we have stuff like LocOverride, we can't rely on the expression we emitted the InvalidCast op for to be a CastExpr. Added: Modified: clang/lib/AST/ByteCode/Interp.cpp clang/test/AST/ByteCode/cxx17.cpp Removed: ################################################################################ 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
