Line | |
---|
1 | Another, more serious, consequence of allowing a pointer just after an object: |
---|
2 | When we coalesce memory blocks to form stack frames the pointer comparison |
---|
3 | must be careful. At the moment, we break in this kind of situation: |
---|
4 | |
---|
5 | ┌───────┐ ┌───────┐ |
---|
6 | │ int x │ │ int y │ |
---|
7 | └───────┘ └───────┘ |
---|
8 | ↑ ↑ |
---|
9 | &x + 1 != &y |
---|
10 | |
---|
11 | these pointers are different in Clight. But in Cminor: |
---|
12 | |
---|
13 | ┌───────┬───────┐ |
---|
14 | │ int x │ int y │ |
---|
15 | └───────┴───────┘ |
---|
16 | ↑ |
---|
17 | &x + 1 == &y |
---|
18 | |
---|
19 | So we break pointer comparison. We can't possibly preserve pointer comparison |
---|
20 | without putting restrictions on the ordering of stack frames, or adding extra |
---|
21 | padding, so the best solution is to consider the original comparison to have |
---|
22 | undefined behaviour because it is comparing a pointer-off-the-end with a pointer |
---|
23 | from another block. |
---|
24 | |
---|
25 | It gets a little worse: we're currently missing range checks in common/ |
---|
26 | FrontEndOps.ma. Or is it? We've already formed stack frames for the variables, |
---|
27 | although we could get into trouble with global variables. |
---|
28 | |
---|
29 | [6th Nov:] |
---|
30 | |
---|
31 | And another problem that Ilias noticed: when a block is free it is made invalid |
---|
32 | by changing the bounds to make it impossible to have a valid pointer; but the |
---|
33 | definition I wrote for the off-the-end pointers in response to the above only |
---|
34 | checks the pointer w.r.t the upper bound, so fails to spot an invalid block. |
---|
35 | We're just going to drop these now - the back end doesn't have any specific |
---|
36 | support for them (and is broken for inter-block comparisons at the moment, too). |
---|
Note: See
TracBrowser
for help on using the repository browser.