Fortran · 831 bytes Raw Blame History
1 ! Audit #4 CRITICAL-1 — SAVE init that references a named
2 ! PARAMETER now folds correctly and preserves SAVE semantics.
3 !
4 ! Fixed: eval_const_scalar takes a `param_consts` map and
5 ! resolves Expr::Name references against it. alloc_decls (and
6 ! collect_module_globals) build the map by walking the decls
7 ! list incrementally so a later parameter declaration can
8 ! reference earlier ones (`tau = 2 * pi`).
9 !
10 ! `integer :: x = k * 2` (k a parameter) now folds to 20,
11 ! SAVE-promotes to .data, and the counter advances correctly
12 ! across calls instead of resetting to 21 every time.
13 !
14 ! CHECK: 21
15 ! CHECK: 22
16 ! CHECK: 23
17 program audit4_c1_save_parameter_ref
18 call s()
19 call s()
20 call s()
21 contains
22 subroutine s()
23 integer, parameter :: k = 10
24 integer :: x = k * 2
25 x = x + 1
26 print *, x
27 end subroutine
28 end program
29