Skip to content

Implement C library string functions via array_{copy,replace,set} #795

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 15 commits into from
May 29, 2017

Conversation

tautschnig
Copy link
Collaborator

This avoids byte-wise copy loops in several places.

@tautschnig
Copy link
Collaborator Author

Some cleanup and debugging is still in progress -> do not merge.

@tautschnig tautschnig self-assigned this May 23, 2017
__CPROVER_array_set(res, 0);
else if(nmemb==1)
for(__CPROVER_size_t i=0; i<size; ++i)
((char*)res)[i]=0;
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason not to use array_set for the nmemb==1 case?

@@ -500,7 +516,7 @@ inline char *strdup(const char *str)

#undef memcpy

inline void *memcpy(void *dst, const void *src, size_t n)
void *memcpy(void *dst, const void *src, size_t n)
Copy link
Member

Choose a reason for hiding this comment

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

A benefit of the 'inline' is that the assertions get the location of the call site.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The problem is that we don't have frames for inlined copies of functions. Thus goto-symex cannot remove local variables when leaving the inlined function scope. Consequently we get type conflicts because we have multiple copies of an array of dynamic size with different size in the same frame.

@@ -2315,7 +2315,7 @@ class extractbits_exprt:public exprt
const exprt &_lower,
const typet &_type):exprt(ID_extractbits, _type)
{
copy_to_operands(_src, _lower, _upper);
copy_to_operands(_src, _upper, _lower);
}
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 swap the order of the parameters?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A comment elsewhere says that this is the order that SMT-LIB uses. Otherwise I have no particular opinion about this...

@tautschnig tautschnig force-pushed the array-replace branch 2 times, most recently from 6818e57 to a320c8c Compare May 23, 2017 17:38
@tautschnig
Copy link
Collaborator Author

Some further testing on the code base that triggered this work is required on my end. Note that a320c8c is not acceptable as is.

@tautschnig tautschnig force-pushed the array-replace branch 4 times, most recently from 55fb898 to 237f248 Compare May 24, 2017 19:00
@tautschnig
Copy link
Collaborator Author

I'm still unhappy and unsure about 37f248, but otherwise this appears to be ok in my (limited) testing.

@tautschnig tautschnig force-pushed the array-replace branch 3 times, most recently from a257611 to 5d79f11 Compare May 25, 2017 10:57
@tautschnig
Copy link
Collaborator Author

I'm still unhappy and unsure about 37f248, but otherwise this appears to be ok in my (limited) testing.

This hack is now gone as it proved unnecessary.

Multiple uses of the same library function might cause phi nodes merging arrays
of different size, when really their objects have actually gone out of scope.
Properly handle byte_extract from arrays or structs, and also support the case
where at least one of source or target size are known.  This is a best-effort
attempt: there could be out-of-bounds accesses in the program under scrutiny,
which will be ignored. Finally ensure that flatten_byte_extract never returns
another byte_extract.
…ter_predicates

This will ensure consistent typing.
…ize_type

member_offset_expr would otherwise yield mixed signed/unsigned plus expressions
as size_of_expr is combined with member_offset_expr results.
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.

2 participants