Skip to content
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

Support quantifiers in ACSL #704

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open

Support quantifiers in ACSL #704

wants to merge 6 commits into from

Conversation

schuessf
Copy link
Contributor

@schuessf schuessf commented Jan 7, 2025

This PR adds support for quantifiers in ACSL.

  • We already had some rules in our grammar to parse quantifiers. These rules just always yielded a NotDefinedExpression. There was also a AST object for a QuantifierExpression that I just adapted to our needs.
  • To translate quantifiers from ACSL to Boogie, I added a new method to ACSLHandler. The crucial steps in this translation are that we have to handle the quantified variables in the expression inside the quantifier properly (track the variables in a ScopedHashMap and first lookup when handling an IdentifierExpression) and that we add type constraints over the quantified variables (ACSL may use bounded types that are translated to an unbounded type in Boogie).

Note that we can only handle quantified expressions, where the inner expressions is side-effect free (which also does not allow any auxiliary statements). Therefore, quantified expressions that contain dereferences are currently not supported, but this should be fixed in #703.

Copy link
Contributor

@maul-esel maul-esel 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 taking care of this. Looks good to me, I've only left some smaller comments.

Could you maybe add some small test cases? (maybe some using verification/Automizer and some for Referee?)

final CType cType = AcslTypeUtils.translateAcslTypeToCType(decl.getType());
final DeclarationInformation declInfo = new DeclarationInformation(StorageClass.QUANTIFIED, null);
final BoogieType boogieType = mTypeHandler.getBoogieTypeForCType(cType);
// TODO: Handle quantified variables on heap
Copy link
Contributor

Choose a reason for hiding this comment

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

What exactly does this mean, and what would have to be done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I don't know 😄
This wold happen, if we quantify over pointers and I am not sure about the ACSL semantics in that case.
Also, I don't think we support pointer types in ACSL properly, so we would probably crash earlier.
So maybe I can just replace the TODO with a comment that we don't support pointers for now and thus yield a LocalLValue.

Copy link
Member

Choose a reason for hiding this comment

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

I am also confused what "quantified variables on heap" means. Is this a quantified pointer?
But I agree, that sounds rather difficult. Perhaps we should crash as soon as we encounter it, i.e., throw UnsupportedSyntax .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just replaced this TODO with an exception. I don't think it can be triggered for now, as we already crash before for non-primitive types (definitely in AcslTypeUtils::translateAcslTypeToCType, maybe already during parsing). But this may change in the future and the thrown exception also serves as some form of documentation.

@schuessf
Copy link
Contributor Author

schuessf commented Jan 7, 2025

Regarding the test cases: I wanted to wait for #703 to write some tests with quantifiers over arrays, but I will just add some simple tests to demonstrate the basic functionality,

final CType cType = AcslTypeUtils.translateAcslTypeToCType(decl.getType());
final DeclarationInformation declInfo = new DeclarationInformation(StorageClass.QUANTIFIED, null);
final BoogieType boogieType = mTypeHandler.getBoogieTypeForCType(cType);
// TODO: Handle quantified variables on heap
Copy link
Member

Choose a reason for hiding this comment

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

I am also confused what "quantified variables on heap" means. Is this a quantified pointer?
But I agree, that sounds rather difficult. Perhaps we should crash as soon as we encounter it, i.e., throw UnsupportedSyntax .

@schuessf schuessf force-pushed the wip/fs/acsl-quantifiers branch 2 times, most recently from ca48b46 to d288eb8 Compare January 8, 2025 13:33
@@ -121,7 +121,7 @@ public enum RedirectionStrategy {
public static final boolean DEF_USESEPARATETRACECHECKSOLVER = true;
public static final SolverMode DEF_CHOOSESEPARATETRACECHECKSOLVER = SolverMode.Internal_SMTInterpol;
public static final String DEF_SEPARATETRACECHECKSOLVERCOMMAND = "";
public static final String DEF_SEPARATETRACECHECKSOLVERTHEORY = "QF_AUFLIA";
public static final String DEF_SEPARATETRACECHECKSOLVERTHEORY = "ALL";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really intended to change the default setting here? If so, are there any settings files that also need to be adapted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In all the relevant settings (e.g. for SV-COMP) ALL was already used. The most simple solution to fix the failing test would be of course to just adapt the settings files that is responsible for the tests. However, to be consistent with Automizer (see RcfgPreferenceInitializer), I adapted the default setting for Kojak instead, but maybe this is nothing that should be done in this PR.

* Introduce ScopedHashMap for quantified variables and use it for the handling of IdentifierExpressions
* Use type constraints in Boogie-quantifiers (with implication for \forall and "and" for \exists)
Otherwise the tests with quantifiers fail
@schuessf schuessf force-pushed the wip/fs/acsl-quantifiers branch from 7253c6b to e4645c2 Compare January 10, 2025 12:51
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