Skip to content

Fix reference to temporary that has gone out of scope#8866

Merged
kroening merged 1 commit intodiffblue:developfrom
tautschnig:asan-fixes/temporary
Mar 16, 2026
Merged

Fix reference to temporary that has gone out of scope#8866
kroening merged 1 commit intodiffblue:developfrom
tautschnig:asan-fixes/temporary

Conversation

@tautschnig
Copy link
Collaborator

@tautschnig tautschnig commented Mar 15, 2026

Store language_mode by value instead of by reference in goto_symex_statet. The copy is cheap (irep_idt is an interned string index) and eliminates the dangling-reference problem at the root: the class now owns its data, so callers need not worry about the lifetime of the argument.

Co-authored-by: Kiro kiro-agent@users.noreply.github.com

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@tautschnig tautschnig self-assigned this Mar 15, 2026
Copilot AI review requested due to automatic review settings March 15, 2026 21:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes undefined behavior in unit tests caused by passing a temporary irep_idt{} into constructors that (directly or indirectly) store references, ensuring the referenced object outlives the constructed test fixtures.

Changes:

  • Introduce a named empty_language_mode variable to give the language-mode argument a stable lifetime.
  • Replace uses of irep_idt{} temporaries with the named variable in affected test constructions.

Reviewed changes

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

File Description
unit/goto-symex/symex_assign.cpp Avoids dangling reference by binding language-mode to a local variable reused across multiple constructions.
unit/goto-symex/goto_symex_state.cpp Same lifetime fix for goto_symex_statet construction in state unit test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.01%. Comparing base (eee45a7) to head (f279121).
⚠️ Report is 4 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8866   +/-   ##
========================================
  Coverage    80.00%   80.01%           
========================================
  Files         1703     1703           
  Lines       188397   188397           
  Branches        73       73           
========================================
+ Hits        150736   150742    +6     
+ Misses       37661    37655    -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kroening
Copy link
Collaborator

May I suggest changing the reference const irep_idt &language_mode in goto-symex/goto_symex_state.h to a copy instead. The copy is cheap.

Store language_mode by value instead of by reference in
goto_symex_statet. The copy is cheap (irep_idt is an interned string
index) and eliminates the dangling-reference problem at the root: the
class now owns its data, so callers need not worry about the lifetime
of the argument.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig
Copy link
Collaborator Author

May I suggest changing the reference const irep_idt &language_mode in goto-symex/goto_symex_state.h to a copy instead. The copy is cheap.

Thanks, done. Updated the commit & PR description accordingly.

@tautschnig tautschnig assigned kroening and unassigned tautschnig Mar 16, 2026
@kroening kroening merged commit 0baf3a8 into diffblue:develop Mar 16, 2026
41 checks passed
@tautschnig tautschnig deleted the asan-fixes/temporary branch March 16, 2026 19:22
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.

3 participants