Internals: Favor std::swap. No functional change.

This commit is contained in:
Wilson Snyder 2026-03-29 20:33:06 -04:00
parent 5036af3d37
commit 600eb7ec86
7 changed files with 12 additions and 34 deletions

View File

@ -1482,11 +1482,7 @@ public:
~VNumRange() = default;
// MEMBERS
void init(int hi, int lo, bool ascending) {
if (lo > hi) {
const int t = hi;
hi = lo;
lo = t;
}
if (lo > hi) std::swap(hi, lo);
m_left = ascending ? lo : hi;
m_right = ascending ? hi : lo;
m_ranged = true;

View File

@ -1185,11 +1185,7 @@ class WidthVisitor final : public VNVisitor {
if (const AstUnpackArrayDType* const adtypep = VN_CAST(fromDtp, UnpackArrayDType)) {
frommsb = adtypep->hi();
fromlsb = adtypep->lo();
if (fromlsb > frommsb) {
const int t = frommsb;
frommsb = fromlsb;
fromlsb = t;
}
if (fromlsb > frommsb) std::swap(frommsb, fromlsb);
// However, if the lsb<0 we may go negative, so need more bits!
if (fromlsb < 0) frommsb += -fromlsb;
nodep->dtypeFrom(adtypep->subDTypep()); // Need to strip off array reference

View File

@ -448,21 +448,15 @@ class WidthSelVisitor final : public VNVisitor {
adtypep,
"Array extraction with width miscomputed " << adtypep->width() << "/"
<< fromRange.elements());
if (fromRange.ascending()) {
// Below code assumes descending bit range; just works out if we swap
const int x = msb;
msb = lsb;
lsb = x;
}
// Below code assumes descending bit range; just works out if we swap
if (fromRange.ascending()) std::swap(msb, lsb);
if (lsb > msb) {
nodep->v3warn(
SELRANGE,
"[" << msb << ":" << lsb
<< "] Slice range has ascending bit ordering, perhaps you wanted [" << lsb
<< ":" << msb << "]");
const int x = msb;
msb = lsb;
lsb = x;
std::swap(msb, lsb);
}
const int elwidth = adtypep->width() / fromRange.elements();
AstSel* const newp
@ -477,21 +471,15 @@ class WidthSelVisitor final : public VNVisitor {
nodep->replaceWith(newp);
VL_DO_DANGLING(pushDeletep(nodep), nodep);
} else if (VN_IS(ddtypep, BasicDType)) {
if (fromRange.ascending()) {
// Below code assumes descending bit range; just works out if we swap
const int x = msb;
msb = lsb;
lsb = x;
}
// Below code assumes descending bit range; just works out if we swap
if (fromRange.ascending()) std::swap(msb, lsb);
if (lsb > msb) {
nodep->v3warn(
SELRANGE,
"[" << msb << ":" << lsb
<< "] Slice range has ascending bit ordering, perhaps you wanted [" << lsb
<< ":" << msb << "]");
const int x = msb;
msb = lsb;
lsb = x;
std::swap(msb, lsb);
}
AstSel* const newp = new AstSel{nodep->fileline(), fromp, newSubLsbOf(lsbp, fromRange),
msb + 1 - lsb};
@ -508,9 +496,7 @@ class WidthSelVisitor final : public VNVisitor {
"[" << msb << ":" << lsb
<< "] Slice range has ascending bit ordering, perhaps you wanted [" << lsb
<< ":" << msb << "]");
const int x = msb;
msb = lsb;
lsb = x;
std::swap(msb, lsb);
}
AstSel* const newp = new AstSel{nodep->fileline(), fromp, newSubLsbOf(lsbp, fromRange),
msb + 1 - lsb};

View File

@ -1,5 +1,5 @@
%Warning-SELRANGE: t/t_param_sel_range.v:41:33: Selection index out of range: 7:7 outside 4:0
: ... note: In instance 't.u2'
%Warning-SELRANGE: t/t_param_sel_range1.v:41:33: Selection index out of range: 7:7 outside 4:0
: ... note: In instance 't.u2'
41 | else r_rst[i] <= r_rst[i-1];
| ^
... For warning description see https://verilator.org/warn/SELRANGE?v=latest

View File

@ -10,7 +10,7 @@
import vltest_bootstrap
test.scenarios('linter')
test.top_filename = "t/t_param_sel_range.v"
test.top_filename = "t/t_param_sel_range1.v"
test.lint(fails=True, expect_filename=test.golden_filename)