https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/197174
>From 9a8a85c9b3528c554ca1a15b61a732bc2aacbd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Tue, 12 May 2026 14:07:04 +0200 Subject: [PATCH] [clang][bytecode] Fix a diagnostic difference in bitcasts Don't immediately return failure and let it be handled by later checks. --- clang/lib/AST/ByteCode/Compiler.cpp | 4 +++- clang/lib/AST/ByteCode/Interp.cpp | 1 - clang/lib/AST/ByteCode/InterpBuiltin.cpp | 9 ++++++++- clang/test/AST/ByteCode/cxx11.cpp | 5 ++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 683676529d52f..3c140407c91f2 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -833,7 +833,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *E) { return this->delegate(SubExpr); case CK_LValueBitCast: - return this->emitInvalidCast(CastKind::ReinterpretLike, /*Fatal=*/true, E); + if (!this->emitInvalidCast(CastKind::ReinterpretLike, /*Fatal=*/false, E)) + return false; + return this->delegate(SubExpr); case CK_HLSLArrayRValue: { // Non-decaying array rvalue cast - creates an rvalue copy of an lvalue diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 0ac6d2f7737fc..595990fcf4080 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1708,7 +1708,6 @@ bool CheckBitCast(InterpState &S, CodePtr OpPC, const Type *TargetType, S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_invalid_cast) << diag::ConstexprInvalidCastKind::ThisConversionOrReinterpret << S.getLangOpts().CPlusPlus << S.Current->getRange(OpPC); - return false; } return true; } diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 5ba15b7ad4f63..10648acacb638 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -6687,6 +6687,8 @@ static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src, assert(!DestDesc->isPrimitive() && !SrcDesc->isPrimitive()); if (DestDesc->isPrimitiveArray()) { + if (!SrcDesc->isPrimitiveArray()) + return false; assert(SrcDesc->isPrimitiveArray()); assert(SrcDesc->getNumElems() == DestDesc->getNumElems()); PrimType ET = DestDesc->getPrimType(); @@ -6701,6 +6703,8 @@ static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src, } if (DestDesc->isCompositeArray()) { + if (!SrcDesc->isCompositeArray()) + return false; assert(SrcDesc->isCompositeArray()); assert(SrcDesc->getNumElems() == DestDesc->getNumElems()); for (unsigned I = 0, N = DestDesc->getNumElems(); I != N; ++I) { @@ -6712,8 +6716,11 @@ static bool copyComposite(InterpState &S, CodePtr OpPC, const Pointer &Src, return true; } - if (DestDesc->isRecord()) + if (DestDesc->isRecord()) { + if (!SrcDesc->isRecord()) + return false; return copyRecord(S, OpPC, Src, Dest, Activate); + } return Invalid(S, OpPC); } diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp index 3acfe50627713..b58088096e377 100644 --- a/clang/test/AST/ByteCode/cxx11.cpp +++ b/clang/test/AST/ByteCode/cxx11.cpp @@ -404,13 +404,12 @@ constexpr int PassByValue(Counter c) { return c.copies; } static_assert(PassByValue(Counter(0)) == 0, "expect no copies"); namespace PointerCast { - /// The two interpreters disagree here. struct S { int x, y; } s; constexpr S* sptr = &s; struct U {}; struct Str { - int e : (Str*)(sptr) == (Str*)(sptr); // expected-error {{not an integral constant expression}} \ - // expected-note {{cast that performs the conversions of a reinterpret_cast}} + int e : (Str*)(sptr) == (Str*)(sptr); + int f : &(U&)(*sptr) == &(U&)(*sptr); }; } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
