Daniel Carvalho has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/27104 )
Change subject: base: Fix undefined behavior in mask generation
..
base: Fix undefined behavior in mask generation
When generating a mask, if the number of bits is greater than
the maximum shift distance (63), the shift will have undefined
behavior. Previously the branch was taking care of a single
trespassing case, and it has been fixed to cover the remaining.
Issue-on: https://gem5.atlassian.net/browse/GEM5-205
Change-Id: Ib5a00917c8d2b23ffdb710c2f9673d956cd9f43e
Signed-off-by: Daniel R. Carvalho
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27104
Tested-by: Gem5 Cloud Project GCB service account
<345032938...@cloudbuild.gserviceaccount.com>
Tested-by: kokoro
Reviewed-by: Gabe Black
Maintainer: Gabe Black
---
M src/base/bitfield.hh
1 file changed, 5 insertions(+), 2 deletions(-)
Approvals:
Gabe Black: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
Gem5 Cloud Project GCB service account: Regressions pass
diff --git a/src/base/bitfield.hh b/src/base/bitfield.hh
index 9a252a4..c2ed72b 100644
--- a/src/base/bitfield.hh
+++ b/src/base/bitfield.hh
@@ -50,12 +50,15 @@
extern const uint8_t reverseLookUpTable[];
/**
- * Generate a 64-bit mask of 'nbits' 1s, right justified.
+ * Generate a 64-bit mask of 'nbits' 1s, right justified. If a number of
bits
+ * greater than 64 is given, it is truncated to 64.
+ *
+ * @param nbits The number of bits set in the mask.
*/
inline uint64_t
mask(int nbits)
{
-return (nbits == 64) ? (uint64_t)-1LL : (1ULL << nbits) - 1;
+return (nbits >= 64) ? (uint64_t)-1LL : (1ULL << nbits) - 1;
}
/**
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27104
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ib5a00917c8d2b23ffdb710c2f9673d956cd9f43e
Gerrit-Change-Number: 27104
Gerrit-PatchSet: 2
Gerrit-Owner: Daniel Carvalho
Gerrit-Reviewer: Bobby R. Bruce
Gerrit-Reviewer: Daniel Carvalho
Gerrit-Reviewer: Gabe Black
Gerrit-Reviewer: Gem5 Cloud Project GCB service account
<345032938...@cloudbuild.gserviceaccount.com>
Gerrit-Reviewer: kokoro
Gerrit-MessageType: merged
___
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev