real.h (struct real_format): Split the signbit field into two two fields, signbit_ro...
[gcc.git] / gcc / toplev.c
1 /* Top level of GCC compilers (cc1, cc1plus, etc.)
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4
5 This file is part of GCC.
6
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
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 /* This is the top level of cc1/c++.
23 It parses command args, opens files, invokes the various passes
24 in the proper order, and counts the time used by each.
25 Error messages and low-level interface to malloc also handled here. */
26
27 #include "config.h"
28 #undef FLOAT /* This is for hpux. They should change hpux. */
29 #undef FFS /* Some systems define this in param.h. */
30 #include "system.h"
31 #include "coretypes.h"
32 #include "tm.h"
33 #include <signal.h>
34
35 #ifdef HAVE_SYS_RESOURCE_H
36 # include <sys/resource.h>
37 #endif
38
39 #ifdef HAVE_SYS_TIMES_H
40 # include <sys/times.h>
41 #endif
42
43 #include "line-map.h"
44 #include "input.h"
45 #include "tree.h"
46 #include "version.h"
47 #include "rtl.h"
48 #include "tm_p.h"
49 #include "flags.h"
50 #include "insn-attr.h"
51 #include "insn-config.h"
52 #include "insn-flags.h"
53 #include "hard-reg-set.h"
54 #include "recog.h"
55 #include "output.h"
56 #include "except.h"
57 #include "function.h"
58 #include "toplev.h"
59 #include "expr.h"
60 #include "basic-block.h"
61 #include "intl.h"
62 #include "ggc.h"
63 #include "graph.h"
64 #include "regs.h"
65 #include "timevar.h"
66 #include "diagnostic.h"
67 #include "params.h"
68 #include "reload.h"
69 #include "dwarf2asm.h"
70 #include "integrate.h"
71 #include "real.h"
72 #include "debug.h"
73 #include "target.h"
74 #include "langhooks.h"
75 #include "cfglayout.h"
76 #include "cfgloop.h"
77 #include "hosthooks.h"
78 #include "cgraph.h"
79 #include "opts.h"
80 #include "coverage.h"
81 #include "value-prof.h"
82 #include "alloc-pool.h"
83 #include "tree-mudflap.h"
84
85 #if defined (DWARF2_UNWIND_INFO) || defined (DWARF2_DEBUGGING_INFO)
86 #include "dwarf2out.h"
87 #endif
88
89 #if defined(DBX_DEBUGGING_INFO) || defined(XCOFF_DEBUGGING_INFO)
90 #include "dbxout.h"
91 #endif
92
93 #ifdef SDB_DEBUGGING_INFO
94 #include "sdbout.h"
95 #endif
96
97 #ifdef XCOFF_DEBUGGING_INFO
98 #include "xcoffout.h" /* Needed for external data
99 declarations for e.g. AIX 4.x. */
100 #endif
101
102 static void general_init (const char *);
103 static void do_compile (void);
104 static void process_options (void);
105 static void backend_init (void);
106 static int lang_dependent_init (const char *);
107 static void init_asm_output (const char *);
108 static void finalize (void);
109
110 static void crash_signal (int) ATTRIBUTE_NORETURN;
111 static void setup_core_dumping (void);
112 static void compile_file (void);
113
114 static int print_single_switch (FILE *, int, int, const char *,
115 const char *, const char *,
116 const char *, const char *);
117 static void print_switch_values (FILE *, int, int, const char *,
118 const char *, const char *);
119
120 /* Nonzero to dump debug info whilst parsing (-dy option). */
121 static int set_yydebug;
122
123 /* True if we don't need a backend (e.g. preprocessing only). */
124 static bool no_backend;
125
126 /* Length of line when printing switch values. */
127 #define MAX_LINE 75
128
129 /* Name of program invoked, sans directories. */
130
131 const char *progname;
132
133 /* Copy of argument vector to toplev_main. */
134 static const char **save_argv;
135
136 /* Name of top-level original source file (what was input to cpp).
137 This comes from the #-command at the beginning of the actual input.
138 If there isn't any there, then this is the cc1 input file name. */
139
140 const char *main_input_filename;
141
142 #ifndef USE_MAPPED_LOCATION
143 location_t unknown_location = { NULL, 0 };
144 #endif
145
146 /* Used to enable -fvar-tracking, -fweb and -frename-registers according
147 to optimize and default_debug_hooks in process_options (). */
148 #define AUTODETECT_FLAG_VAR_TRACKING 2
149
150 /* Current position in real source file. */
151
152 location_t input_location;
153
154 struct line_maps line_table;
155
156 /* Nonzero if it is unsafe to create any new pseudo registers. */
157 int no_new_pseudos;
158
159 /* Stack of currently pending input files. */
160
161 struct file_stack *input_file_stack;
162
163 /* Incremented on each change to input_file_stack. */
164 int input_file_stack_tick;
165
166 /* Name to use as base of names for dump output files. */
167
168 const char *dump_base_name;
169
170 /* Name to use as a base for auxiliary output files. */
171
172 const char *aux_base_name;
173
174 /* Bit flags that specify the machine subtype we are compiling for.
175 Bits are tested using macros TARGET_... defined in the tm.h file
176 and set by `-m...' switches. Must be defined in rtlanal.c. */
177
178 extern int target_flags;
179
180 /* A mask of target_flags that includes bit X if X was set or cleared
181 on the command line. */
182
183 int target_flags_explicit;
184
185 /* Debug hooks - dependent upon command line options. */
186
187 const struct gcc_debug_hooks *debug_hooks;
188
189 /* Debug hooks - target default. */
190
191 static const struct gcc_debug_hooks *default_debug_hooks;
192
193 /* Other flags saying which kinds of debugging dump have been requested. */
194
195 int rtl_dump_and_exit;
196 int flag_print_asm_name;
197 enum graph_dump_types graph_dump_format;
198
199 /* Name for output file of assembly code, specified with -o. */
200
201 const char *asm_file_name;
202
203 /* Nonzero means do optimizations. -O.
204 Particular numeric values stand for particular amounts of optimization;
205 thus, -O2 stores 2 here. However, the optimizations beyond the basic
206 ones are not controlled directly by this variable. Instead, they are
207 controlled by individual `flag_...' variables that are defaulted
208 based on this variable. */
209
210 int optimize = 0;
211
212 /* Nonzero means optimize for size. -Os.
213 The only valid values are zero and nonzero. When optimize_size is
214 nonzero, optimize defaults to 2, but certain individual code
215 bloating optimizations are disabled. */
216
217 int optimize_size = 0;
218
219 /* The FUNCTION_DECL for the function currently being compiled,
220 or 0 if between functions. */
221 tree current_function_decl;
222
223 /* Set to the FUNC_BEGIN label of the current function, or NULL
224 if none. */
225 const char * current_function_func_begin_label;
226
227 /* Temporarily suppress certain warnings.
228 This is set while reading code from a system header file. */
229
230 int in_system_header = 0;
231
232 /* Nonzero means to collect statistics which might be expensive
233 and to print them when we are done. */
234 int flag_detailed_statistics = 0;
235
236 /* A random sequence of characters, unless overridden by user. */
237 const char *flag_random_seed;
238
239 /* A local time stamp derived from the time of compilation. It will be
240 zero if the system cannot provide a time. It will be -1u, if the
241 user has specified a particular random seed. */
242 unsigned local_tick;
243
244 /* -f flags. */
245
246 /* Nonzero means `char' should be signed. */
247
248 int flag_signed_char;
249
250 /* Nonzero means give an enum type only as many bytes as it needs. A value
251 of 2 means it has not yet been initialized. */
252
253 int flag_short_enums;
254
255 /* Nonzero if structures and unions should be returned in memory.
256
257 This should only be defined if compatibility with another compiler or
258 with an ABI is needed, because it results in slower code. */
259
260 #ifndef DEFAULT_PCC_STRUCT_RETURN
261 #define DEFAULT_PCC_STRUCT_RETURN 1
262 #endif
263
264 /* Nonzero for -fpcc-struct-return: return values the same way PCC does. */
265
266 int flag_pcc_struct_return = DEFAULT_PCC_STRUCT_RETURN;
267
268 /* 0 means straightforward implementation of complex divide acceptable.
269 1 means wide ranges of inputs must work for complex divide.
270 2 means C99-like requirements for complex multiply and divide. */
271
272 int flag_complex_method = 1;
273
274 /* Nonzero means that we don't want inlining by virtue of -fno-inline,
275 not just because the tree inliner turned us off. */
276
277 int flag_really_no_inline = 2;
278
279 /* Nonzero means we should be saving declaration info into a .X file. */
280
281 int flag_gen_aux_info = 0;
282
283 /* Specified name of aux-info file. */
284
285 const char *aux_info_file_name;
286
287 /* Nonzero if we are compiling code for a shared library, zero for
288 executable. */
289
290 int flag_shlib;
291
292 /* Set to the default thread-local storage (tls) model to use. */
293
294 enum tls_model flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
295
296 /* Nonzero means change certain warnings into errors.
297 Usually these are warnings about failure to conform to some standard. */
298
299 int flag_pedantic_errors = 0;
300
301 /* -dA causes debug commentary information to be produced in
302 the generated assembly code (to make it more readable). This option
303 is generally only of use to those who actually need to read the
304 generated assembly code (perhaps while debugging the compiler itself).
305 Currently, this switch is only used by dwarfout.c; however, it is intended
306 to be a catchall for printing debug information in the assembler file. */
307
308 int flag_debug_asm = 0;
309
310 /* -dP causes the rtl to be emitted as a comment in assembly. */
311
312 int flag_dump_rtl_in_asm = 0;
313
314 /* When non-NULL, indicates that whenever space is allocated on the
315 stack, the resulting stack pointer must not pass this
316 address---that is, for stacks that grow downward, the stack pointer
317 must always be greater than or equal to this address; for stacks
318 that grow upward, the stack pointer must be less than this address.
319 At present, the rtx may be either a REG or a SYMBOL_REF, although
320 the support provided depends on the backend. */
321 rtx stack_limit_rtx;
322
323 /* If one, renumber instruction UIDs to reduce the number of
324 unused UIDs if there are a lot of instructions. If greater than
325 one, unconditionally renumber instruction UIDs. */
326 int flag_renumber_insns = 1;
327
328 /* Nonzero if we should track variables. When
329 flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING it will be set according
330 to optimize, debug_info_level and debug_hooks in process_options (). */
331 int flag_var_tracking = AUTODETECT_FLAG_VAR_TRACKING;
332
333 /* True if the user has tagged the function with the 'section'
334 attribute. */
335
336 bool user_defined_section_attribute = false;
337
338 /* Values of the -falign-* flags: how much to align labels in code.
339 0 means `use default', 1 means `don't align'.
340 For each variable, there is an _log variant which is the power
341 of two not less than the variable, for .align output. */
342
343 int align_loops_log;
344 int align_loops_max_skip;
345 int align_jumps_log;
346 int align_jumps_max_skip;
347 int align_labels_log;
348 int align_labels_max_skip;
349 int align_functions_log;
350
351 /* Like align_functions_log above, but used by front-ends to force the
352 minimum function alignment. Zero means no alignment is forced. */
353 int force_align_functions_log;
354
355 typedef struct
356 {
357 const char *const string;
358 int *const variable;
359 const int on_value;
360 }
361 lang_independent_options;
362
363 /* Nonzero if subexpressions must be evaluated from left-to-right. */
364 int flag_evaluation_order = 0;
365
366 /* The user symbol prefix after having resolved same. */
367 const char *user_label_prefix;
368
369 static const param_info lang_independent_params[] = {
370 #define DEFPARAM(ENUM, OPTION, HELP, DEFAULT, MIN, MAX) \
371 { OPTION, DEFAULT, MIN, MAX, HELP },
372 #include "params.def"
373 #undef DEFPARAM
374 { NULL, 0, 0, 0, NULL }
375 };
376
377 #ifdef TARGET_SWITCHES
378 /* Here is a table, controlled by the tm.h file, listing each -m switch
379 and which bits in `target_switches' it should set or clear.
380 If VALUE is positive, it is bits to set.
381 If VALUE is negative, -VALUE is bits to clear.
382 (The sign bit is not used so there is no confusion.) */
383
384 static const struct
385 {
386 const char *const name;
387 const int value;
388 const char *const description;
389 }
390 target_switches[] = TARGET_SWITCHES;
391 #endif
392
393 /* This table is similar, but allows the switch to have a value. */
394
395 #ifdef TARGET_OPTIONS
396 static const struct
397 {
398 const char *const prefix;
399 const char **const variable;
400 const char *const description;
401 const char *const value;
402 }
403 target_options[] = TARGET_OPTIONS;
404 #endif
405
406 /* Nonzero means warn about function definitions that default the return type
407 or that use a null return and have a return-type other than void. */
408
409 int warn_return_type;
410
411 /* Output files for assembler code (real compiler output)
412 and debugging dumps. */
413
414 FILE *asm_out_file;
415 FILE *aux_info_file;
416 FILE *dump_file = NULL;
417 const char *dump_file_name;
418
419 /* The current working directory of a translation. It's generally the
420 directory from which compilation was initiated, but a preprocessed
421 file may specify the original directory in which it was
422 created. */
423
424 static const char *src_pwd;
425
426 /* Initialize src_pwd with the given string, and return true. If it
427 was already initialized, return false. As a special case, it may
428 be called with a NULL argument to test whether src_pwd has NOT been
429 initialized yet. */
430
431 bool
432 set_src_pwd (const char *pwd)
433 {
434 if (src_pwd)
435 {
436 if (strcmp (src_pwd, pwd) == 0)
437 return true;
438 else
439 return false;
440 }
441
442 src_pwd = xstrdup (pwd);
443 return true;
444 }
445
446 /* Return the directory from which the translation unit was initiated,
447 in case set_src_pwd() was not called before to assign it a
448 different value. */
449
450 const char *
451 get_src_pwd (void)
452 {
453 if (! src_pwd)
454 {
455 src_pwd = getpwd ();
456 if (!src_pwd)
457 src_pwd = ".";
458 }
459
460 return src_pwd;
461 }
462
463 /* Called when the start of a function definition is parsed,
464 this function prints on stderr the name of the function. */
465 void
466 announce_function (tree decl)
467 {
468 if (!quiet_flag)
469 {
470 if (rtl_dump_and_exit)
471 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
472 else
473 verbatim (" %s", lang_hooks.decl_printable_name (decl, 2));
474 fflush (stderr);
475 pp_needs_newline (global_dc->printer) = true;
476 diagnostic_set_last_function (global_dc);
477 }
478 }
479
480 /* Set up a default flag_random_seed and local_tick, unless the user
481 already specified one. */
482
483 static void
484 randomize (void)
485 {
486 if (!flag_random_seed)
487 {
488 unsigned HOST_WIDE_INT value;
489 static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3];
490
491 /* Get some more or less random data. */
492 #ifdef HAVE_GETTIMEOFDAY
493 {
494 struct timeval tv;
495
496 gettimeofday (&tv, NULL);
497 local_tick = tv.tv_sec * 1000 + tv.tv_usec / 1000;
498 }
499 #else
500 {
501 time_t now = time (NULL);
502
503 if (now != (time_t)-1)
504 local_tick = (unsigned) now;
505 }
506 #endif
507 value = local_tick ^ getpid ();
508
509 sprintf (random_seed, HOST_WIDE_INT_PRINT_HEX, value);
510 flag_random_seed = random_seed;
511 }
512 else if (!local_tick)
513 local_tick = -1;
514 }
515
516
517 /* Decode the string P as an integral parameter.
518 If the string is indeed an integer return its numeric value else
519 issue an Invalid Option error for the option PNAME and return DEFVAL.
520 If PNAME is zero just return DEFVAL, do not call error. */
521
522 int
523 read_integral_parameter (const char *p, const char *pname, const int defval)
524 {
525 const char *endp = p;
526
527 while (*endp)
528 {
529 if (ISDIGIT (*endp))
530 endp++;
531 else
532 break;
533 }
534
535 if (*endp != 0)
536 {
537 if (pname != 0)
538 error ("invalid option argument %qs", pname);
539 return defval;
540 }
541
542 return atoi (p);
543 }
544
545 /* Given X, an unsigned number, return the largest int Y such that 2**Y <= X.
546 If X is 0, return -1. */
547
548 int
549 floor_log2 (unsigned HOST_WIDE_INT x)
550 {
551 int t = 0;
552
553 if (x == 0)
554 return -1;
555
556 #ifdef CLZ_HWI
557 t = HOST_BITS_PER_WIDE_INT - 1 - (int) CLZ_HWI (x);
558 #else
559 if (HOST_BITS_PER_WIDE_INT > 64)
560 if (x >= (unsigned HOST_WIDE_INT) 1 << (t + 64))
561 t += 64;
562 if (HOST_BITS_PER_WIDE_INT > 32)
563 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 32))
564 t += 32;
565 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 16))
566 t += 16;
567 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 8))
568 t += 8;
569 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 4))
570 t += 4;
571 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 2))
572 t += 2;
573 if (x >= ((unsigned HOST_WIDE_INT) 1) << (t + 1))
574 t += 1;
575 #endif
576
577 return t;
578 }
579
580 /* Return the logarithm of X, base 2, considering X unsigned,
581 if X is a power of 2. Otherwise, returns -1. */
582
583 int
584 exact_log2 (unsigned HOST_WIDE_INT x)
585 {
586 if (x != (x & -x))
587 return -1;
588 #ifdef CTZ_HWI
589 return x ? CTZ_HWI (x) : -1;
590 #else
591 return floor_log2 (x);
592 #endif
593 }
594
595 /* Handler for fatal signals, such as SIGSEGV. These are transformed
596 into ICE messages, which is much more user friendly. In case the
597 error printer crashes, reset the signal to prevent infinite recursion. */
598
599 static void
600 crash_signal (int signo)
601 {
602 signal (signo, SIG_DFL);
603
604 /* If we crashed while processing an ASM statement, then be a little more
605 graceful. It's most likely the user's fault. */
606 if (this_is_asm_operands)
607 {
608 output_operand_lossage ("unrecoverable error");
609 exit (FATAL_EXIT_CODE);
610 }
611
612 internal_error ("%s", strsignal (signo));
613 }
614
615 /* Arrange to dump core on error. (The regular error message is still
616 printed first, except in the case of abort().) */
617
618 static void
619 setup_core_dumping (void)
620 {
621 #ifdef SIGABRT
622 signal (SIGABRT, SIG_DFL);
623 #endif
624 #if defined(HAVE_SETRLIMIT)
625 {
626 struct rlimit rlim;
627 if (getrlimit (RLIMIT_CORE, &rlim) != 0)
628 fatal_error ("getting core file size maximum limit: %m");
629 rlim.rlim_cur = rlim.rlim_max;
630 if (setrlimit (RLIMIT_CORE, &rlim) != 0)
631 fatal_error ("setting core file size limit to maximum: %m");
632 }
633 #endif
634 diagnostic_abort_on_error (global_dc);
635 }
636
637
638 /* Strip off a legitimate source ending from the input string NAME of
639 length LEN. Rather than having to know the names used by all of
640 our front ends, we strip off an ending of a period followed by
641 up to five characters. (Java uses ".class".) */
642
643 void
644 strip_off_ending (char *name, int len)
645 {
646 int i;
647 for (i = 2; i < 6 && len > i; i++)
648 {
649 if (name[len - i] == '.')
650 {
651 name[len - i] = '\0';
652 break;
653 }
654 }
655 }
656
657 /* Output a quoted string. */
658
659 void
660 output_quoted_string (FILE *asm_file, const char *string)
661 {
662 #ifdef OUTPUT_QUOTED_STRING
663 OUTPUT_QUOTED_STRING (asm_file, string);
664 #else
665 char c;
666
667 putc ('\"', asm_file);
668 while ((c = *string++) != 0)
669 {
670 if (ISPRINT (c))
671 {
672 if (c == '\"' || c == '\\')
673 putc ('\\', asm_file);
674 putc (c, asm_file);
675 }
676 else
677 fprintf (asm_file, "\\%03o", (unsigned char) c);
678 }
679 putc ('\"', asm_file);
680 #endif
681 }
682
683 /* Output a file name in the form wanted by System V. */
684
685 void
686 output_file_directive (FILE *asm_file, const char *input_name)
687 {
688 int len;
689 const char *na;
690
691 if (input_name == NULL)
692 input_name = "<stdin>";
693
694 len = strlen (input_name);
695 na = input_name + len;
696
697 /* NA gets INPUT_NAME sans directory names. */
698 while (na > input_name)
699 {
700 if (IS_DIR_SEPARATOR (na[-1]))
701 break;
702 na--;
703 }
704
705 #ifdef ASM_OUTPUT_SOURCE_FILENAME
706 ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
707 #else
708 fprintf (asm_file, "\t.file\t");
709 output_quoted_string (asm_file, na);
710 fputc ('\n', asm_file);
711 #endif
712 }
713
714 /* Do any final processing required for the declarations in VEC, of
715 which there are LEN. We write out inline functions and variables
716 that have been deferred until this point, but which are required.
717 Returns nonzero if anything was put out. */
718
719 int
720 wrapup_global_declarations (tree *vec, int len)
721 {
722 tree decl;
723 int i;
724 int reconsider;
725 int output_something = 0;
726
727 for (i = 0; i < len; i++)
728 {
729 decl = vec[i];
730
731 /* We're not deferring this any longer. Assignment is
732 conditional to avoid needlessly dirtying PCH pages. */
733 if (DECL_DEFER_OUTPUT (decl) != 0)
734 DECL_DEFER_OUTPUT (decl) = 0;
735
736 if (TREE_CODE (decl) == VAR_DECL && DECL_SIZE (decl) == 0)
737 lang_hooks.finish_incomplete_decl (decl);
738 }
739
740 /* Now emit any global variables or functions that we have been
741 putting off. We need to loop in case one of the things emitted
742 here references another one which comes earlier in the list. */
743 do
744 {
745 reconsider = 0;
746 for (i = 0; i < len; i++)
747 {
748 decl = vec[i];
749
750 if (TREE_ASM_WRITTEN (decl) || DECL_EXTERNAL (decl))
751 continue;
752
753 /* Don't write out static consts, unless we still need them.
754
755 We also keep static consts if not optimizing (for debugging),
756 unless the user specified -fno-keep-static-consts.
757 ??? They might be better written into the debug information.
758 This is possible when using DWARF.
759
760 A language processor that wants static constants to be always
761 written out (even if it is not used) is responsible for
762 calling rest_of_decl_compilation itself. E.g. the C front-end
763 calls rest_of_decl_compilation from finish_decl.
764 One motivation for this is that is conventional in some
765 environments to write things like:
766 static const char rcsid[] = "... version string ...";
767 intending to force the string to be in the executable.
768
769 A language processor that would prefer to have unneeded
770 static constants "optimized away" would just defer writing
771 them out until here. E.g. C++ does this, because static
772 constants are often defined in header files.
773
774 ??? A tempting alternative (for both C and C++) would be
775 to force a constant to be written if and only if it is
776 defined in a main file, as opposed to an include file. */
777
778 if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
779 {
780 struct cgraph_varpool_node *node;
781 bool needed = 1;
782 node = cgraph_varpool_node (decl);
783
784 if (flag_unit_at_a_time && node->finalized)
785 needed = 0;
786 else if ((flag_unit_at_a_time && !cgraph_global_info_ready)
787 && (TREE_USED (decl)
788 || TREE_USED (DECL_ASSEMBLER_NAME (decl))))
789 /* needed */;
790 else if (node->needed)
791 /* needed */;
792 else if (DECL_COMDAT (decl))
793 needed = 0;
794 else if (TREE_READONLY (decl) && !TREE_PUBLIC (decl)
795 && (optimize || !flag_keep_static_consts
796 || DECL_ARTIFICIAL (decl)))
797 needed = 0;
798
799 if (needed)
800 {
801 reconsider = 1;
802 rest_of_decl_compilation (decl, 1, 1);
803 }
804 }
805 }
806
807 if (reconsider)
808 output_something = 1;
809 }
810 while (reconsider);
811
812 return output_something;
813 }
814
815 /* Issue appropriate warnings for the global declarations in VEC (of
816 which there are LEN). Output debugging information for them. */
817
818 void
819 check_global_declarations (tree *vec, int len)
820 {
821 tree decl;
822 int i;
823
824 for (i = 0; i < len; i++)
825 {
826 decl = vec[i];
827
828 /* Do not emit debug information about variables that are in
829 static storage, but not defined. */
830 if (TREE_CODE (decl) == VAR_DECL
831 && TREE_STATIC (decl)
832 && !TREE_ASM_WRITTEN (decl))
833 DECL_IGNORED_P (decl) = 1;
834
835 /* Warn about any function
836 declared static but not defined.
837 We don't warn about variables,
838 because many programs have static variables
839 that exist only to get some text into the object file. */
840 if (TREE_CODE (decl) == FUNCTION_DECL
841 && DECL_INITIAL (decl) == 0
842 && DECL_EXTERNAL (decl)
843 && ! DECL_ARTIFICIAL (decl)
844 && ! TREE_NO_WARNING (decl)
845 && ! TREE_PUBLIC (decl)
846 && (warn_unused_function
847 || TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))))
848 {
849 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
850 pedwarn ("%J%qF used but never defined", decl, decl);
851 else
852 warning ("%J%qF declared %<static%> but never defined",
853 decl, decl);
854 /* This symbol is effectively an "extern" declaration now. */
855 TREE_PUBLIC (decl) = 1;
856 assemble_external (decl);
857 }
858
859 /* Warn about static fns or vars defined but not used. */
860 if (((warn_unused_function && TREE_CODE (decl) == FUNCTION_DECL)
861 /* We don't warn about "static const" variables because the
862 "rcs_id" idiom uses that construction. */
863 || (warn_unused_variable
864 && TREE_CODE (decl) == VAR_DECL && ! TREE_READONLY (decl)))
865 && ! DECL_IN_SYSTEM_HEADER (decl)
866 && ! TREE_USED (decl)
867 /* The TREE_USED bit for file-scope decls is kept in the identifier,
868 to handle multiple external decls in different scopes. */
869 && ! TREE_USED (DECL_NAME (decl))
870 && ! DECL_EXTERNAL (decl)
871 && ! TREE_PUBLIC (decl)
872 /* A volatile variable might be used in some non-obvious way. */
873 && ! TREE_THIS_VOLATILE (decl)
874 /* Global register variables must be declared to reserve them. */
875 && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl))
876 /* Otherwise, ask the language. */
877 && lang_hooks.decls.warn_unused_global (decl))
878 warning ("%J%qD defined but not used", decl, decl);
879
880 /* Avoid confusing the debug information machinery when there are
881 errors. */
882 if (errorcount == 0 && sorrycount == 0)
883 {
884 timevar_push (TV_SYMOUT);
885 (*debug_hooks->global_decl) (decl);
886 timevar_pop (TV_SYMOUT);
887 }
888 }
889 }
890
891 /* Warn about a use of an identifier which was marked deprecated. */
892 void
893 warn_deprecated_use (tree node)
894 {
895 if (node == 0 || !warn_deprecated_decl)
896 return;
897
898 if (DECL_P (node))
899 {
900 expanded_location xloc = expand_location (DECL_SOURCE_LOCATION (node));
901 warning ("%qs is deprecated (declared at %s:%d)",
902 IDENTIFIER_POINTER (DECL_NAME (node)),
903 xloc.file, xloc.line);
904 }
905 else if (TYPE_P (node))
906 {
907 const char *what = NULL;
908 tree decl = TYPE_STUB_DECL (node);
909
910 if (TYPE_NAME (node))
911 {
912 if (TREE_CODE (TYPE_NAME (node)) == IDENTIFIER_NODE)
913 what = IDENTIFIER_POINTER (TYPE_NAME (node));
914 else if (TREE_CODE (TYPE_NAME (node)) == TYPE_DECL
915 && DECL_NAME (TYPE_NAME (node)))
916 what = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (node)));
917 }
918
919 if (decl)
920 {
921 expanded_location xloc
922 = expand_location (DECL_SOURCE_LOCATION (decl));
923 if (what)
924 warning ("%qs is deprecated (declared at %s:%d)", what,
925 xloc.file, xloc.line);
926 else
927 warning ("type is deprecated (declared at %s:%d)",
928 xloc.file, xloc.line);
929 }
930 else
931 {
932 if (what)
933 warning ("%qs is deprecated", what);
934 else
935 warning ("type is deprecated");
936 }
937 }
938 }
939
940 /* Save the current INPUT_LOCATION on the top entry in the
941 INPUT_FILE_STACK. Push a new entry for FILE and LINE, and set the
942 INPUT_LOCATION accordingly. */
943
944 void
945 #ifdef USE_MAPPED_LOCATION
946 push_srcloc (location_t fline)
947 #else
948 push_srcloc (const char *file, int line)
949 #endif
950 {
951 struct file_stack *fs;
952
953 fs = xmalloc (sizeof (struct file_stack));
954 fs->location = input_location;
955 fs->next = input_file_stack;
956 #ifdef USE_MAPPED_LOCATION
957 input_location = fline;
958 #else
959 input_filename = file;
960 input_line = line;
961 #endif
962 input_file_stack = fs;
963 input_file_stack_tick++;
964 }
965
966 /* Pop the top entry off the stack of presently open source files.
967 Restore the INPUT_LOCATION from the new topmost entry on the
968 stack. */
969
970 void
971 pop_srcloc (void)
972 {
973 struct file_stack *fs;
974
975 fs = input_file_stack;
976 input_location = fs->location;
977 input_file_stack = fs->next;
978 free (fs);
979 input_file_stack_tick++;
980 }
981
982 /* Compile an entire translation unit. Write a file of assembly
983 output and various debugging dumps. */
984
985 static void
986 compile_file (void)
987 {
988 /* Initialize yet another pass. */
989
990 init_cgraph ();
991 init_final (main_input_filename);
992 coverage_init (aux_base_name);
993
994 timevar_push (TV_PARSE);
995
996 /* Call the parser, which parses the entire file (calling
997 rest_of_compilation for each function). */
998 lang_hooks.parse_file (set_yydebug);
999
1000 /* In case there were missing block closers,
1001 get us back to the global binding level. */
1002 lang_hooks.clear_binding_stack ();
1003
1004 /* Compilation is now finished except for writing
1005 what's left of the symbol table output. */
1006 timevar_pop (TV_PARSE);
1007
1008 if (flag_syntax_only)
1009 return;
1010
1011 lang_hooks.decls.final_write_globals ();
1012
1013 cgraph_varpool_assemble_pending_decls ();
1014
1015 /* This must occur after the loop to output deferred functions.
1016 Else the coverage initializer would not be emitted if all the
1017 functions in this compilation unit were deferred. */
1018 coverage_finish ();
1019
1020 /* Likewise for mudflap static object registrations. */
1021 if (flag_mudflap)
1022 mudflap_finish_file ();
1023
1024 /* Write out any pending weak symbol declarations. */
1025
1026 weak_finish ();
1027
1028 /* Do dbx symbols. */
1029 timevar_push (TV_SYMOUT);
1030
1031 #ifdef DWARF2_UNWIND_INFO
1032 if (dwarf2out_do_frame ())
1033 dwarf2out_frame_finish ();
1034 #endif
1035
1036 (*debug_hooks->finish) (main_input_filename);
1037 timevar_pop (TV_SYMOUT);
1038
1039 /* Output some stuff at end of file if nec. */
1040
1041 dw2_output_indirect_constants ();
1042
1043 /* Flush any pending external directives. cgraph did this for
1044 assemble_external calls from the front end, but the RTL
1045 expander can also generate them. */
1046 process_pending_assemble_externals ();
1047
1048 /* Flush any pending equate directives. */
1049 process_pending_assemble_output_defs ();
1050
1051 /* Attach a special .ident directive to the end of the file to identify
1052 the version of GCC which compiled this code. The format of the .ident
1053 string is patterned after the ones produced by native SVR4 compilers. */
1054 #ifdef IDENT_ASM_OP
1055 if (!flag_no_ident)
1056 fprintf (asm_out_file, "%s\"GCC: (GNU) %s\"\n",
1057 IDENT_ASM_OP, version_string);
1058 #endif
1059
1060 /* This must be at the end. Some target ports emit end of file directives
1061 into the assembly file here, and hence we can not output anything to the
1062 assembly file after this point. */
1063 targetm.asm_out.file_end ();
1064 }
1065
1066 /* Display help for target options. */
1067 void
1068 display_target_options (void)
1069 {
1070 int undoc, i;
1071 unsigned int cli;
1072 static bool displayed = false;
1073
1074 /* Avoid double printing for --help --target-help. */
1075 if (displayed)
1076 return;
1077
1078 displayed = true;
1079
1080 for (cli = 0; cli < cl_options_count; cli++)
1081 if ((cl_options[cli].flags & (CL_TARGET | CL_UNDOCUMENTED)) == CL_TARGET)
1082 break;
1083
1084 if (cli < cl_options_count
1085 #ifdef TARGET_SWITCHES
1086 || ARRAY_SIZE (target_switches) > 1
1087 #endif
1088 #ifdef TARGET_OPTIONS
1089 || ARRAY_SIZE (target_options) > 1
1090 #endif
1091 )
1092 {
1093 int doc = cli < cl_options_count;
1094
1095 undoc = 0;
1096
1097 printf (_("\nTarget specific options:\n"));
1098
1099 #ifdef TARGET_SWITCHES
1100 for (i = ARRAY_SIZE (target_switches); i--;)
1101 {
1102 const char *option = target_switches[i].name;
1103 const char *description = target_switches[i].description;
1104
1105 if (option == NULL || *option == 0)
1106 continue;
1107 else if (description == NULL)
1108 {
1109 undoc = 1;
1110
1111 if (extra_warnings)
1112 printf (_(" -m%-23s [undocumented]\n"), option);
1113 }
1114 else if (*description != 0)
1115 doc += printf (" -m%-23s %s\n", option, _(description));
1116 }
1117 #endif
1118
1119 #ifdef TARGET_OPTIONS
1120 for (i = ARRAY_SIZE (target_options); i--;)
1121 {
1122 const char *option = target_options[i].prefix;
1123 const char *description = target_options[i].description;
1124
1125 if (option == NULL || *option == 0)
1126 continue;
1127 else if (description == NULL)
1128 {
1129 undoc = 1;
1130
1131 if (extra_warnings)
1132 printf (_(" -m%-23s [undocumented]\n"), option);
1133 }
1134 else if (*description != 0)
1135 doc += printf (" -m%-23s %s\n", option, _(description));
1136 }
1137 #endif
1138 print_filtered_help (CL_TARGET);
1139 if (undoc)
1140 {
1141 if (doc)
1142 printf (_("\nThere are undocumented target specific options as well.\n"));
1143 else
1144 printf (_(" They exist, but they are not documented.\n"));
1145 }
1146 }
1147 }
1148
1149 /* Parse a -d... command line switch. */
1150
1151 void
1152 decode_d_option (const char *arg)
1153 {
1154 int c;
1155
1156 while (*arg)
1157 switch (c = *arg++)
1158 {
1159 case 'A':
1160 flag_debug_asm = 1;
1161 break;
1162 case 'p':
1163 flag_print_asm_name = 1;
1164 break;
1165 case 'P':
1166 flag_dump_rtl_in_asm = 1;
1167 flag_print_asm_name = 1;
1168 break;
1169 case 'v':
1170 graph_dump_format = vcg;
1171 break;
1172 case 'x':
1173 rtl_dump_and_exit = 1;
1174 break;
1175 case 'y':
1176 set_yydebug = 1;
1177 break;
1178 case 'D': /* These are handled by the preprocessor. */
1179 case 'I':
1180 break;
1181 case 'H':
1182 setup_core_dumping();
1183 break;
1184
1185 case 'a':
1186 default:
1187 if (!enable_rtl_dump_file (c))
1188 warning ("unrecognized gcc debugging option: %c", c);
1189 break;
1190 }
1191 }
1192
1193 /* Indexed by enum debug_info_type. */
1194 const char *const debug_type_names[] =
1195 {
1196 "none", "stabs", "coff", "dwarf-2", "xcoff", "vms"
1197 };
1198
1199 /* Decode -m switches. */
1200 /* Decode the switch -mNAME. */
1201
1202 void
1203 set_target_switch (const char *name)
1204 {
1205 #if defined (TARGET_SWITCHES) || defined (TARGET_OPTIONS)
1206 size_t j;
1207 #endif
1208 int valid_target_option = 0;
1209
1210 #ifdef TARGET_SWITCHES
1211 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
1212 if (!strcmp (target_switches[j].name, name))
1213 {
1214 if (target_switches[j].value < 0)
1215 target_flags &= ~-target_switches[j].value;
1216 else
1217 target_flags |= target_switches[j].value;
1218 if (name[0] != 0)
1219 {
1220 if (target_switches[j].value < 0)
1221 target_flags_explicit |= -target_switches[j].value;
1222 else
1223 target_flags_explicit |= target_switches[j].value;
1224 }
1225 valid_target_option = 1;
1226 }
1227 #endif
1228
1229 #ifdef TARGET_OPTIONS
1230 if (!valid_target_option)
1231 for (j = 0; j < ARRAY_SIZE (target_options); j++)
1232 {
1233 int len = strlen (target_options[j].prefix);
1234 if (target_options[j].value)
1235 {
1236 if (!strcmp (target_options[j].prefix, name))
1237 {
1238 *target_options[j].variable = target_options[j].value;
1239 valid_target_option = 1;
1240 }
1241 }
1242 else
1243 {
1244 if (!strncmp (target_options[j].prefix, name, len))
1245 {
1246 *target_options[j].variable = name + len;
1247 valid_target_option = 1;
1248 }
1249 }
1250 }
1251 #endif
1252
1253 if (name[0] != 0 && !valid_target_option)
1254 error ("invalid option %qs", name);
1255 }
1256
1257 /* Print version information to FILE.
1258 Each line begins with INDENT (for the case where FILE is the
1259 assembler output file). */
1260
1261 void
1262 print_version (FILE *file, const char *indent)
1263 {
1264 #ifndef __VERSION__
1265 #define __VERSION__ "[?]"
1266 #endif
1267 fnotice (file,
1268 #ifdef __GNUC__
1269 "%s%s%s version %s (%s)\n%s\tcompiled by GNU C version %s.\n"
1270 #else
1271 "%s%s%s version %s (%s) compiled by CC.\n"
1272 #endif
1273 , indent, *indent != 0 ? " " : "",
1274 lang_hooks.name, version_string, TARGET_NAME,
1275 indent, __VERSION__);
1276 fnotice (file, "%s%sGGC heuristics: --param ggc-min-expand=%d --param ggc-min-heapsize=%d\n",
1277 indent, *indent != 0 ? " " : "",
1278 PARAM_VALUE (GGC_MIN_EXPAND), PARAM_VALUE (GGC_MIN_HEAPSIZE));
1279 }
1280
1281 /* Print an option value and return the adjusted position in the line.
1282 ??? We don't handle error returns from fprintf (disk full); presumably
1283 other code will catch a disk full though. */
1284
1285 static int
1286 print_single_switch (FILE *file, int pos, int max,
1287 const char *indent, const char *sep, const char *term,
1288 const char *type, const char *name)
1289 {
1290 /* The ultrix fprintf returns 0 on success, so compute the result we want
1291 here since we need it for the following test. */
1292 int len = strlen (sep) + strlen (type) + strlen (name);
1293
1294 if (pos != 0
1295 && pos + len > max)
1296 {
1297 fprintf (file, "%s", term);
1298 pos = 0;
1299 }
1300 if (pos == 0)
1301 {
1302 fprintf (file, "%s", indent);
1303 pos = strlen (indent);
1304 }
1305 fprintf (file, "%s%s%s", sep, type, name);
1306 pos += len;
1307 return pos;
1308 }
1309
1310 /* Print active target switches to FILE.
1311 POS is the current cursor position and MAX is the size of a "line".
1312 Each line begins with INDENT and ends with TERM.
1313 Each switch is separated from the next by SEP. */
1314
1315 static void
1316 print_switch_values (FILE *file, int pos, int max,
1317 const char *indent, const char *sep, const char *term)
1318 {
1319 size_t j;
1320 const char **p;
1321
1322 /* Fill in the -frandom-seed option, if the user didn't pass it, so
1323 that it can be printed below. This helps reproducibility. */
1324 randomize ();
1325
1326 /* Print the options as passed. */
1327 pos = print_single_switch (file, pos, max, indent, *indent ? " " : "", term,
1328 _("options passed: "), "");
1329
1330 for (p = &save_argv[1]; *p != NULL; p++)
1331 if (**p == '-')
1332 {
1333 /* Ignore these. */
1334 if (strcmp (*p, "-o") == 0)
1335 {
1336 if (p[1] != NULL)
1337 p++;
1338 continue;
1339 }
1340 if (strcmp (*p, "-quiet") == 0)
1341 continue;
1342 if (strcmp (*p, "-version") == 0)
1343 continue;
1344 if ((*p)[1] == 'd')
1345 continue;
1346
1347 pos = print_single_switch (file, pos, max, indent, sep, term, *p, "");
1348 }
1349 if (pos > 0)
1350 fprintf (file, "%s", term);
1351
1352 /* Print the -f and -m options that have been enabled.
1353 We don't handle language specific options but printing argv
1354 should suffice. */
1355
1356 pos = print_single_switch (file, 0, max, indent, *indent ? " " : "", term,
1357 _("options enabled: "), "");
1358
1359 for (j = 0; j < cl_options_count; j++)
1360 if ((cl_options[j].flags & CL_REPORT)
1361 && option_enabled (&cl_options[j]) > 0)
1362 pos = print_single_switch (file, pos, max, indent, sep, term,
1363 "", cl_options[j].opt_text);
1364
1365 /* Print target specific options. */
1366
1367 #ifdef TARGET_SWITCHES
1368 for (j = 0; j < ARRAY_SIZE (target_switches); j++)
1369 if (target_switches[j].name[0] != '\0'
1370 && target_switches[j].value > 0
1371 && ((target_switches[j].value & target_flags)
1372 == target_switches[j].value))
1373 {
1374 pos = print_single_switch (file, pos, max, indent, sep, term,
1375 "-m", target_switches[j].name);
1376 }
1377 #endif
1378
1379 #ifdef TARGET_OPTIONS
1380 for (j = 0; j < ARRAY_SIZE (target_options); j++)
1381 if (*target_options[j].variable != NULL)
1382 {
1383 char prefix[256];
1384 sprintf (prefix, "-m%s", target_options[j].prefix);
1385 pos = print_single_switch (file, pos, max, indent, sep, term,
1386 prefix, *target_options[j].variable);
1387 }
1388 #endif
1389
1390 fprintf (file, "%s", term);
1391 }
1392
1393 /* Open assembly code output file. Do this even if -fsyntax-only is
1394 on, because then the driver will have provided the name of a
1395 temporary file or bit bucket for us. NAME is the file specified on
1396 the command line, possibly NULL. */
1397 static void
1398 init_asm_output (const char *name)
1399 {
1400 if (name == NULL && asm_file_name == 0)
1401 asm_out_file = stdout;
1402 else
1403 {
1404 if (asm_file_name == 0)
1405 {
1406 int len = strlen (dump_base_name);
1407 char *dumpname = xmalloc (len + 6);
1408 memcpy (dumpname, dump_base_name, len + 1);
1409 strip_off_ending (dumpname, len);
1410 strcat (dumpname, ".s");
1411 asm_file_name = dumpname;
1412 }
1413 if (!strcmp (asm_file_name, "-"))
1414 asm_out_file = stdout;
1415 else
1416 asm_out_file = fopen (asm_file_name, "w+b");
1417 if (asm_out_file == 0)
1418 fatal_error ("can%'t open %s for writing: %m", asm_file_name);
1419 }
1420
1421 if (!flag_syntax_only)
1422 {
1423 targetm.asm_out.file_start ();
1424
1425 #ifdef ASM_COMMENT_START
1426 if (flag_verbose_asm)
1427 {
1428 /* Print the list of options in effect. */
1429 print_version (asm_out_file, ASM_COMMENT_START);
1430 print_switch_values (asm_out_file, 0, MAX_LINE,
1431 ASM_COMMENT_START, " ", "\n");
1432 /* Add a blank line here so it appears in assembler output but not
1433 screen output. */
1434 fprintf (asm_out_file, "\n");
1435 }
1436 #endif
1437 }
1438 }
1439
1440 /* Default version of get_pch_validity.
1441 By default, every flag difference is fatal; that will be mostly right for
1442 most targets, but completely right for very few. */
1443
1444 void *
1445 default_get_pch_validity (size_t *len)
1446 {
1447 #ifdef TARGET_OPTIONS
1448 size_t i;
1449 #endif
1450 char *result, *r;
1451
1452 *len = sizeof (target_flags) + 2;
1453 #ifdef TARGET_OPTIONS
1454 for (i = 0; i < ARRAY_SIZE (target_options); i++)
1455 {
1456 *len += 1;
1457 if (*target_options[i].variable)
1458 *len += strlen (*target_options[i].variable);
1459 }
1460 #endif
1461
1462 result = r = xmalloc (*len);
1463 r[0] = flag_pic;
1464 r[1] = flag_pie;
1465 r += 2;
1466 memcpy (r, &target_flags, sizeof (target_flags));
1467 r += sizeof (target_flags);
1468
1469 #ifdef TARGET_OPTIONS
1470 for (i = 0; i < ARRAY_SIZE (target_options); i++)
1471 {
1472 const char *str = *target_options[i].variable;
1473 size_t l;
1474 if (! str)
1475 str = "";
1476 l = strlen (str) + 1;
1477 memcpy (r, str, l);
1478 r += l;
1479 }
1480 #endif
1481
1482 return result;
1483 }
1484
1485 /* Default version of pch_valid_p. */
1486
1487 const char *
1488 default_pch_valid_p (const void *data_p, size_t len)
1489 {
1490 const char *data = (const char *)data_p;
1491 const char *flag_that_differs = NULL;
1492 size_t i;
1493
1494 /* -fpic and -fpie also usually make a PCH invalid. */
1495 if (data[0] != flag_pic)
1496 return _("created and used with different settings of -fpic");
1497 if (data[1] != flag_pie)
1498 return _("created and used with different settings of -fpie");
1499 data += 2;
1500
1501 /* Check target_flags. */
1502 if (memcmp (data, &target_flags, sizeof (target_flags)) != 0)
1503 {
1504 int tf;
1505
1506 memcpy (&tf, data, sizeof (target_flags));
1507 #ifdef TARGET_SWITCHES
1508 for (i = 0; i < ARRAY_SIZE (target_switches); i++)
1509 {
1510 int bits;
1511
1512 bits = target_switches[i].value;
1513 if (bits < 0)
1514 bits = -bits;
1515 if ((target_flags & bits) != (tf & bits))
1516 {
1517 flag_that_differs = target_switches[i].name;
1518 goto make_message;
1519 }
1520 }
1521 #endif
1522 for (i = 0; i < cl_options_count; i++)
1523 if (cl_options[i].flag_var == &target_flags
1524 && (cl_options[i].var_value & (target_flags ^ tf)) != 0)
1525 {
1526 flag_that_differs = cl_options[i].opt_text + 2;
1527 goto make_message;
1528 }
1529 gcc_unreachable ();
1530 }
1531 data += sizeof (target_flags);
1532 len -= sizeof (target_flags);
1533
1534 /* Check string options. */
1535 #ifdef TARGET_OPTIONS
1536 for (i = 0; i < ARRAY_SIZE (target_options); i++)
1537 {
1538 const char *str = *target_options[i].variable;
1539 size_t l;
1540 if (! str)
1541 str = "";
1542 l = strlen (str) + 1;
1543 if (len < l || memcmp (data, str, l) != 0)
1544 {
1545 flag_that_differs = target_options[i].prefix;
1546 goto make_message;
1547 }
1548 data += l;
1549 len -= l;
1550 }
1551 #endif
1552
1553 return NULL;
1554
1555 make_message:
1556 {
1557 char *r;
1558 asprintf (&r, _("created and used with differing settings of '-m%s'"),
1559 flag_that_differs);
1560 if (r == NULL)
1561 return _("out of memory");
1562 return r;
1563 }
1564 }
1565
1566 /* Default tree printer. Handles declarations only. */
1567 static bool
1568 default_tree_printer (pretty_printer * pp, text_info *text)
1569 {
1570 tree t;
1571
1572 switch (*text->format_spec)
1573 {
1574 case 'D':
1575 t = va_arg (*text->args_ptr, tree);
1576 if (DECL_DEBUG_EXPR (t) && DECL_DEBUG_EXPR_IS_FROM (t))
1577 t = DECL_DEBUG_EXPR (t);
1578 break;
1579
1580 case 'F':
1581 case 'T':
1582 t = va_arg (*text->args_ptr, tree);
1583 break;
1584
1585 default:
1586 return false;
1587 }
1588
1589 if (DECL_P (t))
1590 {
1591 const char *n = DECL_NAME (t)
1592 ? lang_hooks.decl_printable_name (t, 2)
1593 : "<anonymous>";
1594 pp_string (pp, n);
1595 }
1596 else
1597 dump_generic_node (pp, t, 0, 0, 0);
1598
1599 return true;
1600 }
1601
1602 /* Initialization of the front end environment, before command line
1603 options are parsed. Signal handlers, internationalization etc.
1604 ARGV0 is main's argv[0]. */
1605 static void
1606 general_init (const char *argv0)
1607 {
1608 const char *p;
1609
1610 p = argv0 + strlen (argv0);
1611 while (p != argv0 && !IS_DIR_SEPARATOR (p[-1]))
1612 --p;
1613 progname = p;
1614
1615 xmalloc_set_program_name (progname);
1616
1617 hex_init ();
1618
1619 gcc_init_libintl ();
1620
1621 /* Initialize the diagnostics reporting machinery, so option parsing
1622 can give warnings and errors. */
1623 diagnostic_initialize (global_dc);
1624 /* Set a default printer. Language specific initializations will
1625 override it later. */
1626 pp_format_decoder (global_dc->printer) = &default_tree_printer;
1627
1628 /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages. */
1629 #ifdef SIGSEGV
1630 signal (SIGSEGV, crash_signal);
1631 #endif
1632 #ifdef SIGILL
1633 signal (SIGILL, crash_signal);
1634 #endif
1635 #ifdef SIGBUS
1636 signal (SIGBUS, crash_signal);
1637 #endif
1638 #ifdef SIGABRT
1639 signal (SIGABRT, crash_signal);
1640 #endif
1641 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
1642 signal (SIGIOT, crash_signal);
1643 #endif
1644 #ifdef SIGFPE
1645 signal (SIGFPE, crash_signal);
1646 #endif
1647
1648 /* Other host-specific signal setup. */
1649 (*host_hooks.extra_signals)();
1650
1651 /* Initialize the garbage-collector, string pools and tree type hash
1652 table. */
1653 init_ggc ();
1654 init_stringpool ();
1655 linemap_init (&line_table);
1656 init_ttree ();
1657
1658 /* Initialize register usage now so switches may override. */
1659 init_reg_sets ();
1660
1661 /* Register the language-independent parameters. */
1662 add_params (lang_independent_params, LAST_PARAM);
1663
1664 /* This must be done after add_params but before argument processing. */
1665 init_ggc_heuristics();
1666 init_tree_optimization_passes ();
1667 }
1668
1669 /* Process the options that have been parsed. */
1670 static void
1671 process_options (void)
1672 {
1673 /* Allow the front end to perform consistency checks and do further
1674 initialization based on the command line options. This hook also
1675 sets the original filename if appropriate (e.g. foo.i -> foo.c)
1676 so we can correctly initialize debug output. */
1677 no_backend = lang_hooks.post_options (&main_input_filename);
1678 #ifndef USE_MAPPED_LOCATION
1679 input_filename = main_input_filename;
1680 #endif
1681
1682 #ifdef OVERRIDE_OPTIONS
1683 /* Some machines may reject certain combinations of options. */
1684 OVERRIDE_OPTIONS;
1685 #endif
1686
1687 if (flag_short_enums == 2)
1688 flag_short_enums = targetm.default_short_enums ();
1689
1690 /* Set aux_base_name if not already set. */
1691 if (aux_base_name)
1692 ;
1693 else if (main_input_filename)
1694 {
1695 char *name = xstrdup (lbasename (main_input_filename));
1696
1697 strip_off_ending (name, strlen (name));
1698 aux_base_name = name;
1699 }
1700 else
1701 aux_base_name = "gccaux";
1702
1703 /* Set up the align_*_log variables, defaulting them to 1 if they
1704 were still unset. */
1705 if (align_loops <= 0) align_loops = 1;
1706 if (align_loops_max_skip > align_loops || !align_loops)
1707 align_loops_max_skip = align_loops - 1;
1708 align_loops_log = floor_log2 (align_loops * 2 - 1);
1709 if (align_jumps <= 0) align_jumps = 1;
1710 if (align_jumps_max_skip > align_jumps || !align_jumps)
1711 align_jumps_max_skip = align_jumps - 1;
1712 align_jumps_log = floor_log2 (align_jumps * 2 - 1);
1713 if (align_labels <= 0) align_labels = 1;
1714 align_labels_log = floor_log2 (align_labels * 2 - 1);
1715 if (align_labels_max_skip > align_labels || !align_labels)
1716 align_labels_max_skip = align_labels - 1;
1717 if (align_functions <= 0) align_functions = 1;
1718 align_functions_log = floor_log2 (align_functions * 2 - 1);
1719
1720 /* Unrolling all loops implies that standard loop unrolling must also
1721 be done. */
1722 if (flag_unroll_all_loops)
1723 flag_unroll_loops = 1;
1724
1725 /* The loop unrolling code assumes that cse will be run after loop. */
1726 if (flag_unroll_loops || flag_peel_loops)
1727 flag_rerun_cse_after_loop = 1;
1728
1729 /* If explicitly asked to run new loop optimizer, switch off the old
1730 one. */
1731 if (flag_loop_optimize2)
1732 flag_loop_optimize = 0;
1733
1734 /* Enable new loop optimizer pass if any of its optimizations is called. */
1735 if (flag_move_loop_invariants
1736 || flag_unswitch_loops
1737 || flag_peel_loops
1738 || flag_unroll_loops
1739 || flag_branch_on_count_reg)
1740 flag_loop_optimize2 = 1;
1741
1742 if (flag_non_call_exceptions)
1743 flag_asynchronous_unwind_tables = 1;
1744 if (flag_asynchronous_unwind_tables)
1745 flag_unwind_tables = 1;
1746
1747 /* Disable unit-at-a-time mode for frontends not supporting callgraph
1748 interface. */
1749 if (flag_unit_at_a_time && ! lang_hooks.callgraph.expand_function)
1750 flag_unit_at_a_time = 0;
1751
1752 if (flag_value_profile_transformations)
1753 flag_profile_values = 1;
1754
1755 /* Speculative prefetching implies the value profiling. We also switch off
1756 the prefetching in the loop optimizer, so that we do not emit double
1757 prefetches. TODO -- we should teach these two to cooperate; the loop
1758 based prefetching may sometimes do a better job, especially in connection
1759 with reuse analysis. */
1760 if (flag_speculative_prefetching)
1761 {
1762 flag_profile_values = 1;
1763 flag_prefetch_loop_arrays = 0;
1764 }
1765
1766 /* Warn about options that are not supported on this machine. */
1767 #ifndef INSN_SCHEDULING
1768 if (flag_schedule_insns || flag_schedule_insns_after_reload)
1769 warning ("instruction scheduling not supported on this target machine");
1770 #endif
1771 #ifndef DELAY_SLOTS
1772 if (flag_delayed_branch)
1773 warning ("this target machine does not have delayed branches");
1774 #endif
1775
1776 if (flag_tree_based_profiling && flag_profile_values)
1777 sorry ("value-based profiling not yet implemented in trees.");
1778
1779 user_label_prefix = USER_LABEL_PREFIX;
1780 if (flag_leading_underscore != -1)
1781 {
1782 /* If the default prefix is more complicated than "" or "_",
1783 issue a warning and ignore this option. */
1784 if (user_label_prefix[0] == 0 ||
1785 (user_label_prefix[0] == '_' && user_label_prefix[1] == 0))
1786 {
1787 user_label_prefix = flag_leading_underscore ? "_" : "";
1788 }
1789 else
1790 warning ("-f%sleading-underscore not supported on this target machine",
1791 flag_leading_underscore ? "" : "no-");
1792 }
1793
1794 /* If we are in verbose mode, write out the version and maybe all the
1795 option flags in use. */
1796 if (version_flag)
1797 {
1798 print_version (stderr, "");
1799 if (! quiet_flag)
1800 print_switch_values (stderr, 0, MAX_LINE, "", " ", "\n");
1801 }
1802
1803 if (flag_syntax_only)
1804 {
1805 write_symbols = NO_DEBUG;
1806 profile_flag = 0;
1807 }
1808
1809 /* A lot of code assumes write_symbols == NO_DEBUG if the debugging
1810 level is 0. */
1811 if (debug_info_level == DINFO_LEVEL_NONE)
1812 write_symbols = NO_DEBUG;
1813
1814 /* Now we know write_symbols, set up the debug hooks based on it.
1815 By default we do nothing for debug output. */
1816 if (PREFERRED_DEBUGGING_TYPE == NO_DEBUG)
1817 default_debug_hooks = &do_nothing_debug_hooks;
1818 #if defined(DBX_DEBUGGING_INFO)
1819 else if (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG)
1820 default_debug_hooks = &dbx_debug_hooks;
1821 #endif
1822 #if defined(XCOFF_DEBUGGING_INFO)
1823 else if (PREFERRED_DEBUGGING_TYPE == XCOFF_DEBUG)
1824 default_debug_hooks = &xcoff_debug_hooks;
1825 #endif
1826 #ifdef SDB_DEBUGGING_INFO
1827 else if (PREFERRED_DEBUGGING_TYPE == SDB_DEBUG)
1828 default_debug_hooks = &sdb_debug_hooks;
1829 #endif
1830 #ifdef DWARF2_DEBUGGING_INFO
1831 else if (PREFERRED_DEBUGGING_TYPE == DWARF2_DEBUG)
1832 default_debug_hooks = &dwarf2_debug_hooks;
1833 #endif
1834 #ifdef VMS_DEBUGGING_INFO
1835 else if (PREFERRED_DEBUGGING_TYPE == VMS_DEBUG
1836 || PREFERRED_DEBUGGING_TYPE == VMS_AND_DWARF2_DEBUG)
1837 default_debug_hooks = &vmsdbg_debug_hooks;
1838 #endif
1839
1840 debug_hooks = &do_nothing_debug_hooks;
1841 if (write_symbols == NO_DEBUG)
1842 ;
1843 #if defined(DBX_DEBUGGING_INFO)
1844 else if (write_symbols == DBX_DEBUG)
1845 debug_hooks = &dbx_debug_hooks;
1846 #endif
1847 #if defined(XCOFF_DEBUGGING_INFO)
1848 else if (write_symbols == XCOFF_DEBUG)
1849 debug_hooks = &xcoff_debug_hooks;
1850 #endif
1851 #ifdef SDB_DEBUGGING_INFO
1852 else if (write_symbols == SDB_DEBUG)
1853 debug_hooks = &sdb_debug_hooks;
1854 #endif
1855 #ifdef DWARF2_DEBUGGING_INFO
1856 else if (write_symbols == DWARF2_DEBUG)
1857 debug_hooks = &dwarf2_debug_hooks;
1858 #endif
1859 #ifdef VMS_DEBUGGING_INFO
1860 else if (write_symbols == VMS_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG)
1861 debug_hooks = &vmsdbg_debug_hooks;
1862 #endif
1863 else
1864 error ("target system does not support the \"%s\" debug format",
1865 debug_type_names[write_symbols]);
1866
1867 /* Now we know which debug output will be used so we can set
1868 flag_var_tracking, flag_rename_registers if the user has
1869 not specified them. */
1870 if (debug_info_level < DINFO_LEVEL_NORMAL
1871 || debug_hooks->var_location == do_nothing_debug_hooks.var_location)
1872 {
1873 if (flag_var_tracking == 1)
1874 {
1875 if (debug_info_level < DINFO_LEVEL_NORMAL)
1876 warning ("variable tracking requested, but useless unless "
1877 "producing debug info");
1878 else
1879 warning ("variable tracking requested, but not supported "
1880 "by this debug format");
1881 }
1882 flag_var_tracking = 0;
1883 }
1884
1885 if (flag_rename_registers == AUTODETECT_FLAG_VAR_TRACKING)
1886 flag_rename_registers = default_debug_hooks->var_location
1887 != do_nothing_debug_hooks.var_location;
1888
1889 if (flag_var_tracking == AUTODETECT_FLAG_VAR_TRACKING)
1890 flag_var_tracking = optimize >= 1;
1891
1892 /* If auxiliary info generation is desired, open the output file.
1893 This goes in the same directory as the source file--unlike
1894 all the other output files. */
1895 if (flag_gen_aux_info)
1896 {
1897 aux_info_file = fopen (aux_info_file_name, "w");
1898 if (aux_info_file == 0)
1899 fatal_error ("can%'t open %s: %m", aux_info_file_name);
1900 }
1901
1902 if (! targetm.have_named_sections)
1903 {
1904 if (flag_function_sections)
1905 {
1906 warning ("-ffunction-sections not supported for this target");
1907 flag_function_sections = 0;
1908 }
1909 if (flag_data_sections)
1910 {
1911 warning ("-fdata-sections not supported for this target");
1912 flag_data_sections = 0;
1913 }
1914 }
1915
1916 if (flag_function_sections && profile_flag)
1917 {
1918 warning ("-ffunction-sections disabled; it makes profiling impossible");
1919 flag_function_sections = 0;
1920 }
1921
1922 #ifndef HAVE_prefetch
1923 if (flag_prefetch_loop_arrays)
1924 {
1925 warning ("-fprefetch-loop-arrays not supported for this target");
1926 flag_prefetch_loop_arrays = 0;
1927 }
1928 if (flag_speculative_prefetching)
1929 {
1930 if (flag_speculative_prefetching_set)
1931 warning ("-fspeculative-prefetching not supported for this target");
1932 flag_speculative_prefetching = 0;
1933 }
1934 #else
1935 if (flag_prefetch_loop_arrays && !HAVE_prefetch)
1936 {
1937 warning ("-fprefetch-loop-arrays not supported for this target (try -march switches)");
1938 flag_prefetch_loop_arrays = 0;
1939 }
1940 if (flag_speculative_prefetching && !HAVE_prefetch)
1941 {
1942 if (flag_speculative_prefetching_set)
1943 warning ("-fspeculative-prefetching not supported for this target (try -march switches)");
1944 flag_speculative_prefetching = 0;
1945 }
1946 #endif
1947
1948 /* This combination of options isn't handled for i386 targets and doesn't
1949 make much sense anyway, so don't allow it. */
1950 if (flag_prefetch_loop_arrays && optimize_size)
1951 {
1952 warning ("-fprefetch-loop-arrays is not supported with -Os");
1953 flag_prefetch_loop_arrays = 0;
1954 }
1955
1956 #ifndef OBJECT_FORMAT_ELF
1957 if (flag_function_sections && write_symbols != NO_DEBUG)
1958 warning ("-ffunction-sections may affect debugging on some targets");
1959 #endif
1960
1961 /* The presence of IEEE signaling NaNs, implies all math can trap. */
1962 if (flag_signaling_nans)
1963 flag_trapping_math = 1;
1964
1965 /* With -fcx-limited-range, we do cheap and quick complex arithmetic. */
1966 if (flag_cx_limited_range)
1967 flag_complex_method = 0;
1968 }
1969
1970 /* Initialize the compiler back end. */
1971 static void
1972 backend_init (void)
1973 {
1974 init_emit_once (debug_info_level == DINFO_LEVEL_NORMAL
1975 || debug_info_level == DINFO_LEVEL_VERBOSE
1976 #ifdef VMS_DEBUGGING_INFO
1977 /* Enable line number info for traceback. */
1978 || debug_info_level > DINFO_LEVEL_NONE
1979 #endif
1980 || flag_test_coverage);
1981
1982 init_rtlanal ();
1983 init_regs ();
1984 init_fake_stack_mems ();
1985 init_alias_once ();
1986 init_loop ();
1987 init_reload ();
1988 init_function_once ();
1989 init_varasm_once ();
1990
1991 /* The following initialization functions need to generate rtl, so
1992 provide a dummy function context for them. */
1993 init_dummy_function_start ();
1994 init_expmed ();
1995 if (flag_caller_saves)
1996 init_caller_save ();
1997 expand_dummy_function_end ();
1998 }
1999
2000 /* Language-dependent initialization. Returns nonzero on success. */
2001 static int
2002 lang_dependent_init (const char *name)
2003 {
2004 location_t save_loc = input_location;
2005 if (dump_base_name == 0)
2006 dump_base_name = name && name[0] ? name : "gccdump";
2007
2008 /* Other front-end initialization. */
2009 #ifdef USE_MAPPED_LOCATION
2010 input_location = BUILTINS_LOCATION;
2011 #else
2012 input_filename = "<built-in>";
2013 input_line = 0;
2014 #endif
2015 if (lang_hooks.init () == 0)
2016 return 0;
2017 input_location = save_loc;
2018
2019 init_asm_output (name);
2020
2021 /* These create various _DECL nodes, so need to be called after the
2022 front end is initialized. */
2023 init_eh ();
2024 init_optabs ();
2025
2026 /* The following initialization functions need to generate rtl, so
2027 provide a dummy function context for them. */
2028 init_dummy_function_start ();
2029 init_expr_once ();
2030 expand_dummy_function_end ();
2031
2032 /* If dbx symbol table desired, initialize writing it and output the
2033 predefined types. */
2034 timevar_push (TV_SYMOUT);
2035
2036 #ifdef DWARF2_UNWIND_INFO
2037 if (dwarf2out_do_frame ())
2038 dwarf2out_frame_init ();
2039 #endif
2040
2041 /* Now we have the correct original filename, we can initialize
2042 debug output. */
2043 (*debug_hooks->init) (name);
2044
2045 timevar_pop (TV_SYMOUT);
2046
2047 return 1;
2048 }
2049
2050 /* Clean up: close opened files, etc. */
2051
2052 static void
2053 finalize (void)
2054 {
2055 /* Close the dump files. */
2056 if (flag_gen_aux_info)
2057 {
2058 fclose (aux_info_file);
2059 if (errorcount)
2060 unlink (aux_info_file_name);
2061 }
2062
2063 /* Close non-debugging input and output files. Take special care to note
2064 whether fclose returns an error, since the pages might still be on the
2065 buffer chain while the file is open. */
2066
2067 if (asm_out_file)
2068 {
2069 if (ferror (asm_out_file) != 0)
2070 fatal_error ("error writing to %s: %m", asm_file_name);
2071 if (fclose (asm_out_file) != 0)
2072 fatal_error ("error closing %s: %m", asm_file_name);
2073 }
2074
2075 finish_optimization_passes ();
2076
2077 if (mem_report)
2078 {
2079 ggc_print_statistics ();
2080 stringpool_statistics ();
2081 dump_tree_statistics ();
2082 dump_rtx_statistics ();
2083 dump_varray_statistics ();
2084 dump_alloc_pool_statistics ();
2085 dump_ggc_loc_statistics ();
2086 }
2087
2088 /* Free up memory for the benefit of leak detectors. */
2089 free_reg_info ();
2090
2091 /* Language-specific end of compilation actions. */
2092 lang_hooks.finish ();
2093 }
2094
2095 /* Initialize the compiler, and compile the input file. */
2096 static void
2097 do_compile (void)
2098 {
2099 /* Initialize timing first. The C front ends read the main file in
2100 the post_options hook, and C++ does file timings. */
2101 if (time_report || !quiet_flag || flag_detailed_statistics)
2102 timevar_init ();
2103 timevar_start (TV_TOTAL);
2104
2105 process_options ();
2106
2107 /* Don't do any more if an error has already occurred. */
2108 if (!errorcount)
2109 {
2110 /* This must be run always, because it is needed to compute the FP
2111 predefined macros, such as __LDBL_MAX__, for targets using non
2112 default FP formats. */
2113 init_adjust_machine_modes ();
2114
2115 /* Set up the back-end if requested. */
2116 if (!no_backend)
2117 backend_init ();
2118
2119 /* Language-dependent initialization. Returns true on success. */
2120 if (lang_dependent_init (main_input_filename))
2121 compile_file ();
2122
2123 finalize ();
2124 }
2125
2126 /* Stop timing and print the times. */
2127 timevar_stop (TV_TOTAL);
2128 timevar_print (stderr);
2129 }
2130
2131 /* Entry point of cc1, cc1plus, jc1, f771, etc.
2132 Exit code is FATAL_EXIT_CODE if can't open files or if there were
2133 any errors, or SUCCESS_EXIT_CODE if compilation succeeded.
2134
2135 It is not safe to call this function more than once. */
2136
2137 int
2138 toplev_main (unsigned int argc, const char **argv)
2139 {
2140 save_argv = argv;
2141
2142 /* Initialization of GCC's environment, and diagnostics. */
2143 general_init (argv[0]);
2144
2145 /* Parse the options and do minimal processing; basically just
2146 enough to default flags appropriately. */
2147 decode_options (argc, argv);
2148
2149 randomize ();
2150
2151 /* Exit early if we can (e.g. -help). */
2152 if (!exit_after_options)
2153 do_compile ();
2154
2155 if (errorcount || sorrycount)
2156 return (FATAL_EXIT_CODE);
2157
2158 return (SUCCESS_EXIT_CODE);
2159 }