Author: Timm Baeder
Date: 2026-05-28T08:55:32+02:00
New Revision: 8059bc5944b72f3f6f3734ef61bf9eb89ca850a4

URL: 
https://github.com/llvm/llvm-project/commit/8059bc5944b72f3f6f3734ef61bf9eb89ca850a4
DIFF: 
https://github.com/llvm/llvm-project/commit/8059bc5944b72f3f6f3734ef61bf9eb89ca850a4.diff

LOG: [clang][bytecode] Fix a diagnostic difference in bitcasts (#197174)

Don't immediately return failure and let it be handled by later checks.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/lib/AST/ByteCode/Interp.cpp
    clang/lib/AST/ByteCode/InterpBuiltin.cpp
    clang/test/AST/ByteCode/cxx11.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 1e58d91861ad5..51f82330f97ca 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 ed182ea899f61..eeb302bdde4d3 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1719,7 +1719,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 8a53ae0937782..15d9b8554b425 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -6708,6 +6708,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();
@@ -6722,6 +6724,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) {
@@ -6733,8 +6737,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

Reply via email to