]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | /* Parse and display command line options. |
5624e564 | 2 | Copyright (C) 2000-2015 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | Contributed by Andy Vaught |
4 | ||
9fc4d79b | 5 | This file is part of GCC. |
6de9cd9a | 6 | |
9fc4d79b TS |
7 | GCC is free software; you can redistribute it and/or modify it under |
8 | the terms of the GNU General Public License as published by the Free | |
d234d788 | 9 | Software Foundation; either version 3, or (at your option) any later |
9fc4d79b | 10 | version. |
6de9cd9a | 11 | |
9fc4d79b TS |
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
6de9cd9a DN |
16 | |
17 | You should have received a copy of the GNU General Public License | |
d234d788 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a | 20 | |
6de9cd9a DN |
21 | #include "config.h" |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
40e23961 | 24 | #include "alias.h" |
6de9cd9a | 25 | #include "tree.h" |
c7131fb2 | 26 | #include "options.h" |
6de9cd9a DN |
27 | #include "flags.h" |
28 | #include "intl.h" | |
29 | #include "opts.h" | |
41804a5b | 30 | #include "toplev.h" /* For save_decoded_options. */ |
a5320d39 | 31 | #include "params.h" |
6de9cd9a | 32 | #include "tree-inline.h" |
6de9cd9a | 33 | #include "gfortran.h" |
25d8f0a2 | 34 | #include "target.h" |
670637ee | 35 | #include "cpp.h" |
7d5a5747 | 36 | #include "diagnostic.h" /* For global_dc. */ |
8ce94e44 | 37 | #include "tm.h" |
de3aebff | 38 | #include "langhooks.h" |
6de9cd9a DN |
39 | |
40 | gfc_option_t gfc_option; | |
41 | ||
42 | ||
a47eec17 | 43 | /* Set flags that control warnings and errors for different |
5fb41e29 TB |
44 | Fortran standards to their default values. Keep in sync with |
45 | libgfortran/runtime/compile_options.c (init_compile_options). */ | |
a47eec17 JD |
46 | |
47 | static void | |
48 | set_default_std_flags (void) | |
49 | { | |
50 | gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL | |
f489fba1 | 51 | | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77 |
4650947d | 52 | | GFC_STD_F2008_OBS | GFC_STD_F2008_TS | GFC_STD_GNU | GFC_STD_LEGACY; |
a47eec17 JD |
53 | gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY; |
54 | } | |
55 | ||
5fb41e29 | 56 | |
7a9bf9a4 JM |
57 | /* Return language mask for Fortran options. */ |
58 | ||
59 | unsigned int | |
60 | gfc_option_lang_mask (void) | |
61 | { | |
62 | return CL_Fortran; | |
63 | } | |
64 | ||
a75bfaa6 JM |
65 | /* Initialize options structure OPTS. */ |
66 | ||
67 | void | |
68 | gfc_init_options_struct (struct gcc_options *opts) | |
69 | { | |
70 | opts->x_flag_errno_math = 0; | |
321bff11 | 71 | opts->frontend_set_flag_errno_math = true; |
a75bfaa6 | 72 | opts->x_flag_associative_math = -1; |
321bff11 | 73 | opts->frontend_set_flag_associative_math = true; |
a75bfaa6 | 74 | } |
7a9bf9a4 | 75 | |
5fb41e29 | 76 | /* Get ready for options handling. Keep in sync with |
1cc0e193 | 77 | libgfortran/runtime/compile_options.c (init_compile_options). */ |
6de9cd9a | 78 | |
7a9bf9a4 JM |
79 | void |
80 | gfc_init_options (unsigned int decoded_options_count, | |
81 | struct cl_decoded_option *decoded_options) | |
6de9cd9a | 82 | { |
e0bcf78c | 83 | gfc_source_file = NULL; |
6de9cd9a DN |
84 | gfc_option.module_dir = NULL; |
85 | gfc_option.source_form = FORM_UNKNOWN; | |
dfbfb630 JD |
86 | gfc_option.max_continue_fixed = 255; |
87 | gfc_option.max_continue_free = 255; | |
6de9cd9a | 88 | gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN; |
3f139fcf | 89 | gfc_option.max_errors = 25; |
6de9cd9a | 90 | |
2d7c7df6 | 91 | gfc_option.flag_preprocessed = 0; |
e0bcf78c | 92 | gfc_option.flag_d_lines = -1; |
51b09ce3 AL |
93 | gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF; |
94 | gfc_option.flag_init_integer_value = 0; | |
51b09ce3 AL |
95 | gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF; |
96 | gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF; | |
97 | gfc_option.flag_init_character_value = (char)0; | |
98 | ||
944b8b35 | 99 | gfc_option.fpe = 0; |
fa86f4f9 TB |
100 | /* All except GFC_FPE_INEXACT. */ |
101 | gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL | |
102 | | GFC_FPE_ZERO | GFC_FPE_OVERFLOW | |
103 | | GFC_FPE_UNDERFLOW; | |
d3d3011f | 104 | gfc_option.rtcheck = 0; |
944b8b35 | 105 | |
7c02f68b MLI |
106 | /* ??? Wmissing-include-dirs is disabled by default in C/C++ but |
107 | enabled by default in Fortran. Ideally, we should express this | |
108 | in .opt, but that is not supported yet. */ | |
109 | if (!global_options_set.x_cpp_warn_missing_include_dirs) | |
6f3d1a5e | 110 | global_options.x_cpp_warn_missing_include_dirs = 1; |
7c02f68b | 111 | |
a47eec17 | 112 | set_default_std_flags (); |
6de9cd9a | 113 | |
670637ee | 114 | /* Initialize cpp-related options. */ |
7a9bf9a4 | 115 | gfc_cpp_init_options (decoded_options_count, decoded_options); |
8e54f6d3 | 116 | gfc_diagnostics_init (); |
6de9cd9a DN |
117 | } |
118 | ||
119 | ||
e0bcf78c TS |
120 | /* Determine the source form from the filename extension. We assume |
121 | case insensitivity. */ | |
122 | ||
123 | static gfc_source_form | |
124 | form_from_filename (const char *filename) | |
125 | { | |
e0bcf78c TS |
126 | static const struct |
127 | { | |
128 | const char *extension; | |
129 | gfc_source_form form; | |
130 | } | |
131 | exttype[] = | |
132 | { | |
133 | { | |
134 | ".f90", FORM_FREE} | |
135 | , | |
136 | { | |
137 | ".f95", FORM_FREE} | |
138 | , | |
139 | { | |
7befd5d2 TB |
140 | ".f03", FORM_FREE} |
141 | , | |
142 | { | |
f489fba1 FXC |
143 | ".f08", FORM_FREE} |
144 | , | |
145 | { | |
e0bcf78c TS |
146 | ".f", FORM_FIXED} |
147 | , | |
148 | { | |
149 | ".for", FORM_FIXED} | |
150 | , | |
151 | { | |
1200489c TB |
152 | ".ftn", FORM_FIXED} |
153 | , | |
154 | { | |
e0bcf78c TS |
155 | "", FORM_UNKNOWN} |
156 | }; /* sentinel value */ | |
157 | ||
158 | gfc_source_form f_form; | |
159 | const char *fileext; | |
160 | int i; | |
161 | ||
162 | /* Find end of file name. Note, filename is either a NULL pointer or | |
163 | a NUL terminated string. */ | |
164 | i = 0; | |
165 | while (filename[i] != '\0') | |
166 | i++; | |
167 | ||
168 | /* Find last period. */ | |
169 | while (i >= 0 && (filename[i] != '.')) | |
170 | i--; | |
171 | ||
172 | /* Did we see a file extension? */ | |
173 | if (i < 0) | |
174 | return FORM_UNKNOWN; /* Nope */ | |
175 | ||
176 | /* Get file extension and compare it to others. */ | |
177 | fileext = &(filename[i]); | |
178 | ||
179 | i = -1; | |
180 | f_form = FORM_UNKNOWN; | |
181 | do | |
182 | { | |
183 | i++; | |
184 | if (strcasecmp (fileext, exttype[i].extension) == 0) | |
185 | { | |
186 | f_form = exttype[i].form; | |
187 | break; | |
188 | } | |
189 | } | |
190 | while (exttype[i].form != FORM_UNKNOWN); | |
191 | ||
192 | return f_form; | |
193 | } | |
194 | ||
195 | ||
6de9cd9a DN |
196 | /* Finalize commandline options. */ |
197 | ||
198 | bool | |
199 | gfc_post_options (const char **pfilename) | |
200 | { | |
2d7c7df6 | 201 | const char *filename = *pfilename, *canon_source_file = NULL; |
b424a572 FXC |
202 | char *source_path; |
203 | int i; | |
6de9cd9a | 204 | |
8ce94e44 JM |
205 | /* Excess precision other than "fast" requires front-end |
206 | support. */ | |
207 | if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD | |
208 | && TARGET_FLT_EVAL_METHOD_NON_DEFAULT) | |
209 | sorry ("-fexcess-precision=standard for Fortran"); | |
210 | flag_excess_precision_cmdline = EXCESS_PRECISION_FAST; | |
211 | ||
feef2551 TB |
212 | /* Fortran allows associative math - but we cannot reassociate if |
213 | we want traps or signed zeros. Cf. also flag_protect_parens. */ | |
214 | if (flag_associative_math == -1) | |
215 | flag_associative_math = (!flag_trapping_math && !flag_signed_zeros); | |
216 | ||
203c7ebf TB |
217 | if (flag_protect_parens == -1) |
218 | flag_protect_parens = !optimize_fast; | |
7a994646 | 219 | |
203c7ebf TB |
220 | if (flag_stack_arrays == -1) |
221 | flag_stack_arrays = optimize_fast; | |
2d8c9ad5 | 222 | |
597553ab | 223 | /* By default, disable (re)allocation during assignment for -std=f95, |
1cc0e193 | 224 | and enable it for F2003/F2008/GNU/Legacy. */ |
203c7ebf | 225 | if (flag_realloc_lhs == -1) |
597553ab PT |
226 | { |
227 | if (gfc_option.allow_std & GFC_STD_F2003) | |
203c7ebf | 228 | flag_realloc_lhs = 1; |
597553ab | 229 | else |
203c7ebf | 230 | flag_realloc_lhs = 0; |
597553ab PT |
231 | } |
232 | ||
d3d3011f FXC |
233 | /* -fbounds-check is equivalent to -fcheck=bounds */ |
234 | if (flag_bounds_check) | |
235 | gfc_option.rtcheck |= GFC_RTCHECK_BOUNDS; | |
236 | ||
2153915d | 237 | if (flag_compare_debug) |
c61819ff | 238 | flag_dump_fortran_original = 0; |
2153915d | 239 | |
3a789837 NF |
240 | /* Make -fmax-errors visible to gfortran's diagnostic machinery. */ |
241 | if (global_options_set.x_flag_max_errors) | |
242 | gfc_option.max_errors = flag_max_errors; | |
243 | ||
6de9cd9a DN |
244 | /* Verify the input file name. */ |
245 | if (!filename || strcmp (filename, "-") == 0) | |
246 | { | |
247 | filename = ""; | |
248 | } | |
249 | ||
2d7c7df6 JJ |
250 | if (gfc_option.flag_preprocessed) |
251 | { | |
252 | /* For preprocessed files, if the first tokens are of the form # NUM. | |
253 | handle the directives so we know the original file name. */ | |
254 | gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file); | |
255 | if (gfc_source_file == NULL) | |
256 | gfc_source_file = filename; | |
257 | else | |
258 | *pfilename = gfc_source_file; | |
259 | } | |
260 | else | |
261 | gfc_source_file = filename; | |
262 | ||
263 | if (canon_source_file == NULL) | |
264 | canon_source_file = gfc_source_file; | |
e0bcf78c | 265 | |
b424a572 FXC |
266 | /* Adds the path where the source file is to the list of include files. */ |
267 | ||
2d7c7df6 JJ |
268 | i = strlen (canon_source_file); |
269 | while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i])) | |
b424a572 | 270 | i--; |
edf1eac2 | 271 | |
b424a572 FXC |
272 | if (i != 0) |
273 | { | |
ece3f663 | 274 | source_path = (char *) alloca (i + 1); |
2d7c7df6 | 275 | memcpy (source_path, canon_source_file, i); |
b424a572 | 276 | source_path[i] = 0; |
308f961b | 277 | gfc_add_include_path (source_path, true, true, true); |
b424a572 FXC |
278 | } |
279 | else | |
308f961b | 280 | gfc_add_include_path (".", true, true, true); |
b424a572 | 281 | |
2d7c7df6 | 282 | if (canon_source_file != gfc_source_file) |
cede9502 | 283 | free (CONST_CAST (char *, canon_source_file)); |
2d7c7df6 | 284 | |
e0bcf78c TS |
285 | /* Decide which form the file will be read in as. */ |
286 | ||
287 | if (gfc_option.source_form != FORM_UNKNOWN) | |
288 | gfc_current_form = gfc_option.source_form; | |
289 | else | |
290 | { | |
291 | gfc_current_form = form_from_filename (filename); | |
292 | ||
293 | if (gfc_current_form == FORM_UNKNOWN) | |
294 | { | |
295 | gfc_current_form = FORM_FREE; | |
db30e21c | 296 | gfc_warning_now (0, "Reading file %qs as free form", |
4daa149b | 297 | (filename[0] == '\0') ? "<stdin>" : filename); |
e0bcf78c TS |
298 | } |
299 | } | |
300 | ||
301 | /* If the user specified -fd-lines-as-{code|comments} verify that we're | |
302 | in fixed form. */ | |
303 | if (gfc_current_form == FORM_FREE) | |
304 | { | |
305 | if (gfc_option.flag_d_lines == 0) | |
db30e21c | 306 | gfc_warning_now (0, "%<-fd-lines-as-comments%> has no effect " |
a56abdcc | 307 | "in free form"); |
e0bcf78c | 308 | else if (gfc_option.flag_d_lines == 1) |
db30e21c | 309 | gfc_warning_now (0, "%<-fd-lines-as-code%> has no effect in free form"); |
aecfd035 TB |
310 | |
311 | if (warn_line_truncation == -1) | |
312 | warn_line_truncation = 1; | |
313 | ||
314 | /* Enable -Werror=line-truncation when -Werror and -Wno-error have | |
315 | not been set. */ | |
316 | if (warn_line_truncation && !global_options_set.x_warnings_are_errors | |
317 | && (global_dc->classify_diagnostic[OPT_Wline_truncation] == | |
318 | DK_UNSPECIFIED)) | |
319 | diagnostic_classify_diagnostic (global_dc, OPT_Wline_truncation, | |
320 | DK_ERROR, UNKNOWN_LOCATION); | |
e0bcf78c | 321 | } |
aecfd035 TB |
322 | else if (warn_line_truncation == -1) |
323 | warn_line_truncation = 0; | |
6de9cd9a | 324 | |
fc2d8429 RS |
325 | /* If -pedantic, warn about the use of GNU extensions. */ |
326 | if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0) | |
327 | gfc_option.warn_std |= GFC_STD_GNU; | |
c0309c74 RS |
328 | /* -std=legacy -pedantic is effectively -std=gnu. */ |
329 | if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0) | |
330 | gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY; | |
fc2d8429 | 331 | |
973ff4c0 TS |
332 | /* If the user didn't explicitly specify -f(no)-second-underscore we |
333 | use it if we're trying to be compatible with f2c, and not | |
334 | otherwise. */ | |
203c7ebf | 335 | if (flag_second_underscore == -1) |
c61819ff | 336 | flag_second_underscore = flag_f2c; |
973ff4c0 | 337 | |
c61819ff | 338 | if (!flag_automatic && flag_max_stack_var_size != -2 |
203c7ebf | 339 | && flag_max_stack_var_size != 0) |
db30e21c | 340 | gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-fmax-stack-var-size=%d%>", |
203c7ebf | 341 | flag_max_stack_var_size); |
c61819ff | 342 | else if (!flag_automatic && flag_recursive) |
db30e21c | 343 | gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%>"); |
c61819ff | 344 | else if (!flag_automatic && flag_openmp) |
db30e21c | 345 | gfc_warning_now (0, "Flag %<-fno-automatic%> overwrites %<-frecursive%> implied by " |
203c7ebf | 346 | "%<-fopenmp%>"); |
c61819ff | 347 | else if (flag_max_stack_var_size != -2 && flag_recursive) |
db30e21c | 348 | gfc_warning_now (0, "Flag %<-frecursive%> overwrites %<-fmax-stack-var-size=%d%>", |
203c7ebf | 349 | flag_max_stack_var_size); |
c61819ff | 350 | else if (flag_max_stack_var_size != -2 && flag_openmp) |
db30e21c | 351 | gfc_warning_now (0, "Flag %<-fmax-stack-var-size=%d%> overwrites %<-frecursive%> " |
203c7ebf | 352 | "implied by %<-fopenmp%>", flag_max_stack_var_size); |
1e7de83b | 353 | |
653f6dc5 | 354 | /* Implement -frecursive as -fmax-stack-var-size=-1. */ |
c61819ff | 355 | if (flag_recursive) |
203c7ebf | 356 | flag_max_stack_var_size = -1; |
1e7de83b | 357 | |
653f6dc5 | 358 | /* Implied -frecursive; implemented as -fmax-stack-var-size=-1. */ |
c61819ff | 359 | if (flag_max_stack_var_size == -2 && flag_openmp && flag_automatic) |
653f6dc5 | 360 | { |
c61819ff | 361 | flag_recursive = 1; |
203c7ebf | 362 | flag_max_stack_var_size = -1; |
653f6dc5 TB |
363 | } |
364 | ||
1e7de83b | 365 | /* Set default. */ |
203c7ebf TB |
366 | if (flag_max_stack_var_size == -2) |
367 | flag_max_stack_var_size = 32768; | |
1e7de83b | 368 | |
d05d9ac7 | 369 | /* Implement -fno-automatic as -fmax-stack-var-size=0. */ |
c61819ff | 370 | if (!flag_automatic) |
203c7ebf | 371 | flag_max_stack_var_size = 0; |
3fbab549 | 372 | |
f1abbf69 TK |
373 | /* If we call BLAS directly, only inline up to the BLAS limit. */ |
374 | ||
375 | if (flag_external_blas && flag_inline_matmul_limit < 0) | |
376 | flag_inline_matmul_limit = flag_blas_matmul_limit; | |
377 | ||
51a30b32 TK |
378 | /* Optimization implies front end optimization, unless the user |
379 | specified it directly. */ | |
380 | ||
203c7ebf TB |
381 | if (flag_frontend_optimize == -1) |
382 | flag_frontend_optimize = optimize; | |
383 | ||
c61819ff TB |
384 | if (flag_max_array_constructor < 65535) |
385 | flag_max_array_constructor = 65535; | |
386 | ||
203c7ebf TB |
387 | if (flag_fixed_line_length != 0 && flag_fixed_line_length < 7) |
388 | gfc_fatal_error ("Fixed line length must be at least seven"); | |
389 | ||
390 | if (flag_free_line_length != 0 && flag_free_line_length < 4) | |
391 | gfc_fatal_error ("Free line length must be at least three"); | |
392 | ||
393 | if (flag_max_subrecord_length > MAX_SUBRECORD_LENGTH) | |
394 | gfc_fatal_error ("Maximum subrecord length cannot exceed %d", | |
395 | MAX_SUBRECORD_LENGTH); | |
51a30b32 | 396 | |
670637ee DF |
397 | gfc_cpp_post_options (); |
398 | ||
de3aebff JJ |
399 | if (gfc_option.allow_std & GFC_STD_F2008) |
400 | lang_hooks.name = "GNU Fortran2008"; | |
401 | else if (gfc_option.allow_std & GFC_STD_F2003) | |
402 | lang_hooks.name = "GNU Fortran2003"; | |
403 | ||
566916e6 | 404 | return gfc_cpp_preprocess_only (); |
6de9cd9a DN |
405 | } |
406 | ||
407 | ||
6de9cd9a DN |
408 | static void |
409 | gfc_handle_module_path_options (const char *arg) | |
410 | { | |
411 | ||
412 | if (gfc_option.module_dir != NULL) | |
ddc05d11 | 413 | gfc_fatal_error ("gfortran: Only one %<-J%> option allowed"); |
6de9cd9a | 414 | |
93acb62c | 415 | gfc_option.module_dir = XCNEWVEC (char, strlen (arg) + 2); |
6de9cd9a | 416 | strcpy (gfc_option.module_dir, arg); |
7376d710 | 417 | |
308f961b | 418 | gfc_add_include_path (gfc_option.module_dir, true, false, true); |
22b00a9f TB |
419 | |
420 | strcat (gfc_option.module_dir, "/"); | |
6de9cd9a DN |
421 | } |
422 | ||
edf1eac2 | 423 | |
fa86f4f9 TB |
424 | /* Handle options -ffpe-trap= and -ffpe-summary=. */ |
425 | ||
944b8b35 | 426 | static void |
fa86f4f9 | 427 | gfc_handle_fpe_option (const char *arg, bool trap) |
944b8b35 FXC |
428 | { |
429 | int result, pos = 0, n; | |
57b4d355 | 430 | /* precision is a backwards compatibility alias for inexact. */ |
944b8b35 | 431 | static const char * const exception[] = { "invalid", "denormal", "zero", |
edf1eac2 | 432 | "overflow", "underflow", |
57b4d355 | 433 | "inexact", "precision", NULL }; |
944b8b35 FXC |
434 | static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL, |
435 | GFC_FPE_ZERO, GFC_FPE_OVERFLOW, | |
57b4d355 JB |
436 | GFC_FPE_UNDERFLOW, GFC_FPE_INEXACT, |
437 | GFC_FPE_INEXACT, | |
944b8b35 | 438 | 0 }; |
fa86f4f9 | 439 | |
1cc0e193 | 440 | /* As the default for -ffpe-summary= is nonzero, set it to 0. */ |
fa86f4f9 TB |
441 | if (!trap) |
442 | gfc_option.fpe_summary = 0; | |
443 | ||
944b8b35 FXC |
444 | while (*arg) |
445 | { | |
446 | while (*arg == ',') | |
447 | arg++; | |
edf1eac2 | 448 | |
944b8b35 FXC |
449 | while (arg[pos] && arg[pos] != ',') |
450 | pos++; | |
edf1eac2 | 451 | |
944b8b35 | 452 | result = 0; |
fa86f4f9 | 453 | if (!trap && strncmp ("none", arg, pos) == 0) |
944b8b35 | 454 | { |
fa86f4f9 TB |
455 | gfc_option.fpe_summary = 0; |
456 | arg += pos; | |
457 | pos = 0; | |
458 | continue; | |
459 | } | |
460 | else if (!trap && strncmp ("all", arg, pos) == 0) | |
461 | { | |
462 | gfc_option.fpe_summary = GFC_FPE_INVALID | GFC_FPE_DENORMAL | |
463 | | GFC_FPE_ZERO | GFC_FPE_OVERFLOW | |
464 | | GFC_FPE_UNDERFLOW | GFC_FPE_INEXACT; | |
465 | arg += pos; | |
466 | pos = 0; | |
467 | continue; | |
468 | } | |
469 | else | |
470 | for (n = 0; exception[n] != NULL; n++) | |
471 | { | |
944b8b35 FXC |
472 | if (exception[n] && strncmp (exception[n], arg, pos) == 0) |
473 | { | |
fa86f4f9 TB |
474 | if (trap) |
475 | gfc_option.fpe |= opt_exception[n]; | |
476 | else | |
477 | gfc_option.fpe_summary |= opt_exception[n]; | |
944b8b35 FXC |
478 | arg += pos; |
479 | pos = 0; | |
480 | result = 1; | |
481 | break; | |
482 | } | |
fa86f4f9 TB |
483 | } |
484 | if (!result && !trap) | |
ddc05d11 | 485 | gfc_fatal_error ("Argument to %<-ffpe-trap%> is not valid: %s", arg); |
fa86f4f9 | 486 | else if (!result) |
ddc05d11 | 487 | gfc_fatal_error ("Argument to %<-ffpe-summary%> is not valid: %s", arg); |
fa86f4f9 | 488 | |
944b8b35 FXC |
489 | } |
490 | } | |
491 | ||
edf1eac2 | 492 | |
d3d3011f FXC |
493 | static void |
494 | gfc_handle_runtime_check_option (const char *arg) | |
495 | { | |
496 | int result, pos = 0, n; | |
497 | static const char * const optname[] = { "all", "bounds", "array-temps", | |
22bdbb0f TB |
498 | "recursion", "do", "pointer", |
499 | "mem", NULL }; | |
d3d3011f FXC |
500 | static const int optmask[] = { GFC_RTCHECK_ALL, GFC_RTCHECK_BOUNDS, |
501 | GFC_RTCHECK_ARRAY_TEMPS, | |
33abc845 | 502 | GFC_RTCHECK_RECURSION, GFC_RTCHECK_DO, |
22bdbb0f | 503 | GFC_RTCHECK_POINTER, GFC_RTCHECK_MEM, |
d3d3011f FXC |
504 | 0 }; |
505 | ||
506 | while (*arg) | |
507 | { | |
508 | while (*arg == ',') | |
509 | arg++; | |
510 | ||
511 | while (arg[pos] && arg[pos] != ',') | |
512 | pos++; | |
513 | ||
514 | result = 0; | |
515 | for (n = 0; optname[n] != NULL; n++) | |
516 | { | |
517 | if (optname[n] && strncmp (optname[n], arg, pos) == 0) | |
518 | { | |
519 | gfc_option.rtcheck |= optmask[n]; | |
520 | arg += pos; | |
521 | pos = 0; | |
522 | result = 1; | |
523 | break; | |
524 | } | |
525 | } | |
526 | if (!result) | |
ddc05d11 | 527 | gfc_fatal_error ("Argument to %<-fcheck%> is not valid: %s", arg); |
d3d3011f FXC |
528 | } |
529 | } | |
530 | ||
531 | ||
6de9cd9a DN |
532 | /* Handle command-line options. Returns 0 if unrecognized, 1 if |
533 | recognized and handled. */ | |
edf1eac2 | 534 | |
5f20c657 | 535 | bool |
3734d960 | 536 | gfc_handle_option (size_t scode, const char *arg, int value, |
a4d8c676 | 537 | int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED, |
5f20c657 | 538 | const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED) |
6de9cd9a | 539 | { |
5f20c657 | 540 | bool result = true; |
6de9cd9a DN |
541 | enum opt_code code = (enum opt_code) scode; |
542 | ||
670637ee | 543 | if (gfc_cpp_handle_option (scode, arg, value) == 1) |
5f20c657 | 544 | return true; |
670637ee | 545 | |
6de9cd9a DN |
546 | switch (code) |
547 | { | |
548 | default: | |
7c02f68b MLI |
549 | if (cl_options[code].flags & gfc_option_lang_mask ()) |
550 | break; | |
5f20c657 | 551 | result = false; |
6de9cd9a DN |
552 | break; |
553 | ||
0d52899f | 554 | case OPT_fcheck_array_temporaries: |
d3d3011f | 555 | gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS; |
0d52899f TB |
556 | break; |
557 | ||
e0bcf78c TS |
558 | case OPT_fd_lines_as_code: |
559 | gfc_option.flag_d_lines = 1; | |
560 | break; | |
561 | ||
562 | case OPT_fd_lines_as_comments: | |
563 | gfc_option.flag_d_lines = 0; | |
564 | break; | |
565 | ||
6de9cd9a DN |
566 | case OPT_ffixed_form: |
567 | gfc_option.source_form = FORM_FIXED; | |
568 | break; | |
569 | ||
570 | case OPT_ffree_form: | |
571 | gfc_option.source_form = FORM_FREE; | |
572 | break; | |
573 | ||
86db887a FXC |
574 | case OPT_static_libgfortran: |
575 | #ifndef HAVE_LD_STATIC_DYNAMIC | |
ddc05d11 | 576 | gfc_fatal_error ("%<-static-libgfortran%> is not supported in this " |
86db887a FXC |
577 | "configuration"); |
578 | #endif | |
579 | break; | |
580 | ||
31198773 | 581 | case OPT_fintrinsic_modules_path: |
f34dea03 | 582 | case OPT_fintrinsic_modules_path_: |
308f961b TK |
583 | |
584 | /* This is needed because omp_lib.h is in a directory together | |
585 | with intrinsic modules. Do no warn because during testing | |
586 | without an installed compiler, we would get lots of bogus | |
587 | warnings for a missing include directory. */ | |
588 | gfc_add_include_path (arg, false, false, false); | |
589 | ||
31198773 FXC |
590 | gfc_add_intrinsic_modules_path (arg); |
591 | break; | |
592 | ||
2d7c7df6 JJ |
593 | case OPT_fpreprocessed: |
594 | gfc_option.flag_preprocessed = value; | |
595 | break; | |
596 | ||
6de9cd9a DN |
597 | case OPT_fmax_identifier_length_: |
598 | if (value > GFC_MAX_SYMBOL_LEN) | |
eb6d74fa | 599 | gfc_fatal_error ("Maximum supported identifier length is %d", |
6de9cd9a DN |
600 | GFC_MAX_SYMBOL_LEN); |
601 | gfc_option.max_identifier_length = value; | |
602 | break; | |
603 | ||
51b09ce3 AL |
604 | case OPT_finit_local_zero: |
605 | gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON; | |
606 | gfc_option.flag_init_integer_value = 0; | |
f19626cf | 607 | flag_init_real = GFC_INIT_REAL_ZERO; |
51b09ce3 AL |
608 | gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE; |
609 | gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON; | |
610 | gfc_option.flag_init_character_value = (char)0; | |
611 | break; | |
612 | ||
613 | case OPT_finit_logical_: | |
614 | if (!strcasecmp (arg, "false")) | |
615 | gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE; | |
616 | else if (!strcasecmp (arg, "true")) | |
617 | gfc_option.flag_init_logical = GFC_INIT_LOGICAL_TRUE; | |
618 | else | |
ddc05d11 | 619 | gfc_fatal_error ("Unrecognized option to %<-finit-logical%>: %s", |
51b09ce3 AL |
620 | arg); |
621 | break; | |
622 | ||
51b09ce3 AL |
623 | case OPT_finit_integer_: |
624 | gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON; | |
625 | gfc_option.flag_init_integer_value = atoi (arg); | |
626 | break; | |
627 | ||
628 | case OPT_finit_character_: | |
629 | if (value >= 0 && value <= 127) | |
630 | { | |
631 | gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON; | |
632 | gfc_option.flag_init_character_value = (char)value; | |
633 | } | |
634 | else | |
ddc05d11 | 635 | gfc_fatal_error ("The value of n in %<-finit-character=n%> must be " |
51b09ce3 AL |
636 | "between 0 and 127"); |
637 | break; | |
638 | ||
6de9cd9a | 639 | case OPT_I: |
308f961b | 640 | gfc_add_include_path (arg, true, false, true); |
6de9cd9a DN |
641 | break; |
642 | ||
643 | case OPT_J: | |
6de9cd9a | 644 | gfc_handle_module_path_options (arg); |
2d0b4bcd | 645 | break; |
ccc2ed87 | 646 | |
944b8b35 | 647 | case OPT_ffpe_trap_: |
fa86f4f9 TB |
648 | gfc_handle_fpe_option (arg, true); |
649 | break; | |
650 | ||
651 | case OPT_ffpe_summary_: | |
652 | gfc_handle_fpe_option (arg, false); | |
944b8b35 FXC |
653 | break; |
654 | ||
6de9cd9a | 655 | case OPT_std_f95: |
58fc89f6 TB |
656 | gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77 |
657 | | GFC_STD_F2008_OBS; | |
6de9cd9a | 658 | gfc_option.warn_std = GFC_STD_F95_OBS; |
dfbfb630 JD |
659 | gfc_option.max_continue_fixed = 19; |
660 | gfc_option.max_continue_free = 39; | |
6de9cd9a | 661 | gfc_option.max_identifier_length = 31; |
73e42eef | 662 | warn_ampersand = 1; |
16db2a6a | 663 | warn_tabs = 1; |
6de9cd9a DN |
664 | break; |
665 | ||
666 | case OPT_std_f2003: | |
b7892582 | 667 | gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77 |
58fc89f6 | 668 | | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008_OBS; |
b7892582 | 669 | gfc_option.warn_std = GFC_STD_F95_OBS; |
6de9cd9a | 670 | gfc_option.max_identifier_length = 63; |
73e42eef | 671 | warn_ampersand = 1; |
16db2a6a | 672 | warn_tabs = 1; |
6de9cd9a DN |
673 | break; |
674 | ||
f489fba1 FXC |
675 | case OPT_std_f2008: |
676 | gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77 | |
58fc89f6 TB |
677 | | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS; |
678 | gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS; | |
f489fba1 | 679 | gfc_option.max_identifier_length = 63; |
73e42eef | 680 | warn_ampersand = 1; |
16db2a6a | 681 | warn_tabs = 1; |
f489fba1 FXC |
682 | break; |
683 | ||
4650947d | 684 | case OPT_std_f2008ts: |
2e8d9212 TB |
685 | gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77 |
686 | | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F2008 | GFC_STD_F2008_OBS | |
4650947d | 687 | | GFC_STD_F2008_TS; |
2e8d9212 TB |
688 | gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F2008_OBS; |
689 | gfc_option.max_identifier_length = 63; | |
73e42eef | 690 | warn_ampersand = 1; |
16db2a6a | 691 | warn_tabs = 1; |
2e8d9212 TB |
692 | break; |
693 | ||
6de9cd9a | 694 | case OPT_std_gnu: |
a47eec17 | 695 | set_default_std_flags (); |
c0309c74 RS |
696 | break; |
697 | ||
698 | case OPT_std_legacy: | |
a47eec17 | 699 | set_default_std_flags (); |
c0309c74 | 700 | gfc_option.warn_std = 0; |
b7892582 JB |
701 | break; |
702 | ||
25d8f0a2 | 703 | case OPT_fshort_enums: |
5498f011 | 704 | /* Handled in language-independent code. */ |
25d8f0a2 | 705 | break; |
eaa90d25 | 706 | |
d3d3011f FXC |
707 | case OPT_fcheck_: |
708 | gfc_handle_runtime_check_option (arg); | |
709 | break; | |
6de9cd9a DN |
710 | } |
711 | ||
f2bc201f MLI |
712 | Fortran_handle_option_auto (&global_options, &global_options_set, |
713 | scode, arg, value, | |
714 | gfc_option_lang_mask (), kind, | |
715 | loc, handlers, global_dc); | |
6de9cd9a DN |
716 | return result; |
717 | } | |
41804a5b TB |
718 | |
719 | ||
720 | /* Return a string with the options passed to the compiler; used for | |
721 | Fortran's compiler_options() intrinsic. */ | |
722 | ||
723 | char * | |
724 | gfc_get_option_string (void) | |
725 | { | |
726 | unsigned j; | |
727 | size_t len, pos; | |
728 | char *result; | |
729 | ||
58b2a358 TB |
730 | /* Allocate and return a one-character string with '\0'. */ |
731 | if (!save_decoded_options_count) | |
732 | return XCNEWVEC (char, 1); | |
733 | ||
41804a5b TB |
734 | /* Determine required string length. */ |
735 | ||
736 | len = 0; | |
737 | for (j = 1; j < save_decoded_options_count; j++) | |
738 | { | |
739 | switch (save_decoded_options[j].opt_index) | |
740 | { | |
741 | case OPT_o: | |
742 | case OPT_d: | |
743 | case OPT_dumpbase: | |
744 | case OPT_dumpdir: | |
745 | case OPT_auxbase: | |
746 | case OPT_quiet: | |
747 | case OPT_version: | |
748 | case OPT_fintrinsic_modules_path: | |
f34dea03 | 749 | case OPT_fintrinsic_modules_path_: |
41804a5b TB |
750 | /* Ignore these. */ |
751 | break; | |
752 | default: | |
1cc0e193 | 753 | /* Ignore file names. */ |
41804a5b TB |
754 | if (save_decoded_options[j].orig_option_with_args_text[0] == '-') |
755 | len += 1 | |
756 | + strlen (save_decoded_options[j].orig_option_with_args_text); | |
757 | } | |
758 | } | |
759 | ||
93acb62c | 760 | result = XCNEWVEC (char, len); |
41804a5b TB |
761 | |
762 | pos = 0; | |
763 | for (j = 1; j < save_decoded_options_count; j++) | |
764 | { | |
765 | switch (save_decoded_options[j].opt_index) | |
766 | { | |
767 | case OPT_o: | |
768 | case OPT_d: | |
769 | case OPT_dumpbase: | |
770 | case OPT_dumpdir: | |
771 | case OPT_auxbase: | |
772 | case OPT_quiet: | |
773 | case OPT_version: | |
774 | case OPT_fintrinsic_modules_path: | |
f34dea03 | 775 | case OPT_fintrinsic_modules_path_: |
41804a5b TB |
776 | /* Ignore these. */ |
777 | continue; | |
778 | ||
779 | case OPT_cpp_: | |
780 | /* Use "-cpp" rather than "-cpp=<temporary file>". */ | |
781 | len = 4; | |
782 | break; | |
783 | ||
784 | default: | |
1cc0e193 | 785 | /* Ignore file names. */ |
41804a5b TB |
786 | if (save_decoded_options[j].orig_option_with_args_text[0] != '-') |
787 | continue; | |
788 | ||
789 | len = strlen (save_decoded_options[j].orig_option_with_args_text); | |
790 | } | |
791 | ||
792 | memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len); | |
793 | pos += len; | |
794 | result[pos++] = ' '; | |
795 | } | |
796 | ||
797 | result[--pos] = '\0'; | |
798 | return result; | |
799 | } |