cpu: nullptr in a DPRINTF statement
This change fixes the crashing of gem5 when `Branch` debug flag
is enabled. A DPRINTF statement had a nullptr. This change
prints `INVALID_TARGET` if the nullptr is encountered.
Signed-off-by: Kaustav Goswami <kggoswami@ucdavis.edu>
Change-Id: I40bd42c07de25a493a3dd1094a2fd8cc0ce0a79b
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/59109
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
diff --git a/src/cpu/pred/bpred_unit.cc b/src/cpu/pred/bpred_unit.cc
index 0940ae1..ac51567 100644
--- a/src/cpu/pred/bpred_unit.cc
+++ b/src/cpu/pred/bpred_unit.cc
@@ -335,10 +335,19 @@
while (!pred_hist.empty() &&
pred_hist.front().seqNum > squashed_sn) {
if (pred_hist.front().usedRAS) {
- DPRINTF(Branch, "[tid:%i] [squash sn:%llu]"
- " Restoring top of RAS to: %i,"
- " target: %s\n", tid, squashed_sn,
- pred_hist.front().RASIndex, *pred_hist.front().RASTarget);
+ if (pred_hist.front().RASTarget != nullptr) {
+ DPRINTF(Branch, "[tid:%i] [squash sn:%llu]"
+ " Restoring top of RAS to: %i,"
+ " target: %s\n", tid, squashed_sn,
+ pred_hist.front().RASIndex,
+ *pred_hist.front().RASTarget);
+ }
+ else {
+ DPRINTF(Branch, "[tid:%i] [squash sn:%llu]"
+ " Restoring top of RAS to: %i,"
+ " target: INVALID_TARGET\n", tid, squashed_sn,
+ pred_hist.front().RASIndex);
+ }
RAS[tid].restore(pred_hist.front().RASIndex,
pred_hist.front().RASTarget.get());