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

label_properties: do not rely on source_locationt's get_function() #4131

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

tautschnig
Copy link
Collaborator

A source location is a place in a text file, and the function information stored
in there need not coincide with the name we use in the goto model.

Part 1: label_properties should use the actual function name so that properties
in different instantiations of a function (as may happen when linking static
functions) get unique names.

This is in parts an RFC: it may actually be the right thing to use source_locationt::get_function for this purpose and no change should be made.

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

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 2ff8e7a).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100224366

@kroening
Copy link
Member

I think that there are two cases to consider:

  • Preconditions: these should get an ID that matches the caller, not the callee
  • Inlining. I would say that the ID should match the callee.

A problem with source_location.get_function() could be decoration to resolve overloading. Do we want an ID like some_class.whatnot(int, blub).property1? Or do we want something shorter?

@kroening
Copy link
Member

kroening commented Feb 12, 2019

Another issue is file-local functions. Say multiple instances of some static function. They all have the same get_function(), and then some other layer of disambiguation needs to happen.

@peterschrammel
Copy link
Member

I'm pretty much open to what the property IDs look like. It's convenient if they are somehow related to the function that contains the assertion, but I wouldn't complain if they were just a sequence number or a hash in order to limit their length.

@TGWDB
Copy link
Contributor

TGWDB commented Sep 15, 2021

Closing this as having unresolved status on whether it is the right thing to do as well as being untouched for a couple of years. Please reopen if you believe this is erroneous and can update with a path towards a correct answer.

@kroening
Copy link
Member

Reopening since we still very much want something like this.

@tautschnig tautschnig self-assigned this Oct 13, 2022
@tautschnig tautschnig changed the title [RFC] label_properties: Only use source_locationt's get_function() for user output label_properties: do not rely on source_locationt's get_function() Oct 13, 2022
@tautschnig tautschnig force-pushed the properties-get_function branch from 2ff8e7a to 25bd89d Compare October 13, 2022 11:10
@tautschnig
Copy link
Collaborator Author

Rebased, but various regression test failures need to be debugged.

@tautschnig tautschnig marked this pull request as draft October 13, 2022 11:10
@tautschnig tautschnig removed the request for review from cesaro October 14, 2022 08:29
@tautschnig tautschnig removed the RFC Request for comment label Nov 9, 2022
@tautschnig tautschnig force-pushed the properties-get_function branch from bdf278b to d774afe Compare November 20, 2022 21:44
@tautschnig tautschnig self-assigned this Nov 21, 2022
@tautschnig tautschnig force-pushed the properties-get_function branch from d774afe to cb8c5f3 Compare November 21, 2022 12:49
@tautschnig tautschnig removed their assignment Nov 21, 2022
@@ -1,7 +1,7 @@
CORE
main.c
--dfcc main --enforce-contract foo _ --malloc-may-fail --malloc-fail-null
^\[foo.assigns.\d+\] line 19 Check that a\[\(signed long (long )?int\)i\] is assignable: SUCCESS$
^\[foo_wrapped_for_contract_checking.assigns.\d+\] line 19 Check that a\[\(signed long (long )?int\)i\] is assignable: SUCCESS$
Copy link
Collaborator

Choose a reason for hiding this comment

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

For contracts, we should not refer to the wrapper function, but to the original function (i.e., foo). The user should identify the assignment in the original function that violates the assigns clause. We might want to keep the change from this PR, but fix this in our instrumentation. (cc. @remi-delmas-3000 )

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes let's keep it like this in this PR, I'll fix generated locations in contracts in a different PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

One way to fix this (but I might be missing something) is to rename the original function instead?!

@feliperodri feliperodri removed their assignment Nov 28, 2022
@remi-delmas-3000
Copy link
Collaborator

I don't understand how deprecating get/set_function solves the problems we currently have ?

Is it by forcing us developers in each different context to think harder about where to get a meaningful function ID from ? (instead of reaching for the method that sounds like it gives us what we want).

How about adding a section in the developer manual with high level guidance on properties/locations things should be presented to the user, at least in cases mentioned above (preconditions/postconditions, in the presence of inlining, in the presence of name mangling, when inserting generic checks, etc.).

@tautschnig
Copy link
Collaborator Author

I don't understand how deprecating get/set_function solves the problems we currently have ?

Is it by forcing us developers in each different context to think harder about where to get a meaningful function ID from ? (instead of reaching for the method that sounds like it gives us what we want).

Yes. That current function produces an arbitrary string that might be good enough for presenting information to a (human) user, but even then could be confusing (think: inlining). Using it to solve other problems in the code base will almost always be wrong, and when it's (seemingly) the only option we have then we might have to build new means for solving the problem.

How about adding a section in the developer manual with high level guidance on properties/locations things should be presented to the user, at least in cases mentioned above (preconditions/postconditions, in the presence of inlining, in the presence of name mangling, when inserting generic checks, etc.).

If we end up retaining get_function(), then we will inevitably need to add guidance to the manual on when (not) to use it. Is that the kind of documentation you are suggesting we add?

@tautschnig tautschnig force-pushed the properties-get_function branch 2 times, most recently from 7b50599 to 1a0fe1b Compare January 11, 2023 12:47
Copy link
Collaborator

@remi-delmas-3000 remi-delmas-3000 left a comment

Choose a reason for hiding this comment

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

When checking a function contract on function foo, we rename foo to foo_wrapped_for_contract_checking or __CPROVER_contracts_original_foo in the GOTO functions map but source locations for all instructions keep the foo function attribute.

The original foo function becomes the verification wrapper which is good because pre/post conditions are labelled with foo.

We wanted the mangling to remain transparent to the user and wanted the original funciton id to be used in both wrapper function and original function assertions, but with this change the mangled function name gets exposed in the property id.
Right now apart from doing a specific pass to fix the property_ids afterwards I don't see how to achieve the desired output.

@@ -1,7 +1,7 @@
CORE
main.c
--dfcc main --enforce-contract foo _ --malloc-may-fail --malloc-fail-null
^\[foo.assigns.\d+\] line 19 Check that a\[\(signed long (long )?int\)i\] is assignable: SUCCESS$
^\[foo_wrapped_for_contract_checking.assigns.\d+\] line 19 Check that a\[\(signed long (long )?int\)i\] is assignable: SUCCESS$
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes let's keep it like this in this PR, I'll fix generated locations in contracts in a different PR

@@ -45,11 +45,10 @@ void show_properties(
/// \param property: irep_idt that identifies property
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this the property class (e.g. assert, assigns, precondition, etc.) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, this is the full property identifier (a unique key).

@@ -45,11 +45,10 @@ void show_properties(
/// \param property: irep_idt that identifies property
/// \param goto_functions: program in which to search for
/// the property
/// \return optional<source_locationt> the location of the
/// \return A pair of function identifier and source location of the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: "A pair of function identifier and source location, where the function identifier is that of the GOTO function that contains the ASSERT instructions matching the property, and the source location is that of the ASSERT instruction matching the property. The function identifier and source location's function attribute are not necessarily equal."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, I've updated this comment.

Copy link
Member

@peterschrammel peterschrammel left a comment

Choose a reason for hiding this comment

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

Maybe we should distinguish between GOTO function and "source function"? What you would like to see in the property names is the source function whereas get_function returns the GOTO function (and is required to return the GOTO function in some places in the code). Source function would then always track the original C function a goto statement is associated with/has been derived from.

@tautschnig tautschnig self-assigned this Jan 30, 2023
@feliperodri feliperodri removed aws Bugs or features of importance to AWS CBMC users aws-medium labels Jan 30, 2023
@tautschnig
Copy link
Collaborator Author

Maybe we should distinguish between GOTO function and "source function"? What you would like to see in the property names is the source function whereas get_function returns the GOTO function (and is required to return the GOTO function in some places in the code). Source function would then always track the original C function a goto statement is associated with/has been derived from.

Well, but that "source function" is not necessarily unique (just consider static (file-local) functions). So it can't trivially be used as the prefix of property identifiers.

@tautschnig tautschnig force-pushed the properties-get_function branch from 1a0fe1b to fc24af0 Compare February 4, 2023 21:25
@tautschnig tautschnig removed their assignment Feb 4, 2023
@tautschnig tautschnig force-pushed the properties-get_function branch from fc24af0 to 3e8d1d5 Compare February 23, 2023 10:05
@tautschnig tautschnig self-assigned this May 31, 2023
A source location is a place in a text file, and the function information stored
in there need not coincide with the name we use in the goto model.

In this vein, label_properties should use the actual function name so
that properties in different instantiations of a function (as may happen
when linking static functions) get unique names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants