[f9ad69d] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2023 University of Waterloo
|
---|
| 3 | //
|
---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
---|
| 5 | // file "LICENCE" distributed with Cforall.
|
---|
| 6 | //
|
---|
| 7 | // poly-many-arsz.cfa -- using many built-in array types with concrete sizes
|
---|
| 8 | //
|
---|
| 9 | // Author : Mike Brooks
|
---|
| 10 | // Created On : Tue Aug 13 12:00:00 2024
|
---|
| 11 | // Last Modified By :
|
---|
| 12 | // Last Modified On :
|
---|
| 13 | // Update Count :
|
---|
| 14 | //
|
---|
| 15 |
|
---|
| 16 | // This behaviour was once broken, as trac #175.
|
---|
| 17 |
|
---|
| 18 | forall( T1*, T2* )
|
---|
| 19 | struct mypair {
|
---|
| 20 | T1 first;
|
---|
| 21 | T2 second;
|
---|
| 22 | };
|
---|
| 23 |
|
---|
| 24 | void baseline( void ) {
|
---|
| 25 | printf("baseline\n");
|
---|
| 26 |
|
---|
| 27 | // no declaration of x
|
---|
| 28 | // facts that are true of y:
|
---|
| 29 |
|
---|
| 30 | mypair(char[2], char) y @= {};
|
---|
[641707d] | 31 | printf("|y| = %zd\n", sizeof(y)); // 3
|
---|
[f9ad69d] | 32 |
|
---|
| 33 | y.second = 0;
|
---|
| 34 | printf("y.second = %d\n", y.second); // 0
|
---|
| 35 |
|
---|
| 36 | y.first[1] = 17;
|
---|
| 37 | printf("y.second = %d\n", y.second); // 0
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | void withInterference( void ) {
|
---|
| 41 | printf("with interference\n");
|
---|
| 42 |
|
---|
| 43 | // adding this declaration of x ...
|
---|
| 44 | mypair(char[1], char) x @= {};
|
---|
[641707d] | 45 | printf("|x| = %zd\n", sizeof(x)); // 2
|
---|
| 46 |
|
---|
| 47 | // ... even if it isn't really used ...
|
---|
| 48 | (void)x;
|
---|
[f9ad69d] | 49 |
|
---|
| 50 | // ... must not affect the observed facts of y:
|
---|
| 51 |
|
---|
| 52 | mypair(char[2], char) y @= {};
|
---|
[641707d] | 53 | printf("|y| = %zd\n", sizeof(y)); // 3
|
---|
[f9ad69d] | 54 |
|
---|
| 55 | y.second = 0;
|
---|
| 56 | printf("y.second = %d\n", y.second); // 0
|
---|
| 57 |
|
---|
| 58 | y.first[1] = 17;
|
---|
| 59 | printf("y.second = %d\n", y.second); // 0
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | int main() {
|
---|
| 63 | baseline();
|
---|
| 64 | withInterference();
|
---|
| 65 | return 0;
|
---|
| 66 | }
|
---|