Skip to content

Commit bf9c6e2

Browse files
RudolfWeeberclaude
andcommitted
core: satisfy clang-tidy static analysis on the migration branch
Zero-initialize the ghost PROPRTS archive locals (the analyzer cannot see through the archive operator& and flags the assignments as garbage), fold the RATTLE/BONDS accounting into a mutation-free assert (the masks were dead stores in release builds), and compile the GlueToSurface generation re-stamp only in debug builds (its only reader is the debug generation guard). Behavior unchanged; lj/p3m identity bitwise-identical. The clang-19 + ESPRESSO_BUILD_WITH_CLANG_TIDY configuration is what the ICP GitLab empty and clang-sanitizer jobs run and the previous local gates missed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 9d22cc5 commit bf9c6e2

2 files changed

Lines changed: 49 additions & 41 deletions

File tree

src/core/collision_detection/GlueToSurface.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ void GlueToSurface::handle_collisions(
206206
// re-resolve both base-particle views by id and re-stamp the generation.
207207
p1 = cell_structure.get_local_particle(pid1);
208208
p2 = cell_structure.get_local_particle(pid2);
209+
#ifndef NDEBUG
210+
// Re-stamp for the generation guard; its only reader is the debug
211+
// assert above, so the store would be dead code in release builds.
209212
resolved_generation = cell_structure.particle_store().generation();
213+
#endif
210214
current_vs_pid++;
211215
}
212216
// Create bond between the virtual particles

src/core/ghosts.cpp

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
337337
}
338338
#endif
339339
if (direction == SerializationDirection::LOAD) {
340-
int id, mol_id, type, propagation;
340+
int id = 0, mol_id = 0, type = 0, propagation = 0;
341341
ar & id & mol_id & type & propagation;
342342
if (use_ctx) {
343343
param_ctx->id[urow] = id;
@@ -351,7 +351,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
351351
p.propagation() = propagation;
352352
}
353353
} else {
354-
int id, mol_id, type, propagation;
354+
int id = 0, mol_id = 0, type = 0, propagation = 0;
355355
if (use_ctx) {
356356
id = param_ctx->id[urow];
357357
mol_id = param_ctx->mol_id[urow];
@@ -367,7 +367,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
367367
}
368368
#ifdef ESPRESSO_ROTATION
369369
if (direction == SerializationDirection::LOAD) {
370-
std::uint8_t rotation;
370+
std::uint8_t rotation = 0u;
371371
ar & rotation;
372372
if (use_ctx) {
373373
param_ctx->rotation[urow] = rotation;
@@ -381,7 +381,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
381381
}
382382
#ifdef ESPRESSO_ROTATIONAL_INERTIA
383383
if (direction == SerializationDirection::LOAD) {
384-
Utils::Vector3d rinertia;
384+
Utils::Vector3d rinertia{};
385385
ar & rinertia;
386386
if (use_ctx) {
387387
auto *r = param_ctx->rinertia + urow * param_ctx->rinertia_row_stride;
@@ -392,7 +392,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
392392
p.rinertia() = rinertia;
393393
}
394394
} else {
395-
Utils::Vector3d rinertia;
395+
Utils::Vector3d rinertia{};
396396
if (use_ctx) {
397397
auto const *r =
398398
param_ctx->rinertia + urow * param_ctx->rinertia_row_stride;
@@ -407,7 +407,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
407407
#endif
408408
#ifdef ESPRESSO_MASS
409409
if (direction == SerializationDirection::LOAD) {
410-
double mass;
410+
double mass = 0.;
411411
ar & mass;
412412
if (use_ctx) {
413413
param_ctx->mass[urow] = mass;
@@ -421,7 +421,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
421421
#endif
422422
#ifdef ESPRESSO_ELECTROSTATICS
423423
if (direction == SerializationDirection::LOAD) {
424-
double q;
424+
double q = 0.;
425425
ar & q;
426426
if (use_ctx) {
427427
param_ctx->q[urow] = q;
@@ -435,7 +435,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
435435
#endif
436436
#ifdef ESPRESSO_DIPOLES
437437
if (direction == SerializationDirection::LOAD) {
438-
double dipm;
438+
double dipm = 0.;
439439
ar & dipm;
440440
if (use_ctx) {
441441
param_ctx->dipm[urow] = dipm;
@@ -553,7 +553,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
553553
#endif
554554
#ifdef ESPRESSO_EXTERNAL_FORCES
555555
if (direction == SerializationDirection::LOAD) {
556-
std::uint8_t ext_flag;
556+
std::uint8_t ext_flag = 0u;
557557
ar & ext_flag;
558558
if (use_ctx) {
559559
param_ctx->ext_flag[urow] = ext_flag;
@@ -565,7 +565,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
565565
ar & ext_flag;
566566
}
567567
if (direction == SerializationDirection::LOAD) {
568-
Utils::Vector3d ext_force;
568+
Utils::Vector3d ext_force{};
569569
ar & ext_force;
570570
if (use_ctx) {
571571
auto *f = param_ctx->ext_force + urow * param_ctx->ext_force_row_stride;
@@ -576,7 +576,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
576576
p.ext_force() = ext_force;
577577
}
578578
} else {
579-
Utils::Vector3d ext_force;
579+
Utils::Vector3d ext_force{};
580580
if (use_ctx) {
581581
auto const *f =
582582
param_ctx->ext_force + urow * param_ctx->ext_force_row_stride;
@@ -589,7 +589,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
589589
}
590590
#ifdef ESPRESSO_ROTATION
591591
if (direction == SerializationDirection::LOAD) {
592-
Utils::Vector3d ext_torque;
592+
Utils::Vector3d ext_torque{};
593593
ar & ext_torque;
594594
if (use_ctx) {
595595
auto *t =
@@ -601,7 +601,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
601601
p.ext_torque() = ext_torque;
602602
}
603603
} else {
604-
Utils::Vector3d ext_torque;
604+
Utils::Vector3d ext_torque{};
605605
if (use_ctx) {
606606
auto const *t =
607607
param_ctx->ext_torque + urow * param_ctx->ext_torque_row_stride;
@@ -660,7 +660,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
660660
}
661661
#endif
662662
if (direction == SerializationDirection::LOAD) {
663-
Utils::Vector3d position;
663+
Utils::Vector3d position{};
664664
Utils::Vector3i image_box;
665665
ar & position;
666666
ar & image_box;
@@ -680,7 +680,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
680680
p.image_box() = image_box;
681681
}
682682
} else {
683-
Utils::Vector3d position;
683+
Utils::Vector3d position{};
684684
Utils::Vector3i image_box;
685685
if (use_ctx) {
686686
auto const *pos = pos_ctx->pos + static_cast<std::size_t>(row) *
@@ -707,7 +707,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
707707
}
708708
#ifdef ESPRESSO_ROTATION
709709
if (direction == SerializationDirection::LOAD) {
710-
Utils::Quaternion<double> quat;
710+
Utils::Quaternion<double> quat{};
711711
ar & quat;
712712
if (use_ctx) {
713713
auto *q = pos_ctx->quat +
@@ -720,7 +720,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
720720
p.quat() = quat;
721721
}
722722
} else {
723-
Utils::Quaternion<double> quat;
723+
Utils::Quaternion<double> quat{};
724724
if (use_ctx) {
725725
auto const *q = pos_ctx->quat + static_cast<std::size_t>(row) *
726726
pos_ctx->quat_row_stride;
@@ -736,7 +736,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
736736
#endif
737737
#ifdef ESPRESSO_BOND_CONSTRAINT
738738
if (direction == SerializationDirection::LOAD) {
739-
Utils::Vector3d pos_last_time_step;
739+
Utils::Vector3d pos_last_time_step{};
740740
ar & pos_last_time_step;
741741
if (use_ctx) {
742742
auto *pl = pos_ctx->plast +
@@ -748,7 +748,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
748748
p.pos_last_time_step() = pos_last_time_step;
749749
}
750750
} else {
751-
Utils::Vector3d pos_last_time_step;
751+
Utils::Vector3d pos_last_time_step{};
752752
if (use_ctx) {
753753
auto const *pl = pos_ctx->plast + static_cast<std::size_t>(row) *
754754
pos_ctx->plast_row_stride;
@@ -797,7 +797,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
797797
}
798798
#endif
799799
if (direction == SerializationDirection::LOAD) {
800-
Utils::Vector3d velocity;
800+
Utils::Vector3d velocity{};
801801
ar & velocity;
802802
if (use_ctx) {
803803
auto *v = mom_ctx->vel +
@@ -809,7 +809,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
809809
p.v() = velocity;
810810
}
811811
} else {
812-
Utils::Vector3d velocity;
812+
Utils::Vector3d velocity{};
813813
if (use_ctx) {
814814
auto const *v = mom_ctx->vel +
815815
static_cast<std::size_t>(row) * mom_ctx->vel_row_stride;
@@ -823,7 +823,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
823823
}
824824
#ifdef ESPRESSO_ROTATION
825825
if (direction == SerializationDirection::LOAD) {
826-
Utils::Vector3d angular_velocity;
826+
Utils::Vector3d angular_velocity{};
827827
ar & angular_velocity;
828828
if (use_ctx) {
829829
auto *w = mom_ctx->omega +
@@ -835,7 +835,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
835835
p.omega() = angular_velocity;
836836
}
837837
} else {
838-
Utils::Vector3d angular_velocity;
838+
Utils::Vector3d angular_velocity{};
839839
if (use_ctx) {
840840
auto const *w = mom_ctx->omega + static_cast<std::size_t>(row) *
841841
mom_ctx->omega_row_stride;
@@ -851,7 +851,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
851851
}
852852
if (data_parts & GHOSTTRANS_FORCE) {
853853
if (direction == SerializationDirection::LOAD) {
854-
Utils::Vector3d force;
854+
Utils::Vector3d force{};
855855
ar & force;
856856
if (policy == ReductionPolicy::UPDATE) {
857857
p.force() += force;
@@ -864,7 +864,7 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
864864
}
865865
#ifdef ESPRESSO_ROTATION
866866
if (direction == SerializationDirection::LOAD) {
867-
Utils::Vector3d torque;
867+
Utils::Vector3d torque{};
868868
ar & torque;
869869
if (policy == ReductionPolicy::UPDATE) {
870870
p.torque() += torque;
@@ -886,11 +886,11 @@ serialize_and_reduce(Archive &ar, Particle &p, unsigned int data_parts,
886886
// byte-identical to the previous implementation.
887887
if (policy == ReductionPolicy::UPDATE and
888888
direction == SerializationDirection::LOAD) {
889-
Utils::Vector3d correction;
889+
Utils::Vector3d correction{};
890890
ar & correction;
891891
p.rattle_correction() += correction;
892892
} else if (direction == SerializationDirection::LOAD) {
893-
Utils::Vector3d correction;
893+
Utils::Vector3d correction{};
894894
ar & correction;
895895
p.rattle_correction() = correction;
896896
} else {
@@ -1612,19 +1612,23 @@ static auto calc_transmit_size(BoxGeometry const &box_geo,
16121612
#ifdef ESPRESSO_BOND_CONSTRAINT
16131613
if (data_parts & GHOSTTRANS_RATTLE) {
16141614
rattle_size = 3ul * sizeof(double);
1615-
data_parts &= ~static_cast<unsigned>(GHOSTTRANS_RATTLE);
16161615
}
16171616
#endif
1618-
/* GHOSTTRANS_BONDS contributes ZERO bytes to the main transfer buffer: the
1619-
* bond payload travels in the dedicated ragged bond buffer
1620-
* (CommBuf::bondbuf), which is sized at pack time. A communicator's
1621-
* data_parts legitimately carries the BONDS bit through here (e.g. the
1622-
* exchange communicator when bonded interactions and a thermostat are
1623-
* active), so mask it to keep the accounting assert below meaningful for
1624-
* genuinely unhandled parts. Caught by the Debug-with-asserts checkpoint
1625-
* tests on 4 MPI ranks (upstream fedora CI). */
1626-
data_parts &= ~static_cast<unsigned>(GHOSTTRANS_BONDS);
1627-
assert(data_parts == 0u);
1617+
/* Accounting check: every part must be handled above or contribute zero
1618+
* bytes to the main transfer buffer. GHOSTTRANS_BONDS is tolerated because
1619+
* the bond payload travels in the dedicated ragged bond buffer
1620+
* (CommBuf::bondbuf), sized at pack time; a communicator's data_parts
1621+
* legitimately carries the BONDS bit (e.g. the exchange communicator when
1622+
* bonded interactions and a thermostat are active) -- caught by the
1623+
* Debug-with-asserts checkpoint tests on 4 MPI ranks (upstream fedora CI).
1624+
* RATTLE is tolerated only when its ifdef branch above accounts for it. */
1625+
[[maybe_unused]] constexpr auto tolerated_parts =
1626+
static_cast<unsigned>(GHOSTTRANS_BONDS)
1627+
#ifdef ESPRESSO_BOND_CONSTRAINT
1628+
| static_cast<unsigned>(GHOSTTRANS_RATTLE)
1629+
#endif
1630+
;
1631+
assert((data_parts & ~tolerated_parts) == 0u);
16281632
return properties_size + force_size + position_size + momentum_size +
16291633
rattle_size;
16301634
}
@@ -1876,7 +1880,7 @@ add_rattle_correction_from_recv_buffer(CommBuf &recv_buffer,
18761880
// wire carries one Utils::Vector3d (byte-identical to the previous
18771881
// ParticleRattle payload, which held only the correction Vector3d).
18781882
// Reduce it into the local column through the accessor.
1879-
Utils::Vector3d correction;
1883+
Utils::Vector3d correction{};
18801884
archiver >> correction;
18811885
part.rattle_correction() += correction;
18821886
}
@@ -1922,11 +1926,11 @@ static void add_forces_from_recv_buffer(CommBuf &recv_buffer,
19221926
auto archiver = Utils::MemcpyIArchive{recv_buffer.make_span()};
19231927
for (auto &part_list : ghost_comm.part_lists) {
19241928
for (Particle &part : part_list->particles()) {
1925-
Utils::Vector3d force;
1929+
Utils::Vector3d force{};
19261930
archiver >> force;
19271931
part.force() += force;
19281932
#ifdef ESPRESSO_ROTATION
1929-
Utils::Vector3d torque;
1933+
Utils::Vector3d torque{};
19301934
archiver >> torque;
19311935
part.torque() += torque;
19321936
#endif

0 commit comments

Comments
 (0)