llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

Now that we have it, use it.

---
Full diff: https://github.com/llvm/llvm-project/pull/123522.diff


2 Files Affected:

- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+23-28) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+4-7) 


``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 7afae97f308ad5..78f936ec9f8958 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -689,20 +689,18 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) 
{
     if (!this->visit(SubExpr))
       return false;
 
-    auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
-    uint32_t I;
-    std::memcpy(&I, &Sem, sizeof(Sem));
-    return this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()), 
I,
-                                            CE);
+    auto Sem =
+        
Ctx.getASTContext().getFixedPointSemantics(CE->getType()).toOpaqueInt();
+    return this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()),
+                                            Sem, CE);
   }
   case CK_FloatingToFixedPoint: {
     if (!this->visit(SubExpr))
       return false;
 
-    auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
-    uint32_t I;
-    std::memcpy(&I, &Sem, sizeof(Sem));
-    return this->emitCastFloatingFixedPoint(I, CE);
+    auto Sem =
+        
Ctx.getASTContext().getFixedPointSemantics(CE->getType()).toOpaqueInt();
+    return this->emitCastFloatingFixedPoint(Sem, CE);
   }
   case CK_FixedPointToFloating: {
     if (!this->visit(SubExpr))
@@ -718,10 +716,9 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *CE) {
   case CK_FixedPointCast: {
     if (!this->visit(SubExpr))
       return false;
-    auto Sem = Ctx.getASTContext().getFixedPointSemantics(CE->getType());
-    uint32_t I;
-    std::memcpy(&I, &Sem, sizeof(Sem));
-    return this->emitCastFixedPoint(I, CE);
+    auto Sem =
+        
Ctx.getASTContext().getFixedPointSemantics(CE->getType()).toOpaqueInt();
+    return this->emitCastFixedPoint(Sem, CE);
   }
 
   case CK_ToVoid:
@@ -1522,28 +1519,29 @@ template <class Emitter>
 bool Compiler<Emitter>::VisitFixedPointBinOp(const BinaryOperator *E) {
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
+  const ASTContext &ASTCtx = Ctx.getASTContext();
 
   assert(LHS->getType()->isFixedPointType() ||
          RHS->getType()->isFixedPointType());
 
-  auto LHSSema = Ctx.getASTContext().getFixedPointSemantics(LHS->getType());
-  auto RHSSema = Ctx.getASTContext().getFixedPointSemantics(RHS->getType());
+  auto LHSSema = ASTCtx.getFixedPointSemantics(LHS->getType());
+  auto LHSSemaInt = LHSSema.toOpaqueInt();
+  auto RHSSema = ASTCtx.getFixedPointSemantics(RHS->getType());
+  auto RHSSemaInt = RHSSema.toOpaqueInt();
 
   if (!this->visit(LHS))
     return false;
   if (!LHS->getType()->isFixedPointType()) {
-    uint32_t I;
-    std::memcpy(&I, &LHSSema, sizeof(llvm::FixedPointSemantics));
-    if (!this->emitCastIntegralFixedPoint(classifyPrim(LHS->getType()), I, E))
+    if (!this->emitCastIntegralFixedPoint(classifyPrim(LHS->getType()),
+                                          LHSSemaInt, E))
       return false;
   }
 
   if (!this->visit(RHS))
     return false;
   if (!RHS->getType()->isFixedPointType()) {
-    uint32_t I;
-    std::memcpy(&I, &RHSSema, sizeof(llvm::FixedPointSemantics));
-    if (!this->emitCastIntegralFixedPoint(classifyPrim(RHS->getType()), I, E))
+    if (!this->emitCastIntegralFixedPoint(classifyPrim(RHS->getType()),
+                                          RHSSemaInt, E))
       return false;
   }
 
@@ -1551,13 +1549,10 @@ bool Compiler<Emitter>::VisitFixedPointBinOp(const 
BinaryOperator *E) {
   auto ConvertResult = [&](bool R) -> bool {
     if (!R)
       return false;
-    auto ResultSema = Ctx.getASTContext().getFixedPointSemantics(E->getType());
-    auto CommonSema = LHSSema.getCommonSemantics(RHSSema);
-    if (ResultSema != CommonSema) {
-      uint32_t I;
-      std::memcpy(&I, &ResultSema, sizeof(ResultSema));
-      return this->emitCastFixedPoint(I, E);
-    }
+    auto ResultSema = 
ASTCtx.getFixedPointSemantics(E->getType()).toOpaqueInt();
+    auto CommonSema = LHSSema.getCommonSemantics(RHSSema).toOpaqueInt();
+    if (ResultSema != CommonSema)
+      return this->emitCastFixedPoint(ResultSema, E);
     return true;
   };
 
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 93a91976a31bf1..58c0256c7d7df8 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2141,9 +2141,8 @@ inline bool CastFP(InterpState &S, CodePtr OpPC, const 
llvm::fltSemantics *Sem,
 }
 
 inline bool CastFixedPoint(InterpState &S, CodePtr OpPC, uint32_t FPS) {
-  FixedPointSemantics TargetSemantics(0, 0, false, false, false);
-  std::memcpy(&TargetSemantics, &FPS, sizeof(TargetSemantics));
-
+  FixedPointSemantics TargetSemantics =
+      FixedPointSemantics::getFromOpaqueInt(FPS);
   const auto &Source = S.Stk.pop<FixedPoint>();
 
   bool Overflow;
@@ -2271,8 +2270,7 @@ static inline bool CastIntegralFixedPoint(InterpState &S, 
CodePtr OpPC,
                                           uint32_t FPS) {
   const T &Int = S.Stk.pop<T>();
 
-  FixedPointSemantics Sem(0, 0, false, false, false);
-  std::memcpy(&Sem, &FPS, sizeof(Sem));
+  FixedPointSemantics Sem = FixedPointSemantics::getFromOpaqueInt(FPS);
 
   bool Overflow;
   FixedPoint Result = FixedPoint::from(Int.toAPSInt(), Sem, &Overflow);
@@ -2288,8 +2286,7 @@ static inline bool CastFloatingFixedPoint(InterpState &S, 
CodePtr OpPC,
                                           uint32_t FPS) {
   const auto &Float = S.Stk.pop<Floating>();
 
-  FixedPointSemantics Sem(0, 0, false, false, false);
-  std::memcpy(&Sem, &FPS, sizeof(Sem));
+  FixedPointSemantics Sem = FixedPointSemantics::getFromOpaqueInt(FPS);
 
   bool Overflow;
   FixedPoint Result = FixedPoint::from(Float.getAPFloat(), Sem, &Overflow);

``````````

</details>


https://github.com/llvm/llvm-project/pull/123522
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to