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

Refactor slicing test runner and get rid of UB in tests #413

Merged
merged 25 commits into from
Nov 9, 2021

Conversation

lzaoral
Copy link
Contributor

@lzaoral lzaoral commented Oct 20, 2021

Some small fixes and improvements that I've additionally made during #412 but are independent of it.

@lzaoral lzaoral changed the title Refactor slicing tests a bit Refactor slicing test runner a bit Oct 20, 2021
@lzaoral lzaoral marked this pull request as draft October 22, 2021 20:48
@lzaoral lzaoral changed the title Refactor slicing test runner a bit Refactor slicing test runner and get rid of UB in tests Oct 23, 2021
@lzaoral
Copy link
Contributor Author

lzaoral commented Oct 23, 2021

Blocks #412

@lzaoral lzaoral force-pushed the improve-slicer-tests branch 3 times, most recently from 9dbc9fa to 51478dc Compare October 23, 2021 19:39
@lzaoral lzaoral marked this pull request as ready for review October 23, 2021 20:16
@lzaoral
Copy link
Contributor Author

lzaoral commented Oct 23, 2021

@mchalupa This ended up being a rather big PR but it should have a significant impact (among other things) on the reproducibility of the tests. Thanks in advance!

@lzaoral lzaoral mentioned this pull request Oct 24, 2021
tests/slicing/test-runner.py Outdated Show resolved Hide resolved
tests/slicing/sources/bitcast5.c Show resolved Hide resolved
tests/slicing/sources/pointers6.c Outdated Show resolved Hide resolved
tests/slicing/sources/test22.c Outdated Show resolved Hide resolved
tests/CMakeLists.txt Outdated Show resolved Hide resolved
So that we know that the original code behaves in an expected way.
as some tests used C11 features and many violate the strict aliasing
rules.  Tests that rely on GNU C extensions have set the correct
compiler flags on their own.
According to C11, unaligned access is UB:

A pointer to an object type may be converted to a pointer to a different
object type.  If the resulting pointer is not correctly aligned for the
referenced type, the behavior is undefined.
Namely, -Wimplicit-function-declaration and
-Wincompatible-library-redeclaration.
@lzaoral lzaoral force-pushed the improve-slicer-tests branch from 51478dc to 1b70277 Compare October 29, 2021 14:20
@lzaoral
Copy link
Contributor Author

lzaoral commented Oct 29, 2021

@mchalupa I've incorporated your suggestions and additionally relaxed the input conditions of bitcast tests.

@lzaoral lzaoral force-pushed the improve-slicer-tests branch from 1b70277 to 4aa3201 Compare October 29, 2021 14:36

int result = 0;
for (unsigned i = 0; i < sizeof(int); i++)
result |= (byte[i] = 0x1b) << i * CHAR_BIT;
Copy link
Owner

Choose a reason for hiding this comment

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

This completely changes the test, at least from the point of view of the slicer. Accessing the bytes via constants (e.g., byte[1]) leads to a precise knowledge of what memory is accessed, while accessing it via a variable (bytes[i]) leads to over-approximating the precise knowledge. Please, keep the spirit of the test as it was (accessing bytes via constants). If you want this test with the loop, just add it as a new test (but check that there is not a similar test already).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. I wanted to make the test platform as platform independent as possible so didn't even think about this. I'll revert this change and add this test as a new one. There is already a rather similar one but that one is accessing the bytes by *byte; byte++ pattern and not by byte[i] so I guess that's ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevertheless, I'll change the the type of the char pointer to be explicitly unsigned to silence a clang-tidy warning about implementation defined behaviour of a narrowing conversion from int to char for values greater than 127 which 0xab is.

to silence the following clang-tidy warning:

Narrowing conversion from constant value 171 (0x000000AB) of type 'int' to
signed type 'char' is implementation-defined
... that sets bytes in int in a for loop using `bytes[i]` expression.
@lzaoral lzaoral force-pushed the improve-slicer-tests branch from 4aa3201 to 6131568 Compare November 1, 2021 16:50
@mchalupa
Copy link
Owner

mchalupa commented Nov 9, 2021

Very well, let's merge this then. Thanks a lot!

@mchalupa mchalupa merged commit c4e7e76 into mchalupa:master Nov 9, 2021
@lzaoral lzaoral deleted the improve-slicer-tests branch November 9, 2021 19:00
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