diff options
author | Jacob Bramley <jacob.bramley@arm.com> | 2020-07-22 20:29:00 +0100 |
---|---|---|
committer | Jacob Bramley <jacob.bramley@arm.com> | 2020-07-24 12:30:01 +0000 |
commit | aaf02c54f1f68153d769db26577317e1d4f46c1b (patch) | |
tree | 5cf374df5ba12457a83b39f8e581788cc1263b71 /src | |
parent | f3f5d246129febc518cfa99003ee66c5008202c5 (diff) | |
download | vixl-aaf02c54f1f68153d769db26577317e1d4f46c1b.tar.gz |
Fix initialisation order for ID register fields.
Making the constructor `constexpr` gives these "constant" rather than
"dynamic" initialisation, which guarantees that they'll be initialised
before any other dynamically-initialised static variables.
This makes it safe to make static variable initialisers dependent on the
result of `CPUFeatures::InferFromOS()` and similar functions.
Change-Id: Ib65e92273c7ac03d07e17cbe844b598ef3bc60ac
Diffstat (limited to 'src')
-rw-r--r-- | src/aarch64/cpu-aarch64.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/aarch64/cpu-aarch64.h b/src/aarch64/cpu-aarch64.h index 74b23934..2bf1e60f 100644 --- a/src/aarch64/cpu-aarch64.h +++ b/src/aarch64/cpu-aarch64.h @@ -56,7 +56,11 @@ class IDRegister { public: enum Type { kUnsigned, kSigned }; - explicit Field(int lsb, Type type = kUnsigned) : lsb_(lsb), type_(type) {} + // This needs to be constexpr so that fields have "constant initialisation". + // This avoids initialisation order problems when these values are used to + // (dynamically) initialise static variables, etc. + explicit constexpr Field(int lsb, Type type = kUnsigned) + : lsb_(lsb), type_(type) {} static const int kMaxWidthInBits = 4; |