re PR middle-end/40026 (ICE during gimplify_init_constructor)
[official-gcc.git] / libgfortran / runtime / compile_options.c
blobc3d26f4148d65a4f871482fe4b60bb48ab942c96
1 /* Handling of compile-time options that influence the library.
2 Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6 Libgfortran is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 Libgfortran is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #include "libgfortran.h"
27 #ifdef HAVE_SIGNAL_H
28 #include <signal.h>
29 #endif
32 /* Useful compile-time options will be stored in here. */
33 compile_options_t compile_options;
36 /* A signal handler to allow us to output a backtrace. */
37 void
38 handler (int signum)
40 const char * name = NULL, * desc = NULL;
42 switch (signum)
44 #if defined(SIGSEGV)
45 case SIGSEGV:
46 name = "SIGSEGV";
47 desc = "Segmentation fault";
48 break;
49 #endif
51 #if defined(SIGBUS)
52 case SIGBUS:
53 name = "SIGBUS";
54 desc = "Bus error";
55 break;
56 #endif
58 #if defined(SIGILL)
59 case SIGILL:
60 name = "SIGILL";
61 desc = "Illegal instruction";
62 break;
63 #endif
65 #if defined(SIGFPE)
66 case SIGFPE:
67 name = "SIGFPE";
68 desc = "Floating-point exception";
69 break;
70 #endif
73 if (name)
74 st_printf ("\nProgram received signal %d (%s): %s.\n", signum, name, desc);
75 else
76 st_printf ("\nProgram received signal %d.\n", signum);
78 sys_exit (5);
82 /* Set the usual compile-time options. */
83 extern void set_options (int , int []);
84 export_proto(set_options);
86 void
87 set_options (int num, int options[])
89 if (num >= 1)
90 compile_options.warn_std = options[0];
91 if (num >= 2)
92 compile_options.allow_std = options[1];
93 if (num >= 3)
94 compile_options.pedantic = options[2];
95 if (num >= 4)
96 compile_options.dump_core = options[3];
97 if (num >= 5)
98 compile_options.backtrace = options[4];
99 if (num >= 6)
100 compile_options.sign_zero = options[5];
101 if (num >= 7)
102 compile_options.bounds_check = options[6];
103 if (num >= 8)
104 compile_options.range_check = options[7];
106 /* If backtrace is required, we set signal handlers on most common
107 signals. */
108 #if defined(HAVE_SIGNAL) && (defined(SIGSEGV) || defined(SIGBUS) \
109 || defined(SIGILL) || defined(SIGFPE))
110 if (compile_options.backtrace)
112 #if defined(SIGSEGV)
113 signal (SIGSEGV, handler);
114 #endif
116 #if defined(SIGBUS)
117 signal (SIGBUS, handler);
118 #endif
120 #if defined(SIGILL)
121 signal (SIGILL, handler);
122 #endif
124 #if defined(SIGFPE)
125 signal (SIGFPE, handler);
126 #endif
128 #endif
133 /* Default values for the compile-time options. Keep in sync with
134 gcc/fortran/options.c (gfc_init_options). */
135 void
136 init_compile_options (void)
138 compile_options.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
139 compile_options.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
140 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
141 | GFC_STD_GNU | GFC_STD_LEGACY;
142 compile_options.pedantic = 0;
143 compile_options.dump_core = 0;
144 compile_options.backtrace = 0;
145 compile_options.sign_zero = 1;
146 compile_options.range_check = 1;
149 /* Function called by the front-end to tell us the
150 default for unformatted data conversion. */
152 extern void set_convert (int);
153 export_proto (set_convert);
155 void
156 set_convert (int conv)
158 compile_options.convert = conv;
161 extern void set_record_marker (int);
162 export_proto (set_record_marker);
165 void
166 set_record_marker (int val)
169 switch(val)
171 case 4:
172 compile_options.record_marker = sizeof (GFC_INTEGER_4);
173 break;
175 case 8:
176 compile_options.record_marker = sizeof (GFC_INTEGER_8);
177 break;
179 default:
180 runtime_error ("Invalid value for record marker");
181 break;
185 extern void set_max_subrecord_length (int);
186 export_proto (set_max_subrecord_length);
188 void set_max_subrecord_length(int val)
190 if (val > GFC_MAX_SUBRECORD_LENGTH || val < 1)
192 runtime_error ("Invalid value for maximum subrecord length");
193 return;
196 compile_options.max_subrecord_length = val;