about summary refs log tree commit diff
path: root/compiler/rustc_mir/src/transform/coverage/counters.rs
diff options
context:
space:
mode:
authorRich Kadel <richkadel@google.com>2020-10-25 11:13:16 -0700
committerRich Kadel <richkadel@google.com>2020-11-05 18:24:17 -0800
commit1973f84ebbb3b2bb4b9a1488b6553ac46b2db8d4 (patch)
treeafdc71d2c96bc6fcb4ce8782a2bbfe8fbbaef1fa /compiler/rustc_mir/src/transform/coverage/counters.rs
parent5545c56e9d55909e7b4549c158a39449068d2ef0 (diff)
downloadrust-1973f84ebbb3b2bb4b9a1488b6553ac46b2db8d4.tar.gz
rust-1973f84ebbb3b2bb4b9a1488b6553ac46b2db8d4.zip
Addressed all feedback to date
Diffstat (limited to 'compiler/rustc_mir/src/transform/coverage/counters.rs')
-rw-r--r--compiler/rustc_mir/src/transform/coverage/counters.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_mir/src/transform/coverage/counters.rs b/compiler/rustc_mir/src/transform/coverage/counters.rs
index a3ae3021524..7454ec2f438 100644
--- a/compiler/rustc_mir/src/transform/coverage/counters.rs
+++ b/compiler/rustc_mir/src/transform/coverage/counters.rs
@@ -12,6 +12,16 @@ use rustc_data_structures::graph::WithNumNodes;
 use rustc_index::bit_set::BitSet;
 use rustc_middle::mir::coverage::*;
 
+// When evaluating an expression operand to determine if it references a `Counter` or an
+// `Expression`, the range of counter or expression IDs must be known in order to answer the
+// question: "Does this ID fall inside the range of counters," for example. If "yes," the ID refers
+// to a counter, otherwise the ID refers to an expression.
+//
+// But in situations where the range is not currently known, the only fallback is to assume a
+// specific range limit. `MAX_COUNTER_GUARD` enforces a limit on the number of counters, and
+// therefore a limit on the range of counter IDs.
+pub(crate) const MAX_COUNTER_GUARD: u32 = (u32::MAX / 2) + 1;
+
 /// Manages the counter and expression indexes/IDs to generate `CoverageKind` components for MIR
 /// `Coverage` statements.
 pub(crate) struct CoverageCounters {
@@ -95,6 +105,7 @@ impl CoverageCounters {
     /// Counter IDs start from one and go up.
     fn next_counter(&mut self) -> CounterValueReference {
         assert!(self.next_counter_id < u32::MAX - self.num_expressions);
+        assert!(self.next_counter_id <= MAX_COUNTER_GUARD);
         let next = self.next_counter_id;
         self.next_counter_id += 1;
         CounterValueReference::from(next)