-
Notifications
You must be signed in to change notification settings - Fork 5
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
Adding bounds inference of the form count(i+1) #602
Conversation
I would still like to have a realistic example program on record before adding this much code to 3C, but others can overrule me. |
assert(!Changed && "New arrays needed bounds after inference"); | ||
TmpArrNeededBounds = ArrNeededBounds; | ||
OuterChanged = !ArrNeededBounds.empty(); | ||
while (OuterChanged) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's changed here that requires and extra outer loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the organization of the code a little.
OuterLoop (Loop until nothing changes):
- Loop until nothing changes: Propagate Bounds.
- Loop untill nothing changes: Get bounds from likely bounds (e.g., i < n, arr[i], etc).
@@ -15,6 +15,6 @@ void foo(int *w) { | |||
y[1] = 3; | |||
int *z = realloc(y, 5 * sizeof(int)); | |||
//CHECK_NOALL: int *z = realloc<int>(y, 5 * sizeof(int)); | |||
//CHECK_ALL: _Array_ptr<int> z = realloc<int>(y, 5 * sizeof(int)); | |||
//CHECK_ALL: _Array_ptr<int> z : count(3 + 1) = realloc<int>(y, 5 * sizeof(int)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't realloc
generate a bound on z
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As of now, we do not insert bounds because of realloc
(we only handle malloc
). Lets make another issue for this.
@@ -7,19 +7,19 @@ | |||
|
|||
int **func(int **p, int *x) { | |||
//CHECK_NOALL: int **func(int **p : itype(_Ptr<_Ptr<int>>), _Ptr<int> x) : itype(_Ptr<int *>) { | |||
//CHECK_ALL: _Array_ptr<_Ptr<int>> func(_Array_ptr<_Ptr<int>> p, _Ptr<int> x) _Checked { | |||
//CHECK_ALL: _Array_ptr<_Ptr<int>> func(_Array_ptr<_Ptr<int>> p : count(1 + 1), _Ptr<int> x) : count(1 + 1) _Checked { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return bound here is incorrect, but maybe this is acceptable since we know bounds inference gets bounds wrong some times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Let's make another issue for this. There are some issues with generating bounds for &(arr[1])
kinda expressions.
y[10] = 1; | ||
} | ||
|
||
int *foo(int *q) { | ||
//CHECK: _Array_ptr<int> foo(_Array_ptr<int> q) { | ||
//CHECK: _Array_ptr<int> foo(_Array_ptr<int> q) : count(10 + 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could q
get the same bound as the return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return bounds do not flow to inside variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just recording my skepticism that this change should be made at all (per the pending discussion in #599) in a more obvious way, though of course I may be overruled, in which case we can dismiss my review here.
@john-h-kastner I tested on
and there are other examples too. (Recording justification) |
With regrets for belaboring the point, this is the same example that you already posted on #599 and that I argued there wasn't convincing to me. |
Merging this for now. Zane will do a clean of the code and make it more streamlined. |
This will add a new heuristic, where the bounds of an array will be inferred as index + 1.
For instance, for the following code:
The bounds will be inferred as follows:
More details: #599
This improves the bounds inference of other benchmarks as well.
For
yacr2
ofptrdist
:That further added bounds to other functions: