]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/opts.h
Update copyright years.
[thirdparty/gcc.git] / gcc / opts.h
CommitLineData
2772ef3e 1/* Command line option handling.
8d9254fc 2 Copyright (C) 2002-2020 Free Software Foundation, Inc.
2772ef3e
NB
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
2772ef3e
NB
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
2772ef3e
NB
19
20#ifndef GCC_OPTS_H
21#define GCC_OPTS_H
22
dc357798 23#include "obstack.h"
a4d8c676 24
75685792 25/* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
55bea00a 26enum cl_var_type {
75685792
RS
27 /* The switch is enabled when FLAG_VAR is nonzero. */
28 CLVC_BOOLEAN,
29
30 /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
31 CLVC_EQUAL,
32
33 /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
34 CLVC_BIT_CLEAR,
35
36 /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
55bea00a
RS
37 CLVC_BIT_SET,
38
00abf86c
MS
39 /* The switch is enabled when FLAG_VAR is less than HOST_WIDE_INT_M1U. */
40 CLVC_SIZE,
41
55bea00a
RS
42 /* The switch takes a string argument and FLAG_VAR points to that
43 argument. */
21bf1558
JM
44 CLVC_STRING,
45
e6d4b984
JM
46 /* The switch takes an enumerated argument (VAR_ENUM says what
47 enumeration) and FLAG_VAR points to that argument. */
48 CLVC_ENUM,
49
21bf1558
JM
50 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
51 later processing. */
52 CLVC_DEFER
75685792 53};
2772ef3e 54
35399bdc
NB
55struct cl_option
56{
300d83d9 57 /* Text of the option, including initial '-'. */
35399bdc 58 const char *opt_text;
300d83d9 59 /* Help text for --help, or NULL. */
cf03fd63 60 const char *help;
300d83d9 61 /* Error message for missing argument, or NULL. */
61ff2bdc 62 const char *missing_argument_error;
300d83d9 63 /* Warning to give when this option is used, or NULL. */
2d2bd949 64 const char *warn_message;
300d83d9 65 /* Argument of alias target when positive option given, or NULL. */
5de8299c 66 const char *alias_arg;
300d83d9 67 /* Argument of alias target when negative option given, or NULL. */
5de8299c 68 const char *neg_alias_arg;
300d83d9 69 /* Alias target, or N_OPTS if not an alias. */
5de8299c 70 unsigned short alias_target;
300d83d9
JM
71 /* Previous option that is an initial substring of this one, or
72 N_OPTS if none. */
9cd23ed2 73 unsigned short back_chain;
300d83d9 74 /* Option length, not including initial '-'. */
35399bdc 75 unsigned char opt_len;
00abf86c
MS
76 /* Next option in a sequence marked with Negative, or -1 if none.
77 For a single option with both a negative and a positve form
78 (such as -Wall and -Wno-all), NEG_IDX is equal to the option's
79 own index (i.e., cl_options[IDX].neg_idx == IDX holds). */
14c7833c 80 int neg_index;
300d83d9 81 /* CL_* flags for this option. */
d7b42618 82 unsigned int flags;
300d83d9
JM
83 /* Disabled in this configuration. */
84 BOOL_BITFIELD cl_disabled : 1;
85 /* Options marked with CL_SEPARATE take a number of separate
86 arguments (1 to 4) that is one more than the number in this
87 bit-field. */
88 unsigned int cl_separate_nargs : 2;
89 /* Option is an alias when used with separate argument. */
90 BOOL_BITFIELD cl_separate_alias : 1;
91 /* Alias to negative form of option. */
92 BOOL_BITFIELD cl_negative_alias : 1;
93 /* Option takes no argument in the driver. */
94 BOOL_BITFIELD cl_no_driver_arg : 1;
95 /* Reject this option in the driver. */
96 BOOL_BITFIELD cl_reject_driver : 1;
97 /* Reject no- form. */
98 BOOL_BITFIELD cl_reject_negative : 1;
99 /* Missing argument OK (joined). */
100 BOOL_BITFIELD cl_missing_ok : 1;
101 /* Argument is an integer >=0. */
102 BOOL_BITFIELD cl_uinteger : 1;
99114bbf
L
103 /* Argument is a HOST_WIDE_INT. */
104 BOOL_BITFIELD cl_host_wide_int : 1;
413519ae
JM
105 /* Argument should be converted to lowercase. */
106 BOOL_BITFIELD cl_tolower : 1;
300d83d9
JM
107 /* Report argument with -fverbose-asm */
108 BOOL_BITFIELD cl_report : 1;
00abf86c
MS
109 /* Argument is an unsigned integer with an optional byte suffix. */
110 BOOL_BITFIELD cl_byte_size: 1;
300d83d9
JM
111 /* Offset of field for this option in struct gcc_options, or
112 (unsigned short) -1 if none. */
46625112 113 unsigned short flag_var_offset;
300d83d9
JM
114 /* Index in cl_enums of enum used for this option's arguments, for
115 CLVC_ENUM options. */
e6d4b984 116 unsigned short var_enum;
300d83d9 117 /* How this option's value is determined and sets a field. */
55bea00a 118 enum cl_var_type var_type;
300d83d9 119 /* Value or bit-mask with which to set a field. */
99114bbf 120 HOST_WIDE_INT var_value;
63010089
ML
121 /* Range info minimum, or -1. */
122 int range_min;
123 /* Range info maximum, or -1. */
124 int range_max;
35399bdc
NB
125};
126
5c60a017
RS
127/* Records that the state of an option consists of SIZE bytes starting
128 at DATA. DATA might point to CH in some cases. */
129struct cl_option_state {
130 const void *data;
131 size_t size;
132 char ch;
133};
134
35399bdc
NB
135extern const struct cl_option cl_options[];
136extern const unsigned int cl_options_count;
f18754d6 137extern const char *const lang_names[];
c662432e 138extern const unsigned int cl_lang_count;
35399bdc 139
58265ea6
GF
140#define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
141#define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
142#define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
143#define CL_DRIVER (1U << 19) /* Driver option. */
144#define CL_TARGET (1U << 20) /* Target-specific option. */
145#define CL_COMMON (1U << 21) /* Language-independent. */
a1fd13d0
JJ
146
147#define CL_MIN_OPTION_CLASS CL_PARAMS
c662432e
NC
148#define CL_MAX_OPTION_CLASS CL_COMMON
149
150/* From here on the bits describe attributes of the options.
151 Before this point the bits have described the class of the option.
152 This distinction is important because --help will not list options
153 which only have these higher bits set. */
154
58265ea6
GF
155#define CL_JOINED (1U << 22) /* If takes joined argument. */
156#define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
157#define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
77ee7190 158#define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
212bfe71 159#define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
2772ef3e 160
e6d4b984
JM
161/* Flags for an enumerated option argument. */
162#define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
163#define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
164
165/* Structure describing an enumerated option argument. */
166
167struct cl_enum_arg
168{
169 /* The argument text, or NULL at the end of the array. */
170 const char *arg;
171
172 /* The corresponding integer value. */
173 int value;
174
175 /* Flags associated with this argument. */
176 unsigned int flags;
177};
178
179/* Structure describing an enumerated set of option arguments. */
180
181struct cl_enum
182{
183 /* Help text, or NULL if the values should not be listed in --help
184 output. */
185 const char *help;
186
187 /* Error message for unknown arguments, or NULL to use a generic
188 error. */
189 const char *unknown_error;
190
191 /* Array of possible values. */
192 const struct cl_enum_arg *values;
193
194 /* The size of the type used to store a value. */
195 size_t var_size;
196
197 /* Function to set a variable of this type. */
198 void (*set) (void *var, int value);
199
200 /* Function to get the value of a variable of this type. */
201 int (*get) (const void *var);
202};
203
204extern const struct cl_enum cl_enums[];
205extern const unsigned int cl_enums_count;
206
5d4b393f
JM
207/* Possible ways in which a command-line option may be erroneous.
208 These do not include not being known at all; an option index of
6e2f1956 209 OPT_SPECIAL_unknown is used for that. */
5d4b393f
JM
210
211#define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
212#define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
213#define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
214#define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
63010089
ML
215#define CL_ERR_INT_RANGE_ARG (1 << 4) /* Bad unsigned integer argument. */
216#define CL_ERR_ENUM_ARG (1 << 5) /* Bad enumerated argument. */
217#define CL_ERR_NEGATIVE (1 << 6) /* Negative form of option
184eb658
JM
218 not permitted (together
219 with OPT_SPECIAL_unknown). */
5d4b393f
JM
220
221/* Structure describing the result of decoding an option. */
222
223struct cl_decoded_option
224{
6e2f1956
JM
225 /* The index of this option, or an OPT_SPECIAL_* value for
226 non-options and unknown options. */
5d4b393f
JM
227 size_t opt_index;
228
2d2bd949
JM
229 /* Any warning to give for use of this option, or NULL if none. */
230 const char *warn_message;
231
6e2f1956
JM
232 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
233 the option or non-option command-line argument. */
5d4b393f
JM
234 const char *arg;
235
6e2f1956
JM
236 /* The original text of option plus arguments, with separate argv
237 elements concatenated into one string with spaces separating
238 them. This is for such uses as diagnostics and
239 -frecord-gcc-switches. */
240 const char *orig_option_with_args_text;
241
7a9bf9a4
JM
242 /* The canonical form of the option and its argument, for when it is
243 necessary to reconstruct argv elements (in particular, for
244 processing specs and passing options to subprocesses from the
eea13ead
JM
245 driver). */
246 const char *canonical_option[4];
247
248 /* The number of elements in the canonical form of the option and
249 arguments; always at least 1. */
250 size_t canonical_option_num_elements;
7a9bf9a4 251
5d4b393f
JM
252 /* For a boolean option, 1 for the true case and 0 for the "no-"
253 case. For an unsigned integer option, the value of the
254 argument. 1 in all other cases. */
00abf86c 255 HOST_WIDE_INT value;
5d4b393f
JM
256
257 /* Any flags describing errors detected in this option. */
258 int errors;
259};
260
21bf1558
JM
261/* Structure describing an option deferred for handling after the main
262 option handlers. */
263
84562394 264struct cl_deferred_option
21bf1558
JM
265{
266 /* Elements from struct cl_decoded_option used for deferred
267 options. */
268 size_t opt_index;
269 const char *arg;
270 int value;
84562394 271};
21bf1558 272
5f20c657
JM
273/* Structure describing a single option-handling callback. */
274
275struct cl_option_handler_func
276{
277 /* The function called to handle the option. */
46625112 278 bool (*handler) (struct gcc_options *opts,
d4d24ba4 279 struct gcc_options *opts_set,
46625112 280 const struct cl_decoded_option *decoded,
a4d8c676 281 unsigned int lang_mask, int kind, location_t loc,
d5478783 282 const struct cl_option_handlers *handlers,
130fcab0
ML
283 diagnostic_context *dc,
284 void (*target_option_override_hook) (void));
5f20c657
JM
285
286 /* The mask that must have some bit in common with the flags for the
287 option for this particular handler to be used. */
288 unsigned int mask;
289};
290
291/* Structure describing the callbacks used in handling options. */
292
293struct cl_option_handlers
294{
295 /* Callback for an unknown option to determine whether to give an
296 error for it, and possibly store information to diagnose the
297 option at a later point. Return true if an error should be
298 given, false otherwise. */
481e1176 299 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
5f20c657
JM
300
301 /* Callback to handle, and possibly diagnose, an option for another
302 language. */
481e1176 303 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
5f20c657
JM
304 unsigned int lang_mask);
305
130fcab0
ML
306 /* Target option override hook. */
307 void (*target_option_override_hook) (void);
308
5f20c657
JM
309 /* The number of individual handlers. */
310 size_t num_handlers;
311
312 /* The handlers themselves. */
313 struct cl_option_handler_func handlers[3];
314};
315
ecf835e9
KN
316/* Hold command-line options associated with stack limitation. */
317extern const char *opt_fstack_limit_symbol_arg;
318extern int opt_fstack_limit_register_no;
319
59e4e217 320/* Input file names. */
40e941af
PB
321
322extern const char **in_fnames;
323
59e4e217 324/* The count of input filenames. */
40e941af
PB
325
326extern unsigned num_in_fnames;
327
dc357798
JJ
328extern char *opts_concat (const char *first, ...);
329
330/* Obstack for option strings. */
331
332extern struct obstack opts_obstack;
333
eb50f63a 334size_t find_opt (const char *input, unsigned int lang_mask);
00abf86c 335extern HOST_WIDE_INT integral_argument (const char *arg, int * = NULL, bool = false);
e6d4b984
JM
336extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
337 const char **argp, int value,
338 unsigned int lang_mask);
6e2f1956
JM
339extern void decode_cmdline_options_to_array (unsigned int argc,
340 const char **argv,
341 unsigned int lang_mask,
342 struct cl_decoded_option **decoded_options,
343 unsigned int *decoded_options_count);
a75bfaa6
JM
344extern void init_options_once (void);
345extern void init_options_struct (struct gcc_options *opts,
346 struct gcc_options *opts_set);
de5672fc 347extern void init_opts_obstack (void);
a75bfaa6
JM
348extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
349 const char **argv,
350 struct cl_decoded_option **decoded_options,
351 unsigned int *decoded_options_count);
130fcab0
ML
352extern void set_default_handlers (struct cl_option_handlers *handlers,
353 void (*target_option_override_hook) (void));
a75bfaa6
JM
354extern void decode_options (struct gcc_options *opts,
355 struct gcc_options *opts_set,
356 struct cl_decoded_option *decoded_options,
d5478783 357 unsigned int decoded_options_count,
a4d8c676 358 location_t loc,
130fcab0
ML
359 diagnostic_context *dc,
360 void (*target_option_override_hook) (void));
fa5baeed
MS
361extern int option_enabled (int opt_idx, unsigned lang_mask, void *opts);
362
46625112
JM
363extern bool get_option_state (struct gcc_options *, int,
364 struct cl_option_state *);
d4d24ba4
JM
365extern void set_option (struct gcc_options *opts,
366 struct gcc_options *opts_set,
00abf86c
MS
367 int opt_index, HOST_WIDE_INT value, const char *arg,
368 int kind, location_t loc, diagnostic_context *dc);
46625112 369extern void *option_flag_var (int opt_index, struct gcc_options *opts);
46625112 370bool handle_generated_option (struct gcc_options *opts,
d4d24ba4 371 struct gcc_options *opts_set,
00abf86c
MS
372 size_t opt_index, const char *arg,
373 HOST_WIDE_INT value,
a4d8c676 374 unsigned int lang_mask, int kind, location_t loc,
1ebe4b4f 375 const struct cl_option_handlers *handlers,
b9822443 376 bool generated_p, diagnostic_context *dc);
00abf86c 377void generate_option (size_t opt_index, const char *arg, HOST_WIDE_INT value,
d9d16a19
JM
378 unsigned int lang_mask,
379 struct cl_decoded_option *decoded);
380void generate_option_input_file (const char *file,
381 struct cl_decoded_option *decoded);
46625112 382extern void read_cmdline_option (struct gcc_options *opts,
d4d24ba4 383 struct gcc_options *opts_set,
46625112 384 struct cl_decoded_option *decoded,
a4d8c676 385 location_t loc,
5f20c657 386 unsigned int lang_mask,
1ebe4b4f
JM
387 const struct cl_option_handlers *handlers,
388 diagnostic_context *dc);
c5fa0890 389extern void control_warning_option (unsigned int opt_index, int kind,
63bbf46d 390 const char *arg, bool imply, location_t loc,
c5fa0890
JM
391 unsigned int lang_mask,
392 const struct cl_option_handlers *handlers,
393 struct gcc_options *opts,
394 struct gcc_options *opts_set,
395 diagnostic_context *dc);
c1822f9c 396extern char *write_langs (unsigned int mask);
369dcbd9 397extern void print_ignored_options (void);
21bf1558 398extern void handle_common_deferred_options (void);
b1b46af0
JJ
399unsigned int parse_sanitizer_options (const char *, location_t, int,
400 unsigned int, int, bool);
45b2222a 401
3a266bcd 402unsigned int parse_no_sanitize_attribute (char *value);
c98cd5bf
JM
403extern bool common_handle_option (struct gcc_options *opts,
404 struct gcc_options *opts_set,
405 const struct cl_decoded_option *decoded,
406 unsigned int lang_mask, int kind,
407 location_t loc,
408 const struct cl_option_handlers *handlers,
130fcab0
ML
409 diagnostic_context *dc,
410 void (*target_option_override_hook) (void));
c98cd5bf
JM
411extern bool target_handle_option (struct gcc_options *opts,
412 struct gcc_options *opts_set,
413 const struct cl_decoded_option *decoded,
414 unsigned int lang_mask, int kind,
415 location_t loc,
416 const struct cl_option_handlers *handlers,
130fcab0
ML
417 diagnostic_context *dc,
418 void (*target_option_override_hook) (void));
c98cd5bf 419extern void finish_options (struct gcc_options *opts,
299404a1 420 struct gcc_options *opts_set,
f66409e0 421 location_t loc);
bc405869
ML
422extern void print_help (struct gcc_options *opts, unsigned int lang_mask, const
423 char *help_option_argument);
c98cd5bf
JM
424extern void default_options_optimization (struct gcc_options *opts,
425 struct gcc_options *opts_set,
426 struct cl_decoded_option *decoded_options,
427 unsigned int decoded_options_count,
428 location_t loc,
429 unsigned int lang_mask,
430 const struct cl_option_handlers *handlers,
431 diagnostic_context *dc);
299404a1
JM
432extern void set_struct_debug_option (struct gcc_options *opts,
433 location_t loc,
434 const char *value);
8023568e 435extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
00abf86c
MS
436 int *value,
437 unsigned int lang_mask);
61789eed
DM
438
439extern const struct sanitizer_opts_s
440{
441 const char *const name;
442 unsigned int flag;
443 size_t len;
5cc6c41c 444 bool can_recover;
61789eed
DM
445} sanitizer_opts[];
446
bc405869 447extern vec<const char *> help_option_arguments;
f66409e0 448
61789eed 449extern void add_misspelling_candidates (auto_vec<char *> *candidates,
603107fb 450 const struct cl_option *option,
61789eed 451 const char *base_option);
14bce257
JJ
452extern const char *candidates_list_and_hint (const char *arg, char *&str,
453 const auto_vec <const char *> &
454 candidates);
61789eed 455
c518c102
ML
456
457extern bool parse_and_check_align_values (const char *flag,
458 const char *name,
459 auto_vec<unsigned> &result_values,
460 bool report_error,
461 location_t loc);
462
76c26af9
ML
463/* Set OPTION in OPTS to VALUE if the option is not set in OPTS_SET. */
464
465#define SET_OPTION_IF_UNSET(OPTS, OPTS_SET, OPTION, VALUE) \
466 do \
467 { \
468 if (!(OPTS_SET)->x_ ## OPTION) \
469 (OPTS)->x_ ## OPTION = VALUE; \
470 } \
471 while (false)
472
2772ef3e 473#endif