llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> Since we have stuff like LocOverride, we can't rely on the expression we emitted the InvalidCast op for to be a CastExpr. --- Full diff: https://github.com/llvm/llvm-project/pull/230420.diff 2 Files Affected: - (modified) clang/lib/AST/ByteCode/Interp.cpp (+4-3) - (modified) clang/test/AST/ByteCode/cxx17.cpp (+11) ``````````diff 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; + } +} `````````` </details> https://github.com/llvm/llvm-project/pull/230420 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
