Skip to content

Consider Calloc and Realloc for autotuners#2038

Merged
sim642 merged 4 commits into
masterfrom
lib-alloc-match
May 22, 2026
Merged

Consider Calloc and Realloc for autotuners#2038
sim642 merged 4 commits into
masterfrom
lib-alloc-match

Conversation

@sim642

@sim642 sim642 commented May 19, 2026

Copy link
Copy Markdown
Member

While debugging #2030 (comment) I noticed that the mallocWrappers autotuner doesn't pick up on the wrapper of calloc. Despite the name, it makes sense to do so (and with realloc). The mallocWrapper analysis also already considers them.

After reviewing all pattern matchings for these allocation kinds, I also found the same being missing from the allocation loop unrolling autotuner.

TODO

  • sv-benchmarks

@sim642 sim642 added this to the SV-COMP 2027 milestone May 19, 2026
@sim642 sim642 self-assigned this May 19, 2026
Copilot AI review requested due to automatic review settings May 19, 2026 14:47
@sim642 sim642 added cleanup Refactoring, clean-up bug sv-comp SV-COMP (analyses, results), witnesses labels May 19, 2026
Comment thread src/analyses/c2poAnalysis.ml Outdated

Copilot AI 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.

Pull request overview

This PR updates Goblint’s autotuning heuristics so they treat calloc and realloc similarly to malloc, aligning the autotuners with existing allocation-kind handling in the malloc-wrapper analysis.

Changes:

  • Extend the “allocations-in-loops” autotuner to also detect calloc/realloc calls inside loops.
  • Extend the malloc-wrapper autotuner to recognize wrappers around calloc/realloc in addition to malloc (by reusing wrapper-function classification logic).
  • Add a clarifying TODO comment in c2poAnalysis about missing realloc handling.

Reviewed changes

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

File Description
src/autoTune.ml Autotuners now consider Calloc/Realloc for loop allocation detection and malloc-wrapper detection.
src/analyses/wrapperFunctionAnalysis.ml Exposes wrapper-classification plumbing to enable reuse by autotuners.
src/analyses/c2poAnalysis.ml Comment-only change noting a potential missing Realloc case.

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

Comment thread src/autoTune.ml
Comment thread src/autoTune.ml
Comment thread src/analyses/wrapperFunctionAnalysis.ml
@sim642

sim642 commented May 21, 2026

Copy link
Copy Markdown
Member Author

On sv-benchmarks with level01, 60s and 1GB this already has interesting effects: https://goblint.cs.ut.ee/results/340-all-level01-pr-2038-after/table-generator-cmp.diff.html#/table?filter=0(0*status*(status(notIn(FAILED)),category(notIn()))).
To summarize:

  • 8 trues go to timeout/OOM
  • 10 timeouts/OOMs go to true, most by significant margin
  • 3 unknowns go to true
    • 1 of them is unsound, which suggests an underlying issue because more malloc wrappers should not have that effect on its own.

@michael-schwarz michael-schwarz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks reasonable!

@sim642

sim642 commented May 21, 2026

Copy link
Copy Markdown
Member Author
  • 1 of them is unsound, which suggests an underlying issue because more malloc wrappers should not have that effect on its own.

I looked into it and according to manual inspection the branches that became dead due to this change seemed to actually be dead. I then looked at SV-COMP 2026 results and found out that the task was invalidated. Turns out Mopsa already had an issue with this:
https://gitlab.com/sosy-lab/benchmarking/sv-benchmarks/-/blob/a45aa8f2eae1325c6c555c945ea721c023dde6f3/c/ldv-linux-4.2-rc1/linux-4.2-rc1.tar.xz-32_7a-drivers--pcmcia--pcmcia_rsrc.ko-entry_point.cil.out.yml. Apparently, I never updated sv-benchmarks on our server. So there should be no actual problem in Goblint.

@sim642 sim642 merged commit 27ef455 into master May 22, 2026
16 of 19 checks passed
@sim642 sim642 deleted the lib-alloc-match branch May 22, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug cleanup Refactoring, clean-up sv-comp SV-COMP (analyses, results), witnesses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants