-
Notifications
You must be signed in to change notification settings - Fork 20
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
Allow vla in cil result #7
Conversation
This reverts commit 98aeda1.
…type. This allows more than we would ideally want to allow
This is weaker than the orginal test, but also works for types of VLA arguments
Printing CILs internal representation into C again requires some more work
is turned into
which won't compile because d is out of scope in line 6 where it is used. 😞 |
Turns out this is not a CIL problem (it works in CIL) but a result of the allBBVisitor https://github.com/goblint/analyzer/blob/c74ebb1577c58ad70f4863fe431c53a6a934533a/src/util/cilfacade.ml#L38 |
It assumes that instructions can't be declarations. |
#include <stdlib.h>
int f(int i, int n, int m, int a[n][m]) {
return a[i][2*i];
}
// how to encode multi-dimensional VLAs with alloca?
int main(int argc, char** argv) {
int l = argc;
int x;
if (l==1) {
// normal two-dimensional array, VLA: 5 and 6 might be variables
// -> solution: add a constructor to Cil.instr for (VLA-)declarations?
int a[5][6];
a[1][2] = 42;
x = a[1][2];
x = f(1, 5, 6, a);
return x;
} else if (l==2) {
// pointer to 2nd arrays, problem is that 6 might still be a variable
// -> not a solution for VLAs
int (*a)[6];
a = alloca(sizeof(int [6]) * 5);
a[1][2] = 42;
x = a[1][2];
x = f(1, 5, 6, a);
return x;
} else {
// pointer to int
// -> works but needs a lot of instrumentation
int* a;
// sizes we need to move the pointer by where size_1 is for the first index, _2 for the second. need to save them into temp. variables because the value of the original expression can change (and also to trigger possible side-effects at the location of the declaration).
size_t a_size_2 = sizeof(int);
size_t a_size_1 = 6 * a_size_2;
a = alloca(5 * a_size_1);
// a[1][2] = 42; // this needs to go to a + 1*6 + 2
*(a + 1*a_size_1 + 2*a_size_2) = 42;
x = *(a + 1*a_size_1 + 2*a_size_2);
// x = f(1, 5, 6, a); // incompatible pointer types passing 'int **' to parameter of type 'int (*)[*]' [-Wincompatible-pointer-types]
// we can only cast to a pointer to an array
x = f(1, 5, 6, (int (*)[6]) a);
return x;
}
} |
Ensures that for varinfos for which we have a VarDecl instruction vhasdeclinstruction is set
The input for this testcase did not compile with GCC, and the CIL output just happened to compile due to to the transformation of VLA into alloca. Replaced invalid local var int arr[]; with int *arr;
'make doc' did not work without this
…es or not via alwaysGenerateVarDecl in cabs2cil.ml and cleanup of print code
Summary (cf. #7 (comment)):
Currently only used for VLAs, but could be used for any declaration, which has the advantage that the state would only contain variables that have already been declared so far. OTOH one should then introduce a dual transfer function for when a variable goes out of scope. Cil's renaming would probably have to be kept in case of shadowing. |
|
Also, all osx builds are failing (probably unrelated): https://travis-ci.com/goblint/cil/builds/134384476 |
This does not fix the analyses. In most cases we just raise an exception. To use these analyses with programs that have VLA, some work is most likely required. This is not done at the moment, because we do not use these analyses. References #7
Resolves #5.
Needs to be merged at the same time as https://github.com/goblint/analyzer/tree/allow_vla_in_cil_result is merged into Goblint master.