]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gcc.info-2
Makefile.in (install): Some of HEADERS come from the stl dir now.
[thirdparty/gcc.git] / gcc / gcc.info-2
CommitLineData
336b436a
JL
1This is Info file gcc.info, produced by Makeinfo version 1.68 from the
2input file gcc.texi.
3
4 This file documents the use and the internals of the GNU compiler.
5
6 Published by the Free Software Foundation 59 Temple Place - Suite 330
7Boston, MA 02111-1307 USA
8
9 Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997 Free
10Software Foundation, Inc.
11
12 Permission is granted to make and distribute verbatim copies of this
13manual provided the copyright notice and this permission notice are
14preserved on all copies.
15
16 Permission is granted to copy and distribute modified versions of
17this manual under the conditions for verbatim copying, provided also
18that the sections entitled "GNU General Public License," "Funding for
19Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
20included exactly as in the original, and provided that the entire
21resulting derived work is distributed under the terms of a permission
22notice identical to this one.
23
24 Permission is granted to copy and distribute translations of this
25manual into another language, under the above conditions for modified
26versions, except that the sections entitled "GNU General Public
27License," "Funding for Free Software," and "Protect Your Freedom--Fight
28`Look And Feel'", and this permission notice, may be included in
29translations approved by the Free Software Foundation instead of in the
30original English.
31
32\1f
33File: gcc.info, Node: Warning Options, Next: Debugging Options, Prev: C++ Dialect Options, Up: Invoking GCC
34
35Options to Request or Suppress Warnings
36=======================================
37
38 Warnings are diagnostic messages that report constructions which are
39not inherently erroneous but which are risky or suggest there may have
40been an error.
41
42 You can request many specific warnings with options beginning `-W',
43for example `-Wimplicit' to request warnings on implicit declarations.
44Each of these specific warning options also has a negative form
45beginning `-Wno-' to turn off warnings; for example, `-Wno-implicit'.
46This manual lists only one of the two forms, whichever is not the
47default.
48
49 These options control the amount and kinds of warnings produced by
50GNU CC:
51
52`-fsyntax-only'
53 Check the code for syntax errors, but don't do anything beyond
54 that.
55
56`-pedantic'
57 Issue all the warnings demanded by strict ANSI standard C; reject
58 all programs that use forbidden extensions.
59
60 Valid ANSI standard C programs should compile properly with or
61 without this option (though a rare few will require `-ansi').
62 However, without this option, certain GNU extensions and
63 traditional C features are supported as well. With this option,
64 they are rejected.
65
66 `-pedantic' does not cause warning messages for use of the
67 alternate keywords whose names begin and end with `__'. Pedantic
68 warnings are also disabled in the expression that follows
69 `__extension__'. However, only system header files should use
70 these escape routes; application programs should avoid them.
71 *Note Alternate Keywords::.
72
73 This option is not intended to be useful; it exists only to satisfy
74 pedants who would otherwise claim that GNU CC fails to support the
75 ANSI standard.
76
77 Some users try to use `-pedantic' to check programs for strict ANSI
78 C conformance. They soon find that it does not do quite what they
79 want: it finds some non-ANSI practices, but not all--only those
80 for which ANSI C *requires* a diagnostic.
81
82 A feature to report any failure to conform to ANSI C might be
83 useful in some instances, but would require considerable
84 additional work and would be quite different from `-pedantic'. We
85 recommend, rather, that users take advantage of the extensions of
86 GNU C and disregard the limitations of other compilers. Aside
87 from certain supercomputers and obsolete small machines, there is
88 less and less reason ever to use any other C compiler other than
89 for bootstrapping GNU CC.
90
91`-pedantic-errors'
92 Like `-pedantic', except that errors are produced rather than
93 warnings.
94
95`-w'
96 Inhibit all warning messages.
97
98`-Wno-import'
99 Inhibit warning messages about the use of `#import'.
100
101`-Wchar-subscripts'
102 Warn if an array subscript has type `char'. This is a common cause
103 of error, as programmers often forget that this type is signed on
104 some machines.
105
106`-Wcomment'
107 Warn whenever a comment-start sequence `/*' appears in a `/*'
108 comment, or whenever a Backslash-Newline appears in a `//' comment.
109
110`-Wformat'
111 Check calls to `printf' and `scanf', etc., to make sure that the
112 arguments supplied have types appropriate to the format string
113 specified.
114
115`-Wimplicit-int'
116 Warn when a declaration does not specify a type.
117
118`-Wimplicit-function-declarations'
119 Warn whenever a function is used before being declared.
120
121`-Wimplicit'
122 Same as `-Wimplicit-int' `-Wimplicit-function-declaration'.
123
124`-Wmain'
125 Warn if the type of `main' is suspicious. `main' should be a
126 function with external linkage, returning int, taking either zero
127 arguments, two, or three arguments of appropriate types.
128
129`-Wparentheses'
130 Warn if parentheses are omitted in certain contexts, such as when
131 there is an assignment in a context where a truth value is
132 expected, or when operators are nested whose precedence people
133 often get confused about.
134
135 Also warn about constructions where there may be confusion to which
136 `if' statement an `else' branch belongs. Here is an example of
137 such a case:
138
139 {
140 if (a)
141 if (b)
142 foo ();
143 else
144 bar ();
145 }
146
147 In C, every `else' branch belongs to the innermost possible `if'
148 statement, which in this example is `if (b)'. This is often not
149 what the programmer expected, as illustrated in the above example
150 by indentation the programmer chose. When there is the potential
151 for this confusion, GNU C will issue a warning when this flag is
152 specified. To eliminate the warning, add explicit braces around
153 the innermost `if' statement so there is no way the `else' could
154 belong to the enclosing `if'. The resulting code would look like
155 this:
156
157 {
158 if (a)
159 {
160 if (b)
161 foo ();
162 else
163 bar ();
164 }
165 }
166
167`-Wreturn-type'
168 Warn whenever a function is defined with a return-type that
169 defaults to `int'. Also warn about any `return' statement with no
170 return-value in a function whose return-type is not `void'.
171
172`-Wswitch'
173 Warn whenever a `switch' statement has an index of enumeral type
174 and lacks a `case' for one or more of the named codes of that
175 enumeration. (The presence of a `default' label prevents this
176 warning.) `case' labels outside the enumeration range also
177 provoke warnings when this option is used.
178
179`-Wtrigraphs'
180 Warn if any trigraphs are encountered (assuming they are enabled).
181
182`-Wunused'
183 Warn whenever a variable is unused aside from its declaration,
184 whenever a function is declared static but never defined, whenever
185 a label is declared but not used, and whenever a statement
186 computes a result that is explicitly not used.
187
188 To suppress this warning for an expression, simply cast it to
189 void. For unused variables and parameters, use the `unused'
190 attribute (*note Variable Attributes::.).
191
192`-Wuninitialized'
193 An automatic variable is used without first being initialized.
194
195 These warnings are possible only in optimizing compilation,
196 because they require data flow information that is computed only
197 when optimizing. If you don't specify `-O', you simply won't get
198 these warnings.
199
200 These warnings occur only for variables that are candidates for
201 register allocation. Therefore, they do not occur for a variable
202 that is declared `volatile', or whose address is taken, or whose
203 size is other than 1, 2, 4 or 8 bytes. Also, they do not occur for
204 structures, unions or arrays, even when they are in registers.
205
206 Note that there may be no warning about a variable that is used
207 only to compute a value that itself is never used, because such
208 computations may be deleted by data flow analysis before the
209 warnings are printed.
210
211 These warnings are made optional because GNU CC is not smart
212 enough to see all the reasons why the code might be correct
213 despite appearing to have an error. Here is one example of how
214 this can happen:
215
216 {
217 int x;
218 switch (y)
219 {
220 case 1: x = 1;
221 break;
222 case 2: x = 4;
223 break;
224 case 3: x = 5;
225 }
226 foo (x);
227 }
228
229 If the value of `y' is always 1, 2 or 3, then `x' is always
230 initialized, but GNU CC doesn't know this. Here is another common
231 case:
232
233 {
234 int save_y;
235 if (change_y) save_y = y, y = new_y;
236 ...
237 if (change_y) y = save_y;
238 }
239
240 This has no bug because `save_y' is used only if it is set.
241
242 Some spurious warnings can be avoided if you declare all the
243 functions you use that never return as `noreturn'. *Note Function
244 Attributes::.
245
246`-Wreorder (C++ only)'
247 Warn when the order of member initializers given in the code does
248 not match the order in which they must be executed. For instance:
249
250 struct A {
251 int i;
252 int j;
253 A(): j (0), i (1) { }
254 };
255
256 Here the compiler will warn that the member initializers for `i'
257 and `j' will be rearranged to match the declaration order of the
258 members.
259
260`-Wtemplate-debugging'
261 When using templates in a C++ program, warn if debugging is not yet
262 fully available (C++ only).
263
264`-Wall'
265 All of the above `-W' options combined. This enables all the
266 warnings about constructions that some users consider
267 questionable, and that are easy to avoid (or modify to prevent the
268 warning), even in conjunction with macros.
269
270 The following `-W...' options are not implied by `-Wall'. Some of
271them warn about constructions that users generally do not consider
272questionable, but which occasionally you might wish to check for;
273others warn about constructions that are necessary or hard to avoid in
274some cases, and there is no simple way to modify the code to suppress
275the warning.
276
277`-W'
278 Print extra warning messages for these events:
279
280 * A nonvolatile automatic variable might be changed by a call to
281 `longjmp'. These warnings as well are possible only in
282 optimizing compilation.
283
284 The compiler sees only the calls to `setjmp'. It cannot know
285 where `longjmp' will be called; in fact, a signal handler
286 could call it at any point in the code. As a result, you may
287 get a warning even when there is in fact no problem because
288 `longjmp' cannot in fact be called at the place which would
289 cause a problem.
290
291 * A function can return either with or without a value.
292 (Falling off the end of the function body is considered
293 returning without a value.) For example, this function would
294 evoke such a warning:
295
296 foo (a)
297 {
298 if (a > 0)
299 return a;
300 }
301
302 * An expression-statement or the left-hand side of a comma
303 expression contains no side effects. To suppress the
304 warning, cast the unused expression to void. For example, an
305 expression such as `x[i,j]' will cause a warning, but
306 `x[(void)i,j]' will not.
307
308 * An unsigned value is compared against zero with `<' or `<='.
309
310 * A comparison like `x<=y<=z' appears; this is equivalent to
311 `(x<=y ? 1 : 0) <= z', which is a different interpretation
312 from that of ordinary mathematical notation.
313
314 * Storage-class specifiers like `static' are not the first
315 things in a declaration. According to the C Standard, this
316 usage is obsolescent.
317
318 * If `-Wall' or `-Wunused' is also specified, warn about unused
319 arguments.
320
321 * A comparison between signed and unsigned values could produce
322 an incorrect result when the signed value is converted to
323 unsigned. (But do not warn if `-Wno-sign-compare' is also
324 specified.)
325
326 * An aggregate has a partly bracketed initializer. For
327 example, the following code would evoke such a warning,
328 because braces are missing around the initializer for `x.h':
329
330 struct s { int f, g; };
331 struct t { struct s h; int i; };
332 struct t x = { 1, 2, 3 };
333
334`-Wtraditional'
335 Warn about certain constructs that behave differently in
336 traditional and ANSI C.
337
338 * Macro arguments occurring within string constants in the
339 macro body. These would substitute the argument in
340 traditional C, but are part of the constant in ANSI C.
341
342 * A function declared external in one block and then used after
343 the end of the block.
344
345 * A `switch' statement has an operand of type `long'.
346
347`-Wundef'
348 Warn if an undefined identifier is evaluated in an `#if' directive.
349
350`-Wshadow'
351 Warn whenever a local variable shadows another local variable.
352
353`-Wid-clash-LEN'
354 Warn whenever two distinct identifiers match in the first LEN
355 characters. This may help you prepare a program that will compile
356 with certain obsolete, brain-damaged compilers.
357
358`-Wlarger-than-LEN'
359 Warn whenever an object of larger than LEN bytes is defined.
360
361`-Wpointer-arith'
362 Warn about anything that depends on the "size of" a function type
363 or of `void'. GNU C assigns these types a size of 1, for
364 convenience in calculations with `void *' pointers and pointers to
365 functions.
366
367`-Wbad-function-cast'
368 Warn whenever a function call is cast to a non-matching type. For
369 example, warn if `int malloc()' is cast to `anything *'.
370
371`-Wcast-qual'
372 Warn whenever a pointer is cast so as to remove a type qualifier
373 from the target type. For example, warn if a `const char *' is
374 cast to an ordinary `char *'.
375
376`-Wcast-align'
377 Warn whenever a pointer is cast such that the required alignment
378 of the target is increased. For example, warn if a `char *' is
379 cast to an `int *' on machines where integers can only be accessed
380 at two- or four-byte boundaries.
381
382`-Wwrite-strings'
383 Give string constants the type `const char[LENGTH]' so that
384 copying the address of one into a non-`const' `char *' pointer
385 will get a warning. These warnings will help you find at compile
386 time code that can try to write into a string constant, but only
387 if you have been very careful about using `const' in declarations
388 and prototypes. Otherwise, it will just be a nuisance; this is
389 why we did not make `-Wall' request these warnings.
390
391`-Wconversion'
392 Warn if a prototype causes a type conversion that is different
393 from what would happen to the same argument in the absence of a
394 prototype. This includes conversions of fixed point to floating
395 and vice versa, and conversions changing the width or signedness
396 of a fixed point argument except when the same as the default
397 promotion.
398
399 Also, warn if a negative integer constant expression is implicitly
400 converted to an unsigned type. For example, warn about the
401 assignment `x = -1' if `x' is unsigned. But do not warn about
402 explicit casts like `(unsigned) -1'.
403
404`-Wsign-compare'
405 Warn when a comparison between signed and unsigned values could
406 produce an incorrect result when the signed value is converted to
407 unsigned. This warning is also enabled by `-W'; to get the other
408 warnings of `-W' without this warning, use `-W -Wno-sign-compare'.
409
410`-Waggregate-return'
411 Warn if any functions that return structures or unions are defined
412 or called. (In languages where you can return an array, this also
413 elicits a warning.)
414
415`-Wstrict-prototypes'
416 Warn if a function is declared or defined without specifying the
417 argument types. (An old-style function definition is permitted
418 without a warning if preceded by a declaration which specifies the
419 argument types.)
420
421`-Wmissing-prototypes'
422 Warn if a global function is defined without a previous prototype
423 declaration. This warning is issued even if the definition itself
424 provides a prototype. The aim is to detect global functions that
425 fail to be declared in header files.
426
427`-Wmissing-declarations'
428 Warn if a global function is defined without a previous
429 declaration. Do so even if the definition itself provides a
430 prototype. Use this option to detect global functions that are
431 not declared in header files.
432
433`-Wredundant-decls'
434 Warn if anything is declared more than once in the same scope,
435 even in cases where multiple declaration is valid and changes
436 nothing.
437
438`-Wnested-externs'
439 Warn if an `extern' declaration is encountered within an function.
440
441`-Winline'
442 Warn if a function can not be inlined, and either it was declared
443 as inline, or else the `-finline-functions' option was given.
444
445`-Woverloaded-virtual'
446 Warn when a derived class function declaration may be an error in
447 defining a virtual function (C++ only). In a derived class, the
448 definitions of virtual functions must match the type signature of a
449 virtual function declared in the base class. With this option, the
450 compiler warns when you define a function with the same name as a
451 virtual function, but with a type signature that does not match any
452 declarations from the base class.
453
454`-Wsynth (C++ only)'
455 Warn when g++'s synthesis behavior does not match that of cfront.
456 For instance:
457
458 struct A {
459 operator int ();
460 A& operator = (int);
461 };
462
463 main ()
464 {
465 A a,b;
466 a = b;
467 }
468
469 In this example, g++ will synthesize a default `A& operator =
470 (const A&);', while cfront will use the user-defined `operator ='.
471
472`-Werror'
473 Make all warnings into errors.
474
475\1f
476File: gcc.info, Node: Debugging Options, Next: Optimize Options, Prev: Warning Options, Up: Invoking GCC
477
478Options for Debugging Your Program or GNU CC
479============================================
480
481 GNU CC has various special options that are used for debugging
482either your program or GCC:
483
484`-g'
485 Produce debugging information in the operating system's native
486 format (stabs, COFF, XCOFF, or DWARF). GDB can work with this
487 debugging information.
488
489 On most systems that use stabs format, `-g' enables use of extra
490 debugging information that only GDB can use; this extra information
491 makes debugging work better in GDB but will probably make other
492 debuggers crash or refuse to read the program. If you want to
493 control for certain whether to generate the extra information, use
494 `-gstabs+', `-gstabs', `-gxcoff+', `-gxcoff', `-gdwarf-1+', or
495 `-gdwarf-1' (see below).
496
497 Unlike most other C compilers, GNU CC allows you to use `-g' with
498 `-O'. The shortcuts taken by optimized code may occasionally
499 produce surprising results: some variables you declared may not
500 exist at all; flow of control may briefly move where you did not
501 expect it; some statements may not be executed because they
502 compute constant results or their values were already at hand;
503 some statements may execute in different places because they were
504 moved out of loops.
505
506 Nevertheless it proves possible to debug optimized output. This
507 makes it reasonable to use the optimizer for programs that might
508 have bugs.
509
510 The following options are useful when GNU CC is generated with the
511 capability for more than one debugging format.
512
513`-ggdb'
514 Produce debugging information for use by GDB. This means to use
515 the most expressive format available (DWARF 2, stabs, or the
516 native format if neither of those are supported), including GDB
517 extensions if at all possible.
518
519`-gstabs'
520 Produce debugging information in stabs format (if that is
521 supported), without GDB extensions. This is the format used by
522 DBX on most BSD systems. On MIPS, Alpha and System V Release 4
523 systems this option produces stabs debugging output which is not
524 understood by DBX or SDB. On System V Release 4 systems this
525 option requires the GNU assembler.
526
527`-gstabs+'
528 Produce debugging information in stabs format (if that is
529 supported), using GNU extensions understood only by the GNU
530 debugger (GDB). The use of these extensions is likely to make
531 other debuggers crash or refuse to read the program.
532
533`-gcoff'
534 Produce debugging information in COFF format (if that is
535 supported). This is the format used by SDB on most System V
536 systems prior to System V Release 4.
537
538`-gxcoff'
539 Produce debugging information in XCOFF format (if that is
540 supported). This is the format used by the DBX debugger on IBM
541 RS/6000 systems.
542
543`-gxcoff+'
544 Produce debugging information in XCOFF format (if that is
545 supported), using GNU extensions understood only by the GNU
546 debugger (GDB). The use of these extensions is likely to make
547 other debuggers crash or refuse to read the program, and may cause
548 assemblers other than the GNU assembler (GAS) to fail with an
549 error.
550
551`-gdwarf'
552 Produce debugging information in DWARF version 1 format (if that is
553 supported). This is the format used by SDB on most System V
554 Release 4 systems.
555
556`-gdwarf+'
557 Produce debugging information in DWARF version 1 format (if that is
558 supported), using GNU extensions understood only by the GNU
559 debugger (GDB). The use of these extensions is likely to make
560 other debuggers crash or refuse to read the program.
561
562`-gdwarf-2'
563 Produce debugging information in DWARF version 2 format (if that is
564 supported). This is the format used by DBX on IRIX 6.
565
566`-gLEVEL'
567`-ggdbLEVEL'
568`-gstabsLEVEL'
569`-gcoffLEVEL'
570`-gxcoffLEVEL'
571`-gdwarfLEVEL'
572`-gdwarf-2LEVEL'
573 Request debugging information and also use LEVEL to specify how
574 much information. The default level is 2.
575
576 Level 1 produces minimal information, enough for making backtraces
577 in parts of the program that you don't plan to debug. This
578 includes descriptions of functions and external variables, but no
579 information about local variables and no line numbers.
580
581 Level 3 includes extra information, such as all the macro
582 definitions present in the program. Some debuggers support macro
583 expansion when you use `-g3'.
584
585`-p'
586 Generate extra code to write profile information suitable for the
587 analysis program `prof'. You must use this option when compiling
588 the source files you want data about, and you must also use it when
589 linking.
590
591`-pg'
592 Generate extra code to write profile information suitable for the
593 analysis program `gprof'. You must use this option when compiling
594 the source files you want data about, and you must also use it when
595 linking.
596
597`-a'
598 Generate extra code to write profile information for basic blocks,
599 which will record the number of times each basic block is
600 executed, the basic block start address, and the function name
601 containing the basic block. If `-g' is used, the line number and
602 filename of the start of the basic block will also be recorded.
603 If not overridden by the machine description, the default action is
604 to append to the text file `bb.out'.
605
606 This data could be analyzed by a program like `tcov'. Note,
607 however, that the format of the data is not what `tcov' expects.
608 Eventually GNU `gprof' should be extended to process this data.
609
610`-ax'
611 Generate extra code to profile basic blocks. Your executable will
612 produce output that is a superset of that produced when `-a' is
613 used. Additional output is the source and target address of the
614 basic blocks where a jump takes place, the number of times a jump
615 is executed, and (optionally) the complete sequence of basic
616 blocks being executed. The output is appended to file `bb.out'.
617
618 You can examine different profiling aspects without recompilation.
619 Your execuable will read a list of function names from file
620 `bb.in'. Profiling starts when a function on the list is entered
621 and stops when that invocation is exited. To exclude a function
622 from profiling, prefix its name with `-'. If a function name is
623 not unique, you can disambiguate it by writing it in the form
624 `/path/filename.d:functionname'. Your executable will write the
625 available paths and filenames in file `bb.out'.
626
627 Several function names have a special meaning:
628 `__bb_jumps__'
629 Write source, target and frequency of jumps to file `bb.out'.
630
631 `__bb_hidecall__'
632 Exclude function calls from frequency count.
633
634 `__bb_showret__'
635 Include function returns in frequency count.
636
637 `__bb_trace__'
638 Write the sequence of basic blocks executed to file
639 `bbtrace.gz'. The file will be compressed using the program
640 `gzip', which must exist in your `PATH'. On systems without
641 the `popen' function, the file will be named `bbtrace' and
642 will not be compressed. *Profiling for even a few seconds on
643 these systems will produce a very large file.* Note:
644 `__bb_hidecall__' and `__bb_showret__' will not affect the
645 sequence written to `bbtrace.gz'.
646
647 Here's a short example using different profiling parameters in
648 file `bb.in'. Assume function `foo' consists of basic blocks 1
649 and 2 and is called twice from block 3 of function `main'. After
650 the calls, block 3 transfers control to block 4 of `main'.
651
652 With `__bb_trace__' and `main' contained in file `bb.in', the
653 following sequence of blocks is written to file `bbtrace.gz': 0 3
654 1 2 1 2 4. The return from block 2 to block 3 is not shown,
655 because the return is to a point inside the block and not to the
656 top. The block address 0 always indicates, that control is
657 transferred to the trace from somewhere outside the observed
658 functions. With `-foo' added to `bb.in', the blocks of function
659 `foo' are removed from the trace, so only 0 3 4 remains.
660
661 With `__bb_jumps__' and `main' contained in file `bb.in', jump
662 frequencies will be written to file `bb.out'. The frequencies are
663 obtained by constructing a trace of blocks and incrementing a
664 counter for every neighbouring pair of blocks in the trace. The
665 trace 0 3 1 2 1 2 4 displays the following frequencies:
666
667 Jump from block 0x0 to block 0x3 executed 1 time(s)
668 Jump from block 0x3 to block 0x1 executed 1 time(s)
669 Jump from block 0x1 to block 0x2 executed 2 time(s)
670 Jump from block 0x2 to block 0x1 executed 1 time(s)
671 Jump from block 0x2 to block 0x4 executed 1 time(s)
672
673 With `__bb_hidecall__', control transfer due to call instructions
674 is removed from the trace, that is the trace is cut into three
675 parts: 0 3 4, 0 1 2 and 0 1 2. With `__bb_showret__', control
676 transfer due to return instructions is added to the trace. The
677 trace becomes: 0 3 1 2 3 1 2 3 4. Note, that this trace is not
678 the same, as the sequence written to `bbtrace.gz'. It is solely
679 used for counting jump frequencies.
680
681`-fprofile-arcs'
682 Instrument "arcs" during compilation. For each function of your
683 program, GNU CC creates a program flow graph, then finds a
684 spanning tree for the graph. Only arcs that are not on the
685 spanning tree have to be instrumented: the compiler adds code to
686 count the number of times that these arcs are executed. When an
687 arc is the only exit or only entrance to a block, the
688 instrumentation code can be added to the block; otherwise, a new
689 basic block must be created to hold the instrumentation code.
690
691 Since not every arc in the program must be instrumented, programs
692 compiled with this option run faster than programs compiled with
693 `-a', which adds instrumentation code to every basic block in the
694 program. The tradeoff: since `gcov' does not have execution
695 counts for all branches, it must start with the execution counts
696 for the instrumented branches, and then iterate over the program
697 flow graph until the entire graph has been solved. Hence, `gcov'
698 runs a little more slowly than a program which uses information
699 from `-a'.
700
701 `-fprofile-arcs' also makes it possible to estimate branch
702 probabilities, and to calculate basic block execution counts. In
703 general, basic block execution counts do not give enough
704 information to estimate all branch probabilities. When the
705 compiled program exits, it saves the arc execution counts to a
706 file called `SOURCENAME.da'. Use the compiler option
707 `-fbranch-probabilities' (*note Options that Control Optimization:
708 Optimize Options.) when recompiling, to optimize using estimated
709 branch probabilities.
710
711`-ftest-coverage'
712 Create data files for the `gcov' code-coverage utility (*note
713 `gcov': a GNU CC Test Coverage Program: Gcov.). The data file
714 names begin with the name of your source file:
715
716 `SOURCENAME.bb'
717 A mapping from basic blocks to line numbers, which `gcov'
718 uses to associate basic block execution counts with line
719 numbers.
720
721 `SOURCENAME.bbg'
722 A list of all arcs in the program flow graph. This allows
723 `gcov' to reconstruct the program flow graph, so that it can
724 compute all basic block and arc execution counts from the
725 information in the `SOURCENAME.da' file (this last file is
726 the output from `-fprofile-arcs').
727
728`-dLETTERS'
729 Says to make debugging dumps during compilation at times specified
730 by LETTERS. This is used for debugging the compiler. The file
731 names for most of the dumps are made by appending a word to the
732 source file name (e.g. `foo.c.rtl' or `foo.c.jump'). Here are the
733 possible letters for use in LETTERS, and their meanings:
734
735 `M'
736 Dump all macro definitions, at the end of preprocessing, and
737 write no output.
738
739 `N'
740 Dump all macro names, at the end of preprocessing.
741
742 `D'
743 Dump all macro definitions, at the end of preprocessing, in
744 addition to normal output.
745
746 `y'
747 Dump debugging information during parsing, to standard error.
748
749 `r'
750 Dump after RTL generation, to `FILE.rtl'.
751
752 `x'
753 Just generate RTL for a function instead of compiling it.
754 Usually used with `r'.
755
756 `j'
757 Dump after first jump optimization, to `FILE.jump'.
758
759 `s'
760 Dump after CSE (including the jump optimization that sometimes
761 follows CSE), to `FILE.cse'.
762
763 `L'
764 Dump after loop optimization, to `FILE.loop'.
765
766 `t'
767 Dump after the second CSE pass (including the jump
768 optimization that sometimes follows CSE), to `FILE.cse2'.
769
770 `f'
771 Dump after flow analysis, to `FILE.flow'.
772
773 `c'
774 Dump after instruction combination, to the file
775 `FILE.combine'.
776
777 `S'
778 Dump after the first instruction scheduling pass, to
779 `FILE.sched'.
780
781 `l'
782 Dump after local register allocation, to `FILE.lreg'.
783
784 `g'
785 Dump after global register allocation, to `FILE.greg'.
786
787 `R'
788 Dump after the second instruction scheduling pass, to
789 `FILE.sched2'.
790
791 `J'
792 Dump after last jump optimization, to `FILE.jump2'.
793
794 `d'
795 Dump after delayed branch scheduling, to `FILE.dbr'.
796
797 `k'
798 Dump after conversion from registers to stack, to
799 `FILE.stack'.
800
801 `a'
802 Produce all the dumps listed above.
803
804 `m'
805 Print statistics on memory usage, at the end of the run, to
806 standard error.
807
808 `p'
809 Annotate the assembler output with a comment indicating which
810 pattern and alternative was used.
811
812 `A'
813 Annotate the assembler output with miscellaneous debugging
814 information.
815
816`-fpretend-float'
817 When running a cross-compiler, pretend that the target machine
818 uses the same floating point format as the host machine. This
819 causes incorrect output of the actual floating constants, but the
820 actual instruction sequence will probably be the same as GNU CC
821 would make when running on the target machine.
822
823`-save-temps'
824 Store the usual "temporary" intermediate files permanently; place
825 them in the current directory and name them based on the source
826 file. Thus, compiling `foo.c' with `-c -save-temps' would produce
827 files `foo.i' and `foo.s', as well as `foo.o'.
828
829`-print-file-name=LIBRARY'
830 Print the full absolute name of the library file LIBRARY that
831 would be used when linking--and don't do anything else. With this
832 option, GNU CC does not compile or link anything; it just prints
833 the file name.
834
835`-print-prog-name=PROGRAM'
836 Like `-print-file-name', but searches for a program such as `cpp'.
837
838`-print-libgcc-file-name'
839 Same as `-print-file-name=libgcc.a'.
840
841 This is useful when you use `-nostdlib' or `-nodefaultlibs' but
842 you do want to link with `libgcc.a'. You can do
843
844 gcc -nostdlib FILES... `gcc -print-libgcc-file-name`
845
846`-print-search-dirs'
847 Print the name of the configured installation directory and a list
848 of program and library directories gcc will search--and don't do
849 anything else.
850
851 This is useful when gcc prints the error message `installation
852 problem, cannot exec cpp: No such file or directory'. To resolve
853 this you either need to put `cpp' and the other compiler
854 components where gcc expects to find them, or you can set the
855 environment variable `GCC_EXEC_PREFIX' to the directory where you
856 installed them. Don't forget the trailing '/'. *Note Environment
857 Variables::.
858
859\1f
860File: gcc.info, Node: Optimize Options, Next: Preprocessor Options, Prev: Debugging Options, Up: Invoking GCC
861
862Options That Control Optimization
863=================================
864
865 These options control various sorts of optimizations:
866
867`-O'
868`-O1'
869 Optimize. Optimizing compilation takes somewhat more time, and a
870 lot more memory for a large function.
871
872 Without `-O', the compiler's goal is to reduce the cost of
873 compilation and to make debugging produce the expected results.
874 Statements are independent: if you stop the program with a
875 breakpoint between statements, you can then assign a new value to
876 any variable or change the program counter to any other statement
877 in the function and get exactly the results you would expect from
878 the source code.
879
880 Without `-O', the compiler only allocates variables declared
881 `register' in registers. The resulting compiled code is a little
882 worse than produced by PCC without `-O'.
883
884 With `-O', the compiler tries to reduce code size and execution
885 time.
886
887 When you specify `-O', the compiler turns on `-fthread-jumps' and
888 `-fdefer-pop' on all machines. The compiler turns on
889 `-fdelayed-branch' on machines that have delay slots, and
890 `-fomit-frame-pointer' on machines that can support debugging even
891 without a frame pointer. On some machines the compiler also turns
892 on other flags.
893
894`-O2'
895 Optimize even more. GNU CC performs nearly all supported
896 optimizations that do not involve a space-speed tradeoff. The
897 compiler does not perform loop unrolling or function inlining when
898 you specify `-O2'. As compared to `-O', this option increases
899 both compilation time and the performance of the generated code.
900
901 `-O2' turns on all optional optimizations except for loop unrolling
902 and function inlining. It also turns on the `-fforce-mem' option
903 on all machines and frame pointer elimination on machines where
904 doing so does not interfere with debugging.
905
906`-O3'
907 Optimize yet more. `-O3' turns on all optimizations specified by
908 `-O2' and also turns on the `inline-functions' option.
909
910`-O0'
911 Do not optimize.
912
913 If you use multiple `-O' options, with or without level numbers,
914 the last such option is the one that is effective.
915
916 Options of the form `-fFLAG' specify machine-independent flags.
917Most flags have both positive and negative forms; the negative form of
918`-ffoo' would be `-fno-foo'. In the table below, only one of the forms
919is listed--the one which is not the default. You can figure out the
920other form by either removing `no-' or adding it.
921
922`-ffloat-store'
923 Do not store floating point variables in registers, and inhibit
924 other options that might change whether a floating point value is
925 taken from a register or memory.
926
927 This option prevents undesirable excess precision on machines such
928 as the 68000 where the floating registers (of the 68881) keep more
929 precision than a `double' is supposed to have. Similarly for the
930 x86 architecture. For most programs, the excess precision does
931 only good, but a few programs rely on the precise definition of
932 IEEE floating point. Use `-ffloat-store' for such programs.
933
934`-fno-default-inline'
935 Do not make member functions inline by default merely because they
936 are defined inside the class scope (C++ only). Otherwise, when
937 you specify `-O', member functions defined inside class scope are
938 compiled inline by default; i.e., you don't need to add `inline'
939 in front of the member function name.
940
941`-fno-defer-pop'
942 Always pop the arguments to each function call as soon as that
943 function returns. For machines which must pop arguments after a
944 function call, the compiler normally lets arguments accumulate on
945 the stack for several function calls and pops them all at once.
946
947`-fforce-mem'
948 Force memory operands to be copied into registers before doing
949 arithmetic on them. This produces better code by making all memory
950 references potential common subexpressions. When they are not
951 common subexpressions, instruction combination should eliminate
952 the separate register-load. The `-O2' option turns on this option.
953
954`-fforce-addr'
955 Force memory address constants to be copied into registers before
956 doing arithmetic on them. This may produce better code just as
957 `-fforce-mem' may.
958
959`-fomit-frame-pointer'
960 Don't keep the frame pointer in a register for functions that
961 don't need one. This avoids the instructions to save, set up and
962 restore frame pointers; it also makes an extra register available
963 in many functions. *It also makes debugging impossible on some
964 machines.*
965
966 On some machines, such as the Vax, this flag has no effect, because
967 the standard calling sequence automatically handles the frame
968 pointer and nothing is saved by pretending it doesn't exist. The
969 machine-description macro `FRAME_POINTER_REQUIRED' controls
970 whether a target machine supports this flag. *Note Registers::.
971
972`-fno-inline'
973 Don't pay attention to the `inline' keyword. Normally this option
974 is used to keep the compiler from expanding any functions inline.
975 Note that if you are not optimizing, no functions can be expanded
976 inline.
977
978`-finline-functions'
979 Integrate all simple functions into their callers. The compiler
980 heuristically decides which functions are simple enough to be worth
981 integrating in this way.
982
983 If all calls to a given function are integrated, and the function
984 is declared `static', then the function is normally not output as
985 assembler code in its own right.
986
987`-fkeep-inline-functions'
988 Even if all calls to a given function are integrated, and the
989 function is declared `static', nevertheless output a separate
990 run-time callable version of the function. This switch does not
991 affect `extern inline' functions.
992
993`-fkeep-static-consts'
994 Emit variables declared `static const' when optimization isn't
995 turned on, even if the variables aren't referenced.
996
997 GNU CC enables this option by default. If you want to force the
998 compiler to check if the variable was referenced, regardless of
999 whether or not optimization is turned on, use the
1000 `-fno-keep-static-consts' option.
1001
1002`-fno-function-cse'
1003 Do not put function addresses in registers; make each instruction
1004 that calls a constant function contain the function's address
1005 explicitly.
1006
1007 This option results in less efficient code, but some strange hacks
1008 that alter the assembler output may be confused by the
1009 optimizations performed when this option is not used.
1010
1011`-ffast-math'
1012 This option allows GCC to violate some ANSI or IEEE rules and/or
1013 specifications in the interest of optimizing code for speed. For
1014 example, it allows the compiler to assume arguments to the `sqrt'
1015 function are non-negative numbers and that no floating-point values
1016 are NaNs.
1017
1018 This option should never be turned on by any `-O' option since it
1019 can result in incorrect output for programs which depend on an
1020 exact implementation of IEEE or ANSI rules/specifications for math
1021 functions.
1022
1023 The following options control specific optimizations. The `-O2'
1024option turns on all of these optimizations except `-funroll-loops' and
1025`-funroll-all-loops'. On most machines, the `-O' option turns on the
1026`-fthread-jumps' and `-fdelayed-branch' options, but specific machines
1027may handle it differently.
1028
1029 You can use the following flags in the rare cases when "fine-tuning"
1030of optimizations to be performed is desired.
1031
1032`-fstrength-reduce'
1033 Perform the optimizations of loop strength reduction and
1034 elimination of iteration variables.
1035
1036`-fthread-jumps'
1037 Perform optimizations where we check to see if a jump branches to a
1038 location where another comparison subsumed by the first is found.
1039 If so, the first branch is redirected to either the destination of
1040 the second branch or a point immediately following it, depending
1041 on whether the condition is known to be true or false.
1042
1043`-fcse-follow-jumps'
1044 In common subexpression elimination, scan through jump instructions
1045 when the target of the jump is not reached by any other path. For
1046 example, when CSE encounters an `if' statement with an `else'
1047 clause, CSE will follow the jump when the condition tested is
1048 false.
1049
1050`-fcse-skip-blocks'
1051 This is similar to `-fcse-follow-jumps', but causes CSE to follow
1052 jumps which conditionally skip over blocks. When CSE encounters a
1053 simple `if' statement with no else clause, `-fcse-skip-blocks'
1054 causes CSE to follow the jump around the body of the `if'.
1055
1056`-frerun-cse-after-loop'
1057 Re-run common subexpression elimination after loop optimizations
1058 has been performed.
1059
1060`-fexpensive-optimizations'
1061 Perform a number of minor optimizations that are relatively
1062 expensive.
1063
1064`-fdelayed-branch'
1065 If supported for the target machine, attempt to reorder
1066 instructions to exploit instruction slots available after delayed
1067 branch instructions.
1068
1069`-fschedule-insns'
1070 If supported for the target machine, attempt to reorder
1071 instructions to eliminate execution stalls due to required data
1072 being unavailable. This helps machines that have slow floating
1073 point or memory load instructions by allowing other instructions
1074 to be issued until the result of the load or floating point
1075 instruction is required.
1076
1077`-fschedule-insns2'
1078 Similar to `-fschedule-insns', but requests an additional pass of
1079 instruction scheduling after register allocation has been done.
1080 This is especially useful on machines with a relatively small
1081 number of registers and where memory load instructions take more
1082 than one cycle.
1083
1084`-ffunction-sections'
1085 Place each function into its own section in the output file if the
1086 target supports arbitrary sections. The function's name determines
1087 the section's name in the output file.
1088
1089 Use this option on systems where the linker can perform
1090 optimizations to improve locality of reference in the instruction
1091 space. HPPA processors running HP-UX and Sparc processors running
1092 Solaris 2 have linkers with such optimizations. Other systems
1093 using the ELF object format as well as AIX may have these
1094 optimizations in the future.
1095
1096 Only use this option when there are significant benefits from doing
1097 so. When you specify this option, the assembler and linker will
1098 create larger object and executable files and will also be slower.
1099 You will not be able to use `gprof' on all systems if you specify
1100 this option and you may have problems with debugging if you
1101 specify both this option and `-g'.
1102
1103`-fcaller-saves'
1104 Enable values to be allocated in registers that will be clobbered
1105 by function calls, by emitting extra instructions to save and
1106 restore the registers around such calls. Such allocation is done
1107 only when it seems to result in better code than would otherwise
1108 be produced.
1109
1110 This option is enabled by default on certain machines, usually
1111 those which have no call-preserved registers to use instead.
1112
1113`-funroll-loops'
1114 Perform the optimization of loop unrolling. This is only done for
1115 loops whose number of iterations can be determined at compile time
1116 or run time. `-funroll-loop' implies both `-fstrength-reduce' and
1117 `-frerun-cse-after-loop'.
1118
1119`-funroll-all-loops'
1120 Perform the optimization of loop unrolling. This is done for all
1121 loops and usually makes programs run more slowly.
1122 `-funroll-all-loops' implies `-fstrength-reduce' as well as
1123 `-frerun-cse-after-loop'.
1124
1125`-fno-peephole'
1126 Disable any machine-specific peephole optimizations.
1127
1128`-fbranch-probabilities'
1129 After running a program compiled with `-fprofile-arcs' (*note
1130 Options for Debugging Your Program or `gcc': Debugging Options.),
1131 you can compile it a second time using `-fbranch-probabilities',
1132 to improve optimizations based on guessing the path a branch might
1133 take.
1134
1135 With `-fbranch-probabilities', GNU CC puts a `REG_EXEC_COUNT' note
1136 on the first instruction of each basic block, and a `REG_BR_PROB'
1137 note on each `JUMP_INSN' and `CALL_INSN'. These can be used to
1138 improve optimization. Currently, they are only used in one place:
1139 in `reorg.c', instead of guessing which path a branch is mostly to
1140 take, the `REG_BR_PROB' values are used to exactly determine which
1141 path is taken more often.
1142