[clang] 60eb9b2 - [clang][bytecode] Fix reinterpret casts of two non-primitive types (#107564)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 6 21:16:06 PDT 2024


Author: Timm Baeder
Date: 2024-09-07T06:16:02+02:00
New Revision: 60eb9b214cdcf482069ac4d5da9490b3bbd81b6a

URL: https://github.com/llvm/llvm-project/commit/60eb9b214cdcf482069ac4d5da9490b3bbd81b6a
DIFF: https://github.com/llvm/llvm-project/commit/60eb9b214cdcf482069ac4d5da9490b3bbd81b6a.diff

LOG: [clang][bytecode] Fix reinterpret casts of two non-primitive types (#107564)

We don't want to allow e.g. cast from a record to an array or the other
way arround.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index eea77c2f0a9bb4..e96bafd89c7eca 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2579,8 +2579,15 @@ bool Compiler<Emitter>::VisitCXXReinterpretCastExpr(
     const CXXReinterpretCastExpr *E) {
   const Expr *SubExpr = E->getSubExpr();
 
-  bool TypesMatch = classify(E) == classify(SubExpr);
-  if (!this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/!TypesMatch, E))
+  bool Fatal = false;
+  std::optional<PrimType> FromT = classify(SubExpr);
+  std::optional<PrimType> ToT = classify(E);
+  if (!FromT || !ToT)
+    Fatal = true;
+  else
+    Fatal = (ToT != FromT);
+
+  if (!this->emitInvalidCast(CastKind::Reinterpret, Fatal, E))
     return false;
 
   return this->delegate(SubExpr);


        


More information about the cfe-commits mailing list