Andrea Mondelli has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/17308

Change subject: arm: Correct cast of template parameter
......................................................................

arm: Correct cast of template parameter

Clang with -Wconstant-conversion is _very_ restrictive on casting.
The shift operator results in an incorrect promotion.

This patch add a compile-time static cast that remove the error
when clang is used.

Change-Id: I3aa1e77da2565799feadc32317d5faa111b2de86
---
M src/arch/arm/isa/insts/sve.isa
M src/base/bitfield.hh
2 files changed, 13 insertions(+), 5 deletions(-)



diff --git a/src/arch/arm/isa/insts/sve.isa b/src/arch/arm/isa/insts/sve.isa
index b1b946f..14395d8 100644
--- a/src/arch/arm/isa/insts/sve.isa
+++ b/src/arch/arm/isa/insts/sve.isa
@@ -4278,7 +4278,9 @@
             bool negSrc1 = (srcElem1 < 0);
             bool negSrc2 = (srcElem2 < 0);
             if ((negDest != negSrc1) && (negSrc1 == negSrc2)) {
-                destElem = (Element)1 << (sizeof(Element) * 8 - 1);
+                destElem = static_cast<Element>(
+                    static_cast<Element>(1) << (sizeof(Element) * 8 - 1)
+                    );
                 if (negDest)
                     destElem -= 1;
             }
@@ -4293,7 +4295,9 @@
         bool negSrc = (srcElem1 < 0);
         bool posCount = ((count * imm) >= 0);
         if ((negDest != negSrc) && (negSrc == posCount)) {
-            destElem = (%(dstType)s)1 << (sizeof(%(dstType)s) * 8 - 1);
+            destElem = static_cast<%(dstType)s>(
+                (%(dstType)s)1 << (sizeof(%(dstType)s) * 8 - 1)
+                );
             if (negDest)
                 destElem -= 1;
         }
@@ -4350,7 +4354,9 @@
         bool negSrc = (srcElem1 < 0);
         bool negCount = ((count * imm) < 0);
         if ((negDest != negSrc) && (negSrc == negCount)) {
-            destElem = (%(dstType)s)1 << (sizeof(%(dstType)s) * 8 - 1);
+            destElem = static_cast<%(dstType)s>(
+                (%(dstType)s)1 << (sizeof(%(dstType)s) * 8 - 1)
+                );
             if (negDest)
                 destElem -= 1;
         }
@@ -4407,7 +4413,9 @@
         bool negSrc1 = (srcElem1 < 0);
         bool posSrc2 = (srcElem2 >= 0);
         if ((negDest != negSrc1) && (negSrc1 == posSrc2)) {
-            destElem = (Element)1 << (sizeof(Element) * 8 - 1);
+            destElem = static_cast<Element>(
+                static_cast<Element>(1) << (sizeof(Element) * 8 - 1)
+                );
             if (negDest)
                 destElem -= 1;
         }
diff --git a/src/base/bitfield.hh b/src/base/bitfield.hh
index d696715..ec1ffce 100644
--- a/src/base/bitfield.hh
+++ b/src/base/bitfield.hh
@@ -182,7 +182,7 @@
     assert(size <= sizeof(T));

     T output = 0;
-    for (auto byte = 0; byte < size; byte++, val >>= 8) {
+ for (auto byte = 0; byte < size; byte++, val = static_cast<T>(val >> 8)) {
         output = (output << 8) | reverseLookUpTable[val & 0xFF];
     }


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/17308
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I3aa1e77da2565799feadc32317d5faa111b2de86
Gerrit-Change-Number: 17308
Gerrit-PatchSet: 1
Gerrit-Owner: Andrea Mondelli <andrea.monde...@ucf.edu>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to