Add hppa*-*-hpux* to targets which do not support split DWARF
[official-gcc.git] / gcc / opts.h
blob82800b8f87cd9239c7a3b50213785d40aed49b5c
1 /* Command line option handling.
2 Copyright (C) 2002-2024 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_OPTS_H
21 #define GCC_OPTS_H
23 #include "rich-location.h"
24 #include "obstack.h"
26 /* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
27 enum cl_var_type {
28 /* The switch is an integer value. */
29 CLVC_INTEGER,
31 /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
32 CLVC_EQUAL,
34 /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
35 CLVC_BIT_CLEAR,
37 /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
38 CLVC_BIT_SET,
40 /* The switch is enabled when FLAG_VAR is less than HOST_WIDE_INT_M1U. */
41 CLVC_SIZE,
43 /* The switch takes a string argument and FLAG_VAR points to that
44 argument. */
45 CLVC_STRING,
47 /* The switch takes an enumerated argument (VAR_ENUM says what
48 enumeration) and FLAG_VAR points to that argument. */
49 CLVC_ENUM,
51 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
52 later processing. */
53 CLVC_DEFER
56 /* Values for var_value member of CLVC_ENUM. */
57 enum cl_enum_var_value {
58 /* Enum without EnumSet or EnumBitSet. */
59 CLEV_NORMAL,
61 /* EnumSet. */
62 CLEV_SET,
64 /* EnumBitSet. */
65 CLEV_BITSET
68 struct cl_option
70 /* Text of the option, including initial '-'. */
71 const char *opt_text;
72 /* Help text for --help, or NULL. */
73 const char *help;
74 /* Error message for missing argument, or NULL. */
75 const char *missing_argument_error;
76 /* Warning to give when this option is used, or NULL. */
77 const char *warn_message;
78 /* Argument of alias target when positive option given, or NULL. */
79 const char *alias_arg;
80 /* Argument of alias target when negative option given, or NULL. */
81 const char *neg_alias_arg;
82 /* Alias target, or N_OPTS if not an alias. */
83 unsigned short alias_target;
84 /* Previous option that is an initial substring of this one, or
85 N_OPTS if none. */
86 unsigned short back_chain;
87 /* Option length, not including initial '-'. */
88 unsigned char opt_len;
89 /* Next option in a sequence marked with Negative, or -1 if none.
90 For a single option with both a negative and a positve form
91 (such as -Wall and -Wno-all), NEG_IDX is equal to the option's
92 own index (i.e., cl_options[IDX].neg_idx == IDX holds). */
93 int neg_index;
94 /* CL_* flags for this option. */
95 unsigned int flags;
96 /* Disabled in this configuration. */
97 BOOL_BITFIELD cl_disabled : 1;
98 /* Options marked with CL_SEPARATE take a number of separate
99 arguments (1 to 4) that is one more than the number in this
100 bit-field. */
101 unsigned int cl_separate_nargs : 2;
102 /* Option is an alias when used with separate argument. */
103 BOOL_BITFIELD cl_separate_alias : 1;
104 /* Alias to negative form of option. */
105 BOOL_BITFIELD cl_negative_alias : 1;
106 /* Option takes no argument in the driver. */
107 BOOL_BITFIELD cl_no_driver_arg : 1;
108 /* Reject this option in the driver. */
109 BOOL_BITFIELD cl_reject_driver : 1;
110 /* Reject no- form. */
111 BOOL_BITFIELD cl_reject_negative : 1;
112 /* Missing argument OK (joined). */
113 BOOL_BITFIELD cl_missing_ok : 1;
114 /* Argument is an integer >=0. */
115 BOOL_BITFIELD cl_uinteger : 1;
116 /* Argument is a HOST_WIDE_INT. */
117 BOOL_BITFIELD cl_host_wide_int : 1;
118 /* Argument should be converted to lowercase. */
119 BOOL_BITFIELD cl_tolower : 1;
120 /* Argument is an unsigned integer with an optional byte suffix. */
121 BOOL_BITFIELD cl_byte_size: 1;
122 /* Offset of field for this option in struct gcc_options, or
123 (unsigned short) -1 if none. */
124 unsigned short flag_var_offset;
125 /* Index in cl_enums of enum used for this option's arguments, for
126 CLVC_ENUM options. */
127 unsigned short var_enum;
128 /* How this option's value is determined and sets a field. */
129 enum cl_var_type var_type;
130 /* Value or bit-mask with which to set a field. */
131 HOST_WIDE_INT var_value;
132 /* Range info minimum, or -1. */
133 int range_min;
134 /* Range info maximum, or -1. */
135 int range_max;
138 struct cl_var
140 /* Name of the variable. */
141 const char *var_name;
142 /* Offset of field for this var in struct gcc_options. */
143 unsigned short var_offset;
146 /* Records that the state of an option consists of SIZE bytes starting
147 at DATA. DATA might point to CH in some cases. */
148 struct cl_option_state {
149 const void *data;
150 size_t size;
151 char ch;
154 extern const struct cl_option cl_options[];
155 extern const unsigned int cl_options_count;
157 extern const char *
158 get_opt_url_suffix (int option_index, unsigned lang_mask);
160 #ifdef ENABLE_PLUGIN
161 extern const struct cl_var cl_vars[];
162 #endif
163 extern const char *const lang_names[];
164 extern const unsigned int cl_lang_count;
166 #define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
167 #define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
168 #define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
169 #define CL_DRIVER (1U << 19) /* Driver option. */
170 #define CL_TARGET (1U << 20) /* Target-specific option. */
171 #define CL_COMMON (1U << 21) /* Language-independent. */
173 #define CL_MIN_OPTION_CLASS CL_PARAMS
174 #define CL_MAX_OPTION_CLASS CL_COMMON
176 /* From here on the bits describe attributes of the options.
177 Before this point the bits have described the class of the option.
178 This distinction is important because --help will not list options
179 which only have these higher bits set. */
181 #define CL_JOINED (1U << 22) /* If takes joined argument. */
182 #define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
183 #define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
184 #define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
185 #define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
187 /* Flags for an enumerated option argument. */
188 #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
189 #define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
190 #define CL_ENUM_SET_SHIFT 2 /* Shift for enum set. */
192 /* Structure describing an enumerated option argument. */
194 struct cl_enum_arg
196 /* The argument text, or NULL at the end of the array. */
197 const char *arg;
199 /* The corresponding integer value. */
200 int value;
202 /* Flags associated with this argument. */
203 unsigned int flags;
206 /* Structure describing an enumerated set of option arguments. */
208 struct cl_enum
210 /* Help text, or NULL if the values should not be listed in --help
211 output. */
212 const char *help;
214 /* Error message for unknown arguments, or NULL to use a generic
215 error. */
216 const char *unknown_error;
218 /* Array of possible values. */
219 const struct cl_enum_arg *values;
221 /* The size of the type used to store a value. */
222 size_t var_size;
224 /* Function to set a variable of this type. */
225 void (*set) (void *var, int value);
227 /* Function to get the value of a variable of this type. */
228 int (*get) (const void *var);
231 extern const struct cl_enum cl_enums[];
232 extern const unsigned int cl_enums_count;
234 /* Possible ways in which a command-line option may be erroneous.
235 These do not include not being known at all; an option index of
236 OPT_SPECIAL_unknown is used for that. */
238 #define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
239 #define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
240 #define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
241 #define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
242 #define CL_ERR_INT_RANGE_ARG (1 << 4) /* Bad unsigned integer argument. */
243 #define CL_ERR_ENUM_ARG (1 << 5) /* Bad enumerated argument. */
244 #define CL_ERR_NEGATIVE (1 << 6) /* Negative form of option
245 not permitted (together
246 with OPT_SPECIAL_unknown). */
247 #define CL_ERR_ENUM_SET_ARG (1 << 7) /* Bad argument of enumerated set. */
249 /* Structure describing the result of decoding an option. */
251 struct cl_decoded_option
253 /* The index of this option, or an OPT_SPECIAL_* value for
254 non-options and unknown options. */
255 size_t opt_index;
257 /* Any warning to give for use of this option, or NULL if none. */
258 const char *warn_message;
260 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
261 the option or non-option command-line argument. */
262 const char *arg;
264 /* The original text of option plus arguments, with separate argv
265 elements concatenated into one string with spaces separating
266 them. This is for such uses as diagnostics and
267 -frecord-gcc-switches. */
268 const char *orig_option_with_args_text;
270 /* The canonical form of the option and its argument, for when it is
271 necessary to reconstruct argv elements (in particular, for
272 processing specs and passing options to subprocesses from the
273 driver). */
274 const char *canonical_option[4];
276 /* The number of elements in the canonical form of the option and
277 arguments; always at least 1. */
278 size_t canonical_option_num_elements;
280 /* For a boolean option, 1 for the true case and 0 for the "no-"
281 case. For an unsigned integer option, the value of the
282 argument. For enum the value of the enumerator corresponding
283 to argument string. 1 in all other cases. */
284 HOST_WIDE_INT value;
286 /* For EnumSet the value mask. Variable should be changed to
287 value | (prev_value & ~mask). */
288 HOST_WIDE_INT mask;
290 /* Any flags describing errors detected in this option. */
291 int errors;
294 /* Structure describing an option deferred for handling after the main
295 option handlers. */
297 struct cl_deferred_option
299 /* Elements from struct cl_decoded_option used for deferred
300 options. */
301 size_t opt_index;
302 const char *arg;
303 int value;
306 /* Structure describing a single option-handling callback. */
308 struct cl_option_handler_func
310 /* The function called to handle the option. */
311 bool (*handler) (struct gcc_options *opts,
312 struct gcc_options *opts_set,
313 const struct cl_decoded_option *decoded,
314 unsigned int lang_mask, int kind, location_t loc,
315 const struct cl_option_handlers *handlers,
316 diagnostic_context *dc,
317 void (*target_option_override_hook) (void));
319 /* The mask that must have some bit in common with the flags for the
320 option for this particular handler to be used. */
321 unsigned int mask;
324 /* Structure describing the callbacks used in handling options. */
326 struct cl_option_handlers
328 /* Callback for an unknown option to determine whether to give an
329 error for it, and possibly store information to diagnose the
330 option at a later point. Return true if an error should be
331 given, false otherwise. */
332 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
334 /* Callback to handle, and possibly diagnose, an option for another
335 language. */
336 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
337 unsigned int lang_mask);
339 /* Target option override hook. */
340 void (*target_option_override_hook) (void);
342 /* The number of individual handlers. */
343 size_t num_handlers;
345 /* The handlers themselves. */
346 struct cl_option_handler_func handlers[3];
349 /* Hold command-line options associated with stack limitation. */
350 extern const char *opt_fstack_limit_symbol_arg;
351 extern int opt_fstack_limit_register_no;
352 extern bool flag_stack_protector_set_by_fhardened_p;
354 /* Input file names. */
356 extern const char **in_fnames;
358 /* The count of input filenames. */
360 extern unsigned num_in_fnames;
362 extern char *opts_concat (const char *first, ...);
364 /* Obstack for option strings. */
366 extern struct obstack opts_obstack;
368 size_t find_opt (const char *input, unsigned int lang_mask);
369 extern HOST_WIDE_INT integral_argument (const char *arg, int * = NULL, bool = false);
370 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
371 const char **argp, int value,
372 unsigned int lang_mask);
373 extern void decode_cmdline_options_to_array (unsigned int argc,
374 const char **argv,
375 unsigned int lang_mask,
376 struct cl_decoded_option **decoded_options,
377 unsigned int *decoded_options_count);
378 extern void init_options_once (void);
379 extern void init_options_struct (struct gcc_options *opts,
380 struct gcc_options *opts_set);
381 extern void init_opts_obstack (void);
382 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
383 const char **argv,
384 struct cl_decoded_option **decoded_options,
385 unsigned int *decoded_options_count);
386 extern void set_default_handlers (struct cl_option_handlers *handlers,
387 void (*target_option_override_hook) (void));
388 extern void decode_options (struct gcc_options *opts,
389 struct gcc_options *opts_set,
390 struct cl_decoded_option *decoded_options,
391 unsigned int decoded_options_count,
392 location_t loc,
393 diagnostic_context *dc,
394 void (*target_option_override_hook) (void));
395 extern int option_enabled (int opt_idx, unsigned lang_mask, void *opts);
397 extern bool get_option_state (struct gcc_options *, int,
398 struct cl_option_state *);
399 extern void set_option (struct gcc_options *opts,
400 struct gcc_options *opts_set,
401 int opt_index, HOST_WIDE_INT value, const char *arg,
402 int kind, location_t loc, diagnostic_context *dc,
403 HOST_WIDE_INT = 0);
404 extern void *option_flag_var (int opt_index, struct gcc_options *opts);
405 bool handle_generated_option (struct gcc_options *opts,
406 struct gcc_options *opts_set,
407 size_t opt_index, const char *arg,
408 HOST_WIDE_INT value,
409 unsigned int lang_mask, int kind, location_t loc,
410 const struct cl_option_handlers *handlers,
411 bool generated_p, diagnostic_context *dc);
412 void generate_option (size_t opt_index, const char *arg, HOST_WIDE_INT value,
413 unsigned int lang_mask,
414 struct cl_decoded_option *decoded);
415 void generate_option_input_file (const char *file,
416 struct cl_decoded_option *decoded);
417 extern void read_cmdline_option (struct gcc_options *opts,
418 struct gcc_options *opts_set,
419 struct cl_decoded_option *decoded,
420 location_t loc,
421 unsigned int lang_mask,
422 const struct cl_option_handlers *handlers,
423 diagnostic_context *dc);
424 extern void control_warning_option (unsigned int opt_index, int kind,
425 const char *arg, bool imply, location_t loc,
426 unsigned int lang_mask,
427 const struct cl_option_handlers *handlers,
428 struct gcc_options *opts,
429 struct gcc_options *opts_set,
430 diagnostic_context *dc);
431 extern char *write_langs (unsigned int mask);
432 extern void print_ignored_options (void);
433 extern void handle_common_deferred_options (void);
434 extern void handle_deferred_dump_options (void);
435 unsigned int parse_sanitizer_options (const char *, location_t, int,
436 unsigned int, int, bool);
438 unsigned int parse_no_sanitize_attribute (char *value);
439 extern bool common_handle_option (struct gcc_options *opts,
440 struct gcc_options *opts_set,
441 const struct cl_decoded_option *decoded,
442 unsigned int lang_mask, int kind,
443 location_t loc,
444 const struct cl_option_handlers *handlers,
445 diagnostic_context *dc,
446 void (*target_option_override_hook) (void));
447 extern bool target_handle_option (struct gcc_options *opts,
448 struct gcc_options *opts_set,
449 const struct cl_decoded_option *decoded,
450 unsigned int lang_mask, int kind,
451 location_t loc,
452 const struct cl_option_handlers *handlers,
453 diagnostic_context *dc,
454 void (*target_option_override_hook) (void));
455 extern void finish_options (struct gcc_options *opts,
456 struct gcc_options *opts_set,
457 location_t loc);
458 extern void diagnose_options (gcc_options *opts, gcc_options *opts_set,
459 location_t loc);
460 extern void print_help (struct gcc_options *opts, unsigned int lang_mask, const
461 char *help_option_argument);
462 extern void default_options_optimization (struct gcc_options *opts,
463 struct gcc_options *opts_set,
464 struct cl_decoded_option *decoded_options,
465 unsigned int decoded_options_count,
466 location_t loc,
467 unsigned int lang_mask,
468 const struct cl_option_handlers *handlers,
469 diagnostic_context *dc);
470 extern void set_struct_debug_option (struct gcc_options *opts,
471 location_t loc,
472 const char *value);
473 extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
474 int *value,
475 unsigned int lang_mask);
477 extern const struct sanitizer_opts_s
479 const char *const name;
480 unsigned int flag;
481 size_t len;
482 bool can_recover;
483 bool can_trap;
484 } sanitizer_opts[];
486 extern const struct zero_call_used_regs_opts_s
488 const char *const name;
489 unsigned int flag;
490 } zero_call_used_regs_opts[];
492 extern vec<const char *> help_option_arguments;
494 extern const char *get_option_prefix_remapping (const char *p, size_t sz,
495 const char **out_new_prefix);
497 extern void add_misspelling_candidates (auto_vec<char *> *candidates,
498 const struct cl_option *option,
499 const char *base_option);
500 extern const char *candidates_list_and_hint (const char *arg, char *&str,
501 const auto_vec <const char *> &
502 candidates);
505 extern bool parse_and_check_align_values (const char *flag,
506 const char *name,
507 auto_vec<unsigned> &result_values,
508 bool report_error,
509 location_t loc);
511 extern void parse_and_check_patch_area (const char *arg, bool report_error,
512 HOST_WIDE_INT *patch_area_size,
513 HOST_WIDE_INT *patch_area_start);
515 extern void parse_options_from_collect_gcc_options (const char *, obstack *,
516 int *);
518 extern void prepend_xassembler_to_collect_as_options (const char *, obstack *);
520 extern char *gen_command_line_string (cl_decoded_option *options,
521 unsigned int options_count);
522 extern char *gen_producer_string (const char *language_string,
523 cl_decoded_option *options,
524 unsigned int options_count);
526 /* Set OPTION in OPTS to VALUE if the option is not set in OPTS_SET. */
528 #define SET_OPTION_IF_UNSET(OPTS, OPTS_SET, OPTION, VALUE) \
529 do \
531 if (!(OPTS_SET)->x_ ## OPTION) \
532 (OPTS)->x_ ## OPTION = VALUE; \
534 while (false)
536 /* Return true if OPTION is set by user in global options. */
538 #define OPTION_SET_P(OPTION) global_options_set.x_ ## OPTION
540 /* Find all the switches given to us
541 and make a vector describing them.
542 The elements of the vector are strings, one per switch given.
543 If a switch uses following arguments, then the `part1' field
544 is the switch itself and the `args' field
545 is a null-terminated vector containing the following arguments.
546 Bits in the `live_cond' field are:
547 SWITCH_LIVE to indicate this switch is true in a conditional spec.
548 SWITCH_FALSE to indicate this switch is overridden by a later switch.
549 SWITCH_IGNORE to indicate this switch should be ignored (used in %<S).
550 SWITCH_IGNORE_PERMANENTLY to indicate this switch should be ignored.
551 SWITCH_KEEP_FOR_GCC to indicate that this switch, otherwise ignored,
552 should be included in COLLECT_GCC_OPTIONS.
553 in all do_spec calls afterwards. Used for %<S from self specs.
554 The `known' field describes whether this is an internal switch.
555 The `validated' field describes whether any spec has looked at this switch;
556 if it remains false at the end of the run, the switch must be meaningless.
557 The `ordering' field is used to temporarily mark switches that have to be
558 kept in a specific order. */
560 #define SWITCH_LIVE (1 << 0)
561 #define SWITCH_FALSE (1 << 1)
562 #define SWITCH_IGNORE (1 << 2)
563 #define SWITCH_IGNORE_PERMANENTLY (1 << 3)
564 #define SWITCH_KEEP_FOR_GCC (1 << 4)
566 struct switchstr
568 const char *part1;
569 const char **args;
570 unsigned int live_cond;
571 bool known;
572 bool validated;
573 bool ordering;
576 extern label_text
577 get_option_url_suffix (int option_index, unsigned lang_mask);
579 #endif