| [6fbe9a5] | 1 | //
 | 
|---|
 | 2 | // Cforall Version 1.0.0 Copyright (C) 2020 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 | // const-init.cfa -- tests of initializing constants
 | 
|---|
 | 8 | //
 | 
|---|
 | 9 | // Author           : Michael Brooks
 | 
|---|
 | 10 | // Created On       : Tue Oct 06 22:00:00 2020
 | 
|---|
 | 11 | // Last Modified By : Michael Brooks
 | 
|---|
 | 12 | // Last Modified On : Tue Oct 06 22:00:00 2020
 | 
|---|
 | 13 | // Update Count     : 1
 | 
|---|
 | 14 | //
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | /*
 | 
|---|
 | 17 | 
 | 
|---|
| [f1791a4] | 18 | These tests show non-crashing of generated code for constants with interesting initializers.
 | 
|---|
| [6fbe9a5] | 19 | The potential for these to crash is compiler dependent.
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | There are two cases:
 | 
|---|
| [f1791a4] | 22 | 1. static constants in one compilation unit (tested here, in a few sub-cases)
 | 
|---|
| [6fbe9a5] | 23 | 2. extern constants across compilation units (tested by libcfa being loadable, specifically
 | 
|---|
| [f1791a4] | 24 |    the constant definitions in libcfa/src/limits.cfa, which almost every test exercises,
 | 
|---|
| [6fbe9a5] | 25 |    including "hello;" but notably, the "limits" test does not exercise it because that test
 | 
|---|
 | 26 |    is compile-only)
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | Crashes that we have obsrved (#182 and build failures September 2020) are because the libcfa
 | 
|---|
 | 29 | initialization is writing to a global variable (which the declaring program wants typed as 
 | 
|---|
 | 30 | constant), while the compiler has placed this global in a read-only section.
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | Compiler dependence includes:
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 |                           Case 1           Case 2
 | 
|---|
 | 35 | GCC-6  on Ubuntu 16.04    Never crashed    Never crashed
 | 
|---|
 | 36 | GCC-8  on both            Has crashed      Never crashed
 | 
|---|
 | 37 | GCC-10 on Ubuntu 20.04    Has crashed      Has crashed
 | 
|---|
 | 38 | 
 | 
|---|
| [f1791a4] | 39 | For this test to fail, with most other tests passing, would be a situation only ever
 | 
|---|
| [6fbe9a5] | 40 | observed with GCC-8.
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | */
 | 
|---|
 | 43 | 
 | 
|---|
| [f1791a4] | 44 | // initailized by generated function, called before main
 | 
|---|
| [6fbe9a5] | 45 | static const char foo = -1;
 | 
|---|
 | 46 | 
 | 
|---|
| [f1791a4] | 47 | struct thing{};
 | 
|---|
 | 48 | void ^?{}( thing & ) { printf("dtor\n"); }
 | 
|---|
 | 49 | 
 | 
|---|
| [6fbe9a5] | 50 | int main() {
 | 
|---|
| [f1791a4] | 51 |     // foo is already initialized
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 |     // no dtor => stays a (static) local, initialized here
 | 
|---|
 | 54 |     static const char bar = -1;
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 |     // has dtor => becomes a global, ctor called here, dtor called at exit
 | 
|---|
 | 57 |     static const thing it;
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 |     printf("almost done\n");
 | 
|---|
| [6fbe9a5] | 60 | }
 | 
|---|