summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Sandberg <Andreas.Sandberg@ARM.com>2014-08-26 10:13:28 -0400
committerAndreas Sandberg <Andreas.Sandberg@ARM.com>2014-08-26 10:13:28 -0400
commit61b8d5e4e4b27010f5dd757a34e7295bb5dd10ff (patch)
tree04092d104f18cd22dc58214fed8bf847d07d6844
parenta3d3eb0ff777e0580aa30f52f31958a090cbe3af (diff)
downloadgem5-61b8d5e4e4b27010f5dd757a34e7295bb5dd10ff.tar.xz
base: Add a static assert to check bit union ranges
If a bit field in a bit union specified as Bitfield<LSB, MSB> instead of Bitfield<MSB, LSB> the code silently fails and the field is read as zero. This changeset introduces a static assert that tests, at compile time, that the bit order is correct.
-rw-r--r--src/base/bitunion.hh3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/base/bitunion.hh b/src/base/bitunion.hh
index f640fa3b1..190c1a5e1 100644
--- a/src/base/bitunion.hh
+++ b/src/base/bitunion.hh
@@ -85,6 +85,9 @@ namespace BitfieldBackend
template<int first, int last=first>
class Bitfield : public BitfieldBase<Type>
{
+ static_assert(first >= last,
+ "Bitfield ranges must be specified as <msb, lsb>");
+
public:
operator const uint64_t () const
{