Skip to content

Commit cc8b927

Browse files
authored
Merge pull request #10407 from The-OpenROAD-Project-staging/secure-fix-coverity-rsz2
rsz: Fix Coverity defects
2 parents 1ca7d21 + a6ac84b commit cc8b927

10 files changed

Lines changed: 107 additions & 109 deletions

src/rsz/src/DelayEstimator.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,11 @@ ArcDelayState collectPathStages(const Resizer& resizer,
11541154
}
11551155
std::ranges::reverse(fanin_stages);
11561156

1157-
context.path_stages = std::move(fanin_stages);
1157+
context.path_stages.reserve(fanin_stages.size() + 1 + delay_levels);
1158+
for (DelayStageState& stage : fanin_stages) {
1159+
context.path_stages.push_back(std::move(stage));
1160+
}
11581161
context.target_stage_index = static_cast<int>(context.path_stages.size());
1159-
context.path_stages.reserve(context.path_stages.size() + 1 + delay_levels);
11601162
context.path_stages.push_back(target_stage);
11611163

11621164
int found_fanout_stages = 0;

src/rsz/src/DelayEstimatorReporter.cc

Lines changed: 68 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <optional>
1212
#include <string>
1313
#include <string_view>
14+
#include <utility>
1415
#include <vector>
1516

1617
#include "DelayEstimator.hh"
@@ -295,11 +296,16 @@ void DelayEstimatorReporter::reportAccuracyForSizing(
295296
{
296297
odb::dbDatabase::beginEco(reporter.block_);
297298
}
298-
~EcoJournalScope()
299+
~EcoJournalScope() noexcept
299300
{
300-
reporter.resizer_.initForJournalRestore();
301-
odb::dbDatabase::undoEco(reporter.block_);
302-
reporter.resizer_.updateParasiticsAndTiming();
301+
try {
302+
reporter.resizer_.initForJournalRestore();
303+
odb::dbDatabase::undoEco(reporter.block_);
304+
reporter.resizer_.updateParasiticsAndTiming();
305+
} catch (...) {
306+
// Destructors must not throw during diagnostic ECO cleanup.
307+
return;
308+
}
303309
}
304310
};
305311

@@ -702,25 +708,31 @@ DelayEstimatorReporter::buildLegacyProfile(const Target& target,
702708
}
703709

704710
sta::PathExpanded expanded(target.endpoint_path, resizer_.staState());
705-
StageProfileRow current_row{
706-
.path_index = target.path_index,
707-
.role = Role::kTarget,
708-
.pin_name = stagePinName(expanded, target.path_index),
709-
.cell_name = driver_port->libertyCell()->name(),
710-
.input_slew = context->target().input_slew,
711-
.cell_delay = current_cell_delay,
712-
.wire_delay = pathWireDelay(expanded, target.path_index),
713-
.load_cap = load_cap,
714-
.output_slew = context->target().current_slew,
715-
.extra_delay = current_fanin_penalty};
716-
profile.current_stages.push_back(current_row);
717-
718-
StageProfileRow candidate_row = current_row;
719-
candidate_row.cell_name = replacement->name();
720-
candidate_row.cell_delay = candidate_cell_delay;
721-
candidate_row.output_slew = kMissingValue;
722-
candidate_row.extra_delay = candidate_fanin_penalty;
723-
profile.candidate_stages.push_back(candidate_row);
711+
const std::string target_pin_name = stagePinName(expanded, target.path_index);
712+
const float target_wire_delay = pathWireDelay(expanded, target.path_index);
713+
StageProfileRow current_row{.path_index = target.path_index,
714+
.role = Role::kTarget,
715+
.pin_name = target_pin_name,
716+
.cell_name = driver_port->libertyCell()->name(),
717+
.input_slew = context->target().input_slew,
718+
.cell_delay = current_cell_delay,
719+
.wire_delay = target_wire_delay,
720+
.load_cap = load_cap,
721+
.output_slew = context->target().current_slew,
722+
.extra_delay = current_fanin_penalty};
723+
profile.current_stages.push_back(std::move(current_row));
724+
725+
StageProfileRow candidate_row{.path_index = target.path_index,
726+
.role = Role::kTarget,
727+
.pin_name = target_pin_name,
728+
.cell_name = replacement->name(),
729+
.input_slew = context->target().input_slew,
730+
.cell_delay = candidate_cell_delay,
731+
.wire_delay = target_wire_delay,
732+
.load_cap = load_cap,
733+
.output_slew = kMissingValue,
734+
.extra_delay = candidate_fanin_penalty};
735+
profile.candidate_stages.push_back(std::move(candidate_row));
724736

725737
return profile;
726738
}
@@ -877,7 +889,7 @@ DelayEstimatorReporter::captureFixedStages(const Target& target,
877889
fixed_stage.next_pin_name = network_->pathName(next_pin);
878890
}
879891

880-
fixed_stages.push_back(fixed_stage);
892+
fixed_stages.push_back(std::move(fixed_stage));
881893
}
882894
return fixed_stages;
883895
}
@@ -1178,28 +1190,36 @@ void DelayEstimatorReporter::printStageWindowDetail(
11781190
const bool has_golden_before = row_index < golden_before.size();
11791191
const bool has_golden_after = row_index < golden_after.size();
11801192

1181-
const Role role = has_estimated_current ? estimated_current_row.role
1182-
: has_estimated_candidate ? estimated_candidate_row.role
1183-
: has_golden_before ? golden_before_row.role
1184-
: golden_after_row.role;
1185-
const int path_index
1186-
= has_estimated_current ? estimated_current_row.path_index
1187-
: has_estimated_candidate ? estimated_candidate_row.path_index
1188-
: has_golden_before ? golden_before_row.path_index
1189-
: golden_after_row.path_index;
1190-
const std::string& pin_name
1191-
= has_estimated_current ? estimated_current_row.pin_name
1192-
: has_estimated_candidate ? estimated_candidate_row.pin_name
1193-
: has_golden_before ? golden_before_row.pin_name
1194-
: golden_after_row.pin_name;
1195-
const std::string& pre_cell
1196-
= has_estimated_current ? estimated_current_row.cell_name
1197-
: has_golden_before ? golden_before_row.cell_name
1198-
: kDashCell;
1199-
const std::string& post_cell
1200-
= has_estimated_candidate ? estimated_candidate_row.cell_name
1201-
: has_golden_after ? golden_after_row.cell_name
1202-
: kDashCell;
1193+
const StageProfileRow* reference_row = &golden_after_row;
1194+
if (has_golden_before) {
1195+
reference_row = &golden_before_row;
1196+
}
1197+
if (has_estimated_candidate) {
1198+
reference_row = &estimated_candidate_row;
1199+
}
1200+
if (has_estimated_current) {
1201+
reference_row = &estimated_current_row;
1202+
}
1203+
1204+
const std::string* pre_cell = &kDashCell;
1205+
if (has_golden_before) {
1206+
pre_cell = &golden_before_row.cell_name;
1207+
}
1208+
if (has_estimated_current) {
1209+
pre_cell = &estimated_current_row.cell_name;
1210+
}
1211+
1212+
const std::string* post_cell = &kDashCell;
1213+
if (has_golden_after) {
1214+
post_cell = &golden_after_row.cell_name;
1215+
}
1216+
if (has_estimated_candidate) {
1217+
post_cell = &estimated_candidate_row.cell_name;
1218+
}
1219+
1220+
const Role role = reference_row->role;
1221+
const int path_index = reference_row->path_index;
1222+
const std::string& pin_name = reference_row->pin_name;
12031223

12041224
const float estimated_current_delay
12051225
= has_estimated_current
@@ -1281,8 +1301,8 @@ void DelayEstimatorReporter::printStageWindowDetail(
12811301
const bool post_arc_relaxed
12821302
= has_estimated_candidate && estimated_candidate_row.arc_match_relaxed;
12831303
logger_->report(" cell: pre={} post={}{}",
1284-
pre_cell,
1285-
post_cell,
1304+
*pre_cell,
1305+
*post_cell,
12861306
post_arc_relaxed ? " arc_match: relaxed" : "");
12871307
logger_->report("");
12881308
logger_->report(" {:<31} {:>10} {:>10} {:>10}",

src/rsz/src/RepairTargetCollector.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ std::vector<Target> RepairTargetCollector::collectCritPathDriverPinTargets(
936936
if (visited_pins.contains(pin) || !is_valid_target(pin)) {
937937
continue;
938938
}
939-
targets.push_back(target);
939+
targets.push_back(std::move(target));
940940
visited_pins.insert(pin);
941941
}
942942
}
@@ -1472,7 +1472,7 @@ vector<const sta::Pin*> RepairTargetCollector::collectViolatorsByFaninTraversal(
14721472
// Populate pin_data for sorting and filtering
14731473
pinData pd;
14741474
updatePinData(pin, pd);
1475-
pin_data_[pin] = pd;
1475+
pin_data_[pin] = std::move(pd);
14761476
}
14771477

14781478
int pins_before_filter = violating_pins_.size();
@@ -1631,7 +1631,7 @@ RepairTargetCollector::collectViolatorsByFanoutTraversal(
16311631
// Populate pin_data for sorting and filtering
16321632
pinData pd;
16331633
updatePinData(pin, pd);
1634-
pin_data_[pin] = pd;
1634+
pin_data_[pin] = std::move(pd);
16351635
}
16361636

16371637
int pins_before_filter = violating_pins_.size();
@@ -1785,7 +1785,7 @@ RepairTargetCollector::collectViolatorsByFaninTraversalForEndpoint(
17851785
// Populate pin_data for sorting and filtering
17861786
pinData pd;
17871787
updatePinData(pin, pd);
1788-
pin_data_[pin] = pd;
1788+
pin_data_[pin] = std::move(pd);
17891789
}
17901790

17911791
int pins_before_filter = violating_pins_.size();
@@ -2001,7 +2001,7 @@ sta::Slack RepairTargetCollector::computeAdaptiveThreshold(
20012001
delayAsString(chosen_threshold, 3, sta_),
20022002
pin_count,
20032003
cone_size,
2004-
cone_size > 0 ? 100.0 * pin_count / cone_size : 0.0);
2004+
100.0 * pin_count / cone_size);
20052005
} else {
20062006
chosen_threshold = -1e30;
20072007
logger_->info(RSZ,
@@ -2027,7 +2027,7 @@ void RepairTargetCollector::collectPinsWithThreshold(
20272027

20282028
pinData pd;
20292029
updatePinData(pin_slack_pair.first, pd);
2030-
pin_data_[pin_slack_pair.first] = pd;
2030+
pin_data_[pin_slack_pair.first] = std::move(pd);
20312031
}
20322032
}
20332033
}

src/rsz/src/move/RerouteGenerator.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ std::vector<std::unique_ptr<MoveCandidate>> RerouteGenerator::generate(
114114
const float resistance = global_router->getFRNetResistance(db_net);
115115
const float estimated_resistance
116116
= global_router->getFRNetResistanceOnMinClockLayer(db_net);
117-
const float reduction_ratio
118-
= (resistance > 0.0f) ? (resistance - estimated_resistance) / resistance
119-
: 0.0f;
117+
float reduction_ratio = 0.0f;
118+
if (resistance > 0.0f) {
119+
reduction_ratio = (resistance - estimated_resistance) / resistance;
120+
}
120121
if (reduction_ratio < kMinResistanceReduction) {
121122
debugPrint(resizer_.logger(),
122123
RSZ,

src/rsz/src/move/SizeDownGenerator.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,11 @@ float computeElmoreSlewFactor(const SizeDownContext& ctx,
271271
ctx.resizer.sta()->scenes(),
272272
ctx.resizer.maxAnalysisMode());
273273
const float output_res = output_port->driveResistance();
274-
return output_res > 0.0f && output_load_cap > 0.0f
275-
? slew / (output_res * output_load_cap)
276-
: 0.0f;
274+
if (output_res <= 0.0f || output_load_cap <= 0.0f) {
275+
return 0.0f;
276+
}
277+
const float elmore_denominator = output_res * output_load_cap;
278+
return slew / elmore_denominator;
277279
}
278280

279281
bool checkMaxSlewViolation(const SizeDownContext& ctx,

src/rsz/src/policy/SetupLastGaspPolicy.cc

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,21 @@
33

44
#include "SetupLastGaspPolicy.hh"
55

6-
#include <algorithm>
76
#include <cmath>
8-
#include <cstddef>
9-
#include <limits>
10-
#include <map>
11-
#include <queue>
12-
#include <set>
13-
#include <unordered_map>
14-
#include <unordered_set>
157
#include <utility>
168
#include <vector>
179

18-
#include "MoveCandidate.hh"
1910
#include "MoveCommitter.hh"
2011
#include "MoveGenerator.hh"
2112
#include "OptimizerTypes.hh"
2213
#include "RepairTargetCollector.hh"
23-
#include "VtSwapGenerator.hh"
2414
#include "est/EstimateParasitics.h"
2515
#include "policy/OptimizationPolicy.hh"
2616
#include "rsz/Resizer.hh"
2717
#include "sta/Delay.hh"
2818
#include "sta/Fuzzy.hh"
2919
#include "sta/GraphClass.hh"
30-
#include "sta/Network.hh"
31-
#include "sta/NetworkClass.hh"
3220
#include "sta/Path.hh"
33-
#include "sta/PortDirection.hh"
3421
#include "utl/Logger.h"
3522
#include "utl/timer.h"
3623

@@ -296,12 +283,11 @@ void SetupLastGaspPolicy::repairLastGaspEndpoint(
296283
acceptEndpointState(endpoint_state);
297284
break;
298285
}
299-
if (last_gasp_state.end_index == 1) {
286+
if (last_gasp_state.end_index == 1
287+
&& endpoint_state.worst_vertex != nullptr) {
300288
endpoint_state.end = endpoint_state.worst_vertex;
301-
if (endpoint_state.end != nullptr) {
302-
target_collector_->useWorstEndpoint(endpoint_state.end);
303-
committer_.setCurrentEndpoint(endpoint_state.end->pin());
304-
}
289+
target_collector_->useWorstEndpoint(endpoint_state.end);
290+
committer_.setCurrentEndpoint(endpoint_state.end->pin());
305291
}
306292

307293
++endpoint_state.pass;

src/rsz/src/policy/SetupLegacyBase.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55

66
#include <algorithm>
77
#include <cmath>
8-
#include <cstddef>
98
#include <cstdlib>
109
#include <limits>
11-
#include <map>
1210
#include <memory>
1311
#include <optional>
14-
#include <set>
1512
#include <string>
1613
#include <unordered_map>
1714
#include <unordered_set>
@@ -32,15 +29,13 @@
3229
#include "est/EstimateParasitics.h"
3330
#include "rsz/Resizer.hh"
3431
#include "sta/Delay.hh"
35-
#include "sta/Fuzzy.hh"
3632
#include "sta/Graph.hh"
3733
#include "sta/GraphClass.hh"
3834
#include "sta/Liberty.hh"
3935
#include "sta/Network.hh"
4036
#include "sta/NetworkClass.hh"
4137
#include "sta/Path.hh"
4238
#include "sta/PathExpanded.hh"
43-
#include "sta/PortDirection.hh"
4439
#include "sta/Sdc.hh"
4540
#include "sta/Search.hh"
4641
#include "sta/SearchClass.hh"
@@ -524,7 +519,7 @@ bool SetupLegacyBase::repairPins(
524519
driver_pin, focus_path, focus_slack, target)
525520
: makePinTarget(driver_pin, focus_slack, target);
526521
if (has_target) {
527-
prewarm_targets.push_back(target);
522+
prewarm_targets.push_back(std::move(target));
528523
}
529524
}
530525
prewarmTargets(prewarm_targets);
@@ -761,7 +756,7 @@ bool SetupLegacyBase::repairPath(sta::Path* path,
761756
static_cast<void>(ignored);
762757
Target target;
763758
makePathDriverTarget(path, expanded, drvr_index, path_slack, target);
764-
targets.push_back(target);
759+
targets.push_back(std::move(target));
765760
}
766761

767762
// Prewarm for legacy MT policy

0 commit comments

Comments
 (0)