Skip to content

Add missing type unrollings #1677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 4, 2025
Merged

Add missing type unrollings #1677

merged 22 commits into from
Mar 4, 2025

Conversation

sim642
Copy link
Member

@sim642 sim642 commented Feb 12, 2025

Closes #1600. I once started working on it, but never completed it.

PR #1676 independently found two places with missing type unrolling (which are also among the ones found here) that have clear impact on precision. Thus, it would be a good idea to more systematically fix the issue as a preventative measure.

Currently this PR is mostly a scattering of TODOs that still need to be looked at.

@sim642 sim642 added cleanup Refactoring, clean-up precision labels Feb 12, 2025
@sim642 sim642 self-assigned this Feb 12, 2025
@michael-schwarz
Copy link
Member

Are there any circumstances under which unrolling might be the wrong thing to do?

@sim642
Copy link
Member Author

sim642 commented Feb 13, 2025

Are there any circumstances under which unrolling might be the wrong thing to do?

Yes, some places actually want to match TNamed and use the typedef name. For example, mutex types are recognized like this (instead of looking at the internal struct that they happen to be).
So this cannot be done blindly.

@sim642 sim642 marked this pull request as ready for review February 24, 2025 16:50
@sim642 sim642 added this to the v2.6.0 milestone Feb 24, 2025
Copy link
Member

@michael-schwarz michael-schwarz left a comment

Choose a reason for hiding this comment

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

Thanks for putting all this effort into this! I left some comments here and there.

Comment on lines 2035 to 2038
if Cil.isVoidType t_override then (
M.warn ~category:M.Category.Program "Returning a value from a void function";
assert false
);
Copy link
Member

Choose a reason for hiding this comment

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

This is unrelated to the main topic of this PR, but doesn't the assert false cause the program to crash, and the warning before to never be printed? Does not seem to make much sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

That might be true indeed if we aren't doing early warnings or such. I'll think about it and perhaps turn it into logging/failwith.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just tried triggering this case and couldn't even do it. Apparently CIL already covers it here: https://github.com/goblint/cil/blob/f5ee39bd344dc74e2a10e407d877e0ddf73c9c6f/src/frontc/cabs2cil.ml#L6840-L6843. I think we don't show the CIL warning but CIL removes the returned expression anyway, so Goblint never sees it.

I'll change this to a plain assert without a more specific message because this shouldn't even be triggerable by the user.

@@ -311,6 +311,7 @@ class addTypeAttributeVisitor = object

(*Set arrays with important types for thread analysis to unroll*)
method! vtype typ =
(* TODO: reuse predicates in Access module (also handles TNamed correctly) *)
Copy link
Member

Choose a reason for hiding this comment

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

Should we not do this rather than leave new TODOs in the code base?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now the ones in Access aren't directly suitable for reuse here: what Access considers ignorable isn't exactly what unrolling considers important (e.g. FILE, jmp_buf, etc).

I think this needs a bit bigger refactoring. In particular, what I'd like to have is something like LibraryTypes (but initially at least less DSLy than LibraryFunctions). These are currently unconditional everywhere, but they should also be controlled by lib.activated.
I think recently @karoliineh found something in sv-benchmarks where our Linux kernel-specific overrides trigger on LDV tasks because they use the same names, but actually have stub implementations different from the kernel's. In the specific case we were perhaps imprecise because of it (?) but this is actually accidental task fingerprinting.

@sim642 sim642 requested a review from michael-schwarz March 4, 2025 07:08
@sim642 sim642 merged commit db16544 into master Mar 4, 2025
21 checks passed
@sim642 sim642 deleted the unrolltype branch March 4, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Refactoring, clean-up precision
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Audit for missing type unrollings
2 participants