source: tests/const-init.cfa @ 262c600

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 262c600 was f1791a4, checked in by Michael Brooks <mlbrooks@…>, 4 years ago

Expanding earlier #182 fix to another case of the same issue. Fixes #224?

There is now a reusable helper function addDataSectonAttribute that applies the fix to an ObjectDecl? when we realize it needs it. Test const-init is expanded with case of #224.

  • Property mode set to 100644
File size: 2.0 KB
Line 
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
18These tests show non-crashing of generated code for constants with interesting initializers.
19The potential for these to crash is compiler dependent.
20
21There are two cases:
221. static constants in one compilation unit (tested here, in a few sub-cases)
232. extern constants across compilation units (tested by libcfa being loadable, specifically
24   the constant definitions in libcfa/src/limits.cfa, which almost every test exercises,
25   including "hello;" but notably, the "limits" test does not exercise it because that test
26   is compile-only)
27
28Crashes that we have obsrved (#182 and build failures September 2020) are because the libcfa
29initialization is writing to a global variable (which the declaring program wants typed as
30constant), while the compiler has placed this global in a read-only section.
31
32Compiler dependence includes:
33
34                          Case 1           Case 2
35GCC-6  on Ubuntu 16.04    Never crashed    Never crashed
36GCC-8  on both            Has crashed      Never crashed
37GCC-10 on Ubuntu 20.04    Has crashed      Has crashed
38
39For this test to fail, with most other tests passing, would be a situation only ever
40observed with GCC-8.
41
42*/
43
44// initailized by generated function, called before main
45static const char foo = -1;
46
47struct thing{};
48void ^?{}( thing & ) { printf("dtor\n"); }
49
50int main() {
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");
60}
Note: See TracBrowser for help on using the repository browser.