Skip to content

Fixed issues with use-after-move - #1014

Merged
volkm merged 4 commits into
stormchecker:masterfrom
volkm:lint-bugprone-fixes
Aug 17, 2026
Merged

Fixed issues with use-after-move#1014
volkm merged 4 commits into
stormchecker:masterfrom
volkm:lint-bugprone-fixes

Conversation

@volkm

@volkm volkm commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Revealed by clang-tidy with bugprone-use-after-move.

Also enabled some more warnings (which are already satisfied on the code base) and fixed clang-tidy scripts such that relative paths are handled correctly now.


// Get the solver object and satisfy requirements
// The solver consumes the matrix, so the acyclic check must be performed before moving it.
bool const hasCycles = storm::utility::graph::hasCycle(sccMatrix);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is now always performed. Is this an acceptable performance impact? Or do you have a better suggestion how to handle this part?

}
if (!choiceRewardsJson.empty()) {
choiceRewardsJson["rew"] = std::move(choiceRewardsJson);
choiceJson["rew"] = std::move(choiceRewardsJson);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was incorrect before, but I guess the function was seldom used.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR addresses clang-tidy’s bugprone-use-after-move findings, enables additional clang-tidy bugprone checks, and improves the clang-tidy script so file selection works reliably with relative paths.

Changes:

  • Fixes multiple use-after-move patterns by capturing goal/config values before std::move, and by restructuring JSON construction to avoid self-move / moved-from reuse.
  • Enables additional bugprone-* clang-tidy checks in .clang-tidy.
  • Updates resources/scripts/clang-tidy.sh to correctly handle relative paths (cwd vs repo-root) and normalize paths for compilation database matching.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/test/storm/modelchecker/prctl/dtmc/DtmcPrctlModelCheckerTest.cpp Adjusts test setup to avoid moving an already-consumed SolveGoal.
src/storm/storage/valuations/ValuationsStorage.cpp Fixes assertions/logging to reference the actual stored members (this->strings, this->valuations).
src/storm/storage/memorystructure/SparseModelMemoryProduct.cpp Uses components.transitionMatrix for row-grouping check (fixing incorrect variable usage).
src/storm/storage/jani/visitor/JSONExporter.cpp Reworks array-access JSON building to avoid use-after-move of the intermediate JSON object.
src/storm/models/sparse/StochasticTwoPlayerGame.cpp Adds suppression and comment for clang-tidy use-after-move warning in ctor init list.
src/storm/models/sparse/Smg.cpp Adds suppression blocks for use-after-move warning due to base ctor consuming only part of components.
src/storm/models/sparse/Model.cpp Fixes a self-move bug when attaching rewards JSON to a choice JSON object.
src/storm/models/sparse/MarkovAutomaton.cpp Adds suppression blocks for use-after-move warning in ctor.
src/storm/models/sparse/Ctmc.cpp Adds suppression blocks for use-after-move warning in ctor.
src/storm/modelchecker/prctl/helper/SparseMdpPrctlHelper.cpp Captures goal-derived settings before moving goal; refactors scheduler extension API to avoid goal access post-move.
src/storm/modelchecker/prctl/helper/SparseDtmcPrctlHelper.cpp Captures uncertainty mode before moving goal.
src/storm/modelchecker/helper/indefinitehorizon/visitingtimes/SparseDeterministicVisitingTimesHelper.cpp Avoids using a moved matrix by computing cycle info before moving it to the solver.
src/storm-pars/modelchecker/region/monotonicity/MonotonicityResult.cpp Removes pointless std::move of enum values and avoids map access patterns that can be problematic after moves.
src/storm-dft/generator/DftNextStateGenerator.cpp Ensures a fresh choice object is used after adding a choice (avoids reusing moved-from state).
resources/scripts/clang-tidy.sh Fixes file selection behavior for relative paths and normalizes absolute paths to match compilation DB entries.
.clang-tidy Enables additional bugprone-* checks.
Suppressed comments (1)

src/storm/models/sparse/Ctmc.cpp:1

  • Same pattern as other model ctors: accessing components after moving it into the base ctor and suppressing the diagnostic. This is fragile if the base ctor’s implementation changes. Consider refactoring to avoid moved-from access (split derived-only fields from base-relevant fields) so this does not rely on undocumented consumption semantics, and/or narrow the suppression scope.
#include "storm/models/sparse/Ctmc.h"

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +40 to +42
: NondeterministicModel<ValueType, RewardModelType>(ModelType::S2pg, std::move(components)),
// NOLINTNEXTLINE(bugprone-use-after-move) The base constructor only consumes the base-relevant fields of components.
player1Matrix(std::move(components.player1Matrix.get())) {
Comment on lines +26 to +32
// NOLINTBEGIN(bugprone-use-after-move) The base constructor only consumes the base-relevant fields of components.
statePlayerIndications(std::move(components.statePlayerIndications.get())) {
if (components.playerNameToIndexMap) {
playerNameToIndexMap = std::move(components.playerNameToIndexMap.get());
}
// Otherwise the map remains empty.
// NOLINTEND(bugprone-use-after-move)
Comment on lines 52 to +63
@@ -59,6 +60,7 @@ MarkovAutomaton<ValueType, RewardModelType>::MarkovAutomaton(storm::storage::spa
if (components.rateTransitions) {
this->turnRatesToProbabilities();
}
// NOLINTEND(bugprone-use-after-move)
Comment on lines +474 to 476
// The solver consumes the matrix, so the acyclic check must be performed before moving it.
bool const hasCycles = storm::utility::graph::hasCycle(sccMatrix);
auto solver = linearEquationSolverFactory.create(env, std::move(sccMatrix));
if (req.acyclic().isCritical()) {
STORM_LOG_THROW(!storm::utility::graph::hasCycle(sccMatrix), storm::exceptions::UnmetRequirementException,
"The solver requires an acyclic model, but the model is not acyclic.");
STORM_LOG_THROW(!hasCycles, storm::exceptions::UnmetRequirementException, "The solver requires an acyclic model, but the model is not acyclic.");
@sjunges

sjunges commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

LGTM.

@volkm

volkm commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

The review comments by copilot are things I deliberately did not address. Splitting the components in the constructors would make the code unnecessarily complicated in my view. But if you have a good idea, I am happy to make changes.

@tquatmann Is the performance impact in SparseDeterministicVisitingTimesHelper okay?

@sjunges

sjunges commented Aug 15, 2026 via email

Copy link
Copy Markdown
Contributor

@tquatmann tquatmann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fixes! Thanks! The visiting times overhead can be avoided, see my suggestion :)

@volkm
volkm merged commit d0344cb into stormchecker:master Aug 17, 2026
23 of 24 checks passed
@volkm
volkm deleted the lint-bugprone-fixes branch August 17, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants