Skip to content

Function pointer removal: give candidate functions a source location - #9626

Draft
tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/function-pointer-removal-source-location
Draft

tautschnig wants to merge 1 commit into
diffblue:developfrom
tautschnig:kiro/function-pointer-removal-source-location

Conversation

@tautschnig

Copy link
Copy Markdown
Collaborator

goto-instrument --remove-function-pointers and --value-set-fi-fp-removal followed by cbmc failed with an invariant violation when cbmc added the C library ("front-ends should construct symbol expressions with source locations", casting_replace_symbol.cpp), as soon as one of the candidate functions of a removed call is defined by the library, for example malloc called through a function pointer.

Worst-case removal (remove_function_pointerst::remove_function_pointer, also run by --value-set-fi-fp-removal for calls whose value set has no function) builds the candidates as symbol_exprt{name, type}, without a source location, and remove_function_pointer() uses them for the new call and comparison. Linking the library replaces each use of a function the library defines (finalize_linking), and casting_replace_symbolt requires these symbol expressions to have a location. cbmc itself removes function pointers only after adding the library, so it did not run into this.

Give each candidate the source location of the call it replaces, as the front end does for a function designator, in remove_function_pointer(), which all ways of removing function pointers use. This also makes the locations of candidates found by the value-set analysis independent of which use of the function the analysis recorded first.

Found on goto programs of libxml2, which calls malloc, realloc and free through the function pointers xmlMalloc, xmlRealloc and xmlFree.

  • 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.

goto-instrument --remove-function-pointers and --value-set-fi-fp-removal
followed by cbmc failed with an invariant violation when cbmc added the C
library ("front-ends should construct symbol expressions with source
locations", casting_replace_symbol.cpp), as soon as one of the candidate
functions of a removed call is defined by the library, for example malloc
called through a function pointer.

Worst-case removal (remove_function_pointerst::remove_function_pointer,
also run by --value-set-fi-fp-removal for calls whose value set has no
function) builds the candidates as symbol_exprt{name, type}, without a
source location, and remove_function_pointer() uses them for the new call
and comparison. Linking the library replaces each use of a function the
library defines (finalize_linking), and casting_replace_symbolt requires
these symbol expressions to have a location. cbmc itself removes function
pointers only after adding the library, so it did not run into this.

Give each candidate the source location of the call it replaces, as the
front end does for a function designator, in remove_function_pointer(),
which all ways of removing function pointers use. This also makes the
locations of candidates found by the value-set analysis independent of
which use of the function the analysis recorded first.

Found on goto programs of libxml2, which calls malloc, realloc and free
through the function pointers xmlMalloc, xmlRealloc and xmlFree.

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

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.34%. Comparing base (3e1f386) to head (d8cdbd0).
⚠️ Report is 36 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9626      +/-   ##
===========================================
+ Coverage    81.29%   81.34%   +0.04%     
===========================================
  Files         1725     1727       +2     
  Lines       191680   191717      +37     
  Branches        73       73              
===========================================
+ Hits        155835   155950     +115     
+ Misses       35845    35767      -78     

☔ View full report in Codecov by Harness.
📢 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.

This branch has not been deployed

No deployments
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.

1 participant