[fd4df379] | 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 | // boxed.bookend.cfa -- stack address recording and acceptance for the "array boxed" test
|
---|
| 8 | //
|
---|
| 9 | // Author : Mike Brooks
|
---|
| 10 | // Created On : Thu Jul 25 17:00:00 2024
|
---|
| 11 | // Last Modified By :
|
---|
| 12 | // Last Modified On :
|
---|
| 13 | // Update Count :
|
---|
| 14 | //
|
---|
| 15 |
|
---|
| 16 | // See general test documentation in boxed.main.cfa.
|
---|
| 17 | // See abbreviation definitions in boxed.cases.hfa.
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | #include "boxed.hfa"
|
---|
| 23 |
|
---|
| 24 | char * ar_lo = (char *) -1;
|
---|
| 25 | char * ar_hi = 0p;
|
---|
| 26 | static char * bookend_lo = (char *) -1;
|
---|
| 27 | static char * bookend_hi = 0p;
|
---|
| 28 |
|
---|
[829821c] | 29 | // bookend pointers are set to stack addresses and compared (but not dereferenced)
|
---|
| 30 | // after their functions exit; they are "dangling"
|
---|
| 31 | #pragma GCC diagnostic push
|
---|
| 32 | #pragma GCC diagnostic ignored "-Wpragmas" // -Wdangling-pointer unrecognized until GCC 12
|
---|
| 33 | #pragma GCC diagnostic ignored "-Wdangling-pointer"
|
---|
| 34 |
|
---|
[fd4df379] | 35 | void bookendInner( void ) {
|
---|
| 36 | char var = 'x';
|
---|
| 37 | (void) var;
|
---|
| 38 | bookend_lo = & var;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | #define TC(...)
|
---|
| 42 | #define TR( TRID, SZS, SZV, ETG, ACCS, SPS, OVLD ) \
|
---|
[829821c] | 43 | F_SIG( bookendOuter, TRID, SZS, SZV, ACCS, SPS, OVLD ) { \
|
---|
[fd4df379] | 44 | char var = 'x'; \
|
---|
| 45 | (void) var; \
|
---|
| 46 | bookend_hi = & var; \
|
---|
[829821c] | 47 | return CALL( allocAndAccess, TRID, SZS, n, expectedElmSz, tcid, vart ); \
|
---|
[fd4df379] | 48 | }
|
---|
| 49 | #include "boxed.cases.hfa"
|
---|
| 50 | #undef TC
|
---|
| 51 | #undef TR
|
---|
| 52 |
|
---|
[829821c] | 53 | #pragma GCC diagnostic pop
|
---|
| 54 |
|
---|
[fd4df379] | 55 | void resetBookends( void ) {
|
---|
| 56 | bookend_lo = (char *) -1;
|
---|
| 57 | bookend_hi = 0p;
|
---|
| 58 | ar_lo = (char *) -1;
|
---|
| 59 | ar_hi = 0p;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | void reportBookends( void ) {
|
---|
| 63 | ptrdiff_t ar_lo_fwd_offs = ar_lo - bookend_lo;
|
---|
| 64 | ptrdiff_t ar_hi_rev_offs = bookend_hi - ar_hi;
|
---|
| 65 |
|
---|
| 66 | VPRT( "Bookends are %p and %p\n", bookend_lo, bookend_hi );
|
---|
| 67 | VPRT( "Array ends are %p and %p\n", ar_lo, ar_hi );
|
---|
| 68 | VPRT( "Bookend lo fwd offset %zd\n", bookend_lo - bookend_lo );
|
---|
| 69 | VPRT( "Array lo fwd offset %zd\n", ar_lo_fwd_offs );
|
---|
| 70 | VPRT( "Array hi fwd offset %zd\n", ar_hi - bookend_lo );
|
---|
| 71 | VPRT( "Bookend hi fwd offset %zd\n", bookend_hi - bookend_lo );
|
---|
| 72 | VPRT( "Bookend lo rev offset %zd\n", bookend_hi - bookend_lo );
|
---|
| 73 | VPRT( "Array lo rev offset %zd\n", bookend_hi - ar_lo );
|
---|
| 74 | VPRT( "Array hi rev offset %zd\n", ar_hi_rev_offs );
|
---|
| 75 | VPRT( "Bookend hi rev offset %zd\n", bookend_hi - bookend_hi );
|
---|
| 76 |
|
---|
| 77 | if (bookend_lo >= bookend_hi) {
|
---|
| 78 | printf("bookends were not set\n");
|
---|
| 79 | return;
|
---|
| 80 | }
|
---|
| 81 | if (ar_lo >= ar_hi) {
|
---|
| 82 | printf("array bounds were not set\n");
|
---|
| 83 | return;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | printf("array starts after lo bookend: %s\n", ar_lo_fwd_offs > 0 ? "yes" : "no" );
|
---|
| 87 | printf("array ends before hi bookend: %s\n", ar_hi_rev_offs > 0 ? "yes" : "no" );
|
---|
| 88 | }
|
---|