home *** CD-ROM | disk | FTP | other *** search
/ Monster Disc 2: The Best of 1992 / MONSTER2.ISO / prog / djgpp / djgcc222.a04 / DOCS / GCC.TEX next >
Encoding:
Text File  |  1992-07-06  |  79.8 KB  |  2,041 lines

  1. ages complain of mismatched
  2. psect attributes.  You can ignore them.  @xref{VMS Install}.
  3.  
  4. @cindex Alliant
  5. @item
  6. On the Alliant, the system's own convention for returning structures
  7. and unions is unusual, and is not compatible with GNU CC no matter
  8. what options are used.
  9.  
  10. @cindex RT PC
  11. @cindex IBM RT PC
  12. @item
  13. On the IBM RT PC, the MetaWare HighC compiler (hc) uses yet another
  14. convention for structure and union returning.  Use
  15. @samp{-mhc-struct-return} to tell GNU CC to use a convention compatible
  16. with it.
  17.  
  18. @cindex Vax calling convention
  19. @cindex Ultrix calling convention
  20. @item
  21. On Ultrix, the Fortran compiler expects registers 2 through 5 to be saved
  22. by function calls.  However, the C compiler uses conventions compatible
  23. with BSD Unix: registers 2 through 5 may be clobbered by function calls.
  24.  
  25. GNU CC uses the same convention as the Ultrix C compiler.  You can use
  26. these options to produce code compatible with the Fortran compiler:
  27.  
  28. @smallexample
  29. -fcall-saved-r2 -fcall-saved-r3 -fcall-saved-r4 -fcall-saved-r5
  30. @end smallexample
  31. @end itemize
  32.  
  33. @node Incompatibilities
  34. @section Incompatibilities of GNU CC
  35. @cindex incompatibilities of GNU CC
  36.  
  37. There are several noteworthy incompatibilities between GNU C and most
  38. existing (non-ANSI) versions of C.  The @samp{-traditional} option
  39. eliminates many of these incompatibilities, @emph{but not all}, by
  40. telling GNU C to behave like the other C compilers.
  41.  
  42. @itemize @bullet
  43. @cindex string constants
  44. @cindex read-only strings
  45. @cindex shared strings
  46. @item
  47. GNU CC normally makes string constants read-only.  If several
  48. identical-looking string constants are used, GNU CC stores only one
  49. copy of the string.
  50.  
  51. @cindex @code{mktemp}, and constant strings
  52. One consequence is that you cannot call @code{mktemp} with a string
  53. constant argument.  The function @code{mktemp} always alters the
  54. string its argument points to.
  55.  
  56. @cindex @code{sscanf}, and constant strings
  57. @cindex @code{fscanf}, and constant strings
  58. @cindex @code{scanf}, and constant strings
  59. Another consequence is that @code{sscanf} does not work on some systems
  60. when passed a string constant as its format control string or input.
  61. This is because @code{sscanf} incorrectly tries to write into the string
  62. constant.  Likewise @code{fscanf} and @code{scanf}.
  63.  
  64. The best solution to these problems is to change the program to use
  65. @code{char}-array variables with initialization strings for these
  66. purposes instead of string constants.  But if this is not possible,
  67. you can use the @samp{-fwritable-strings} flag, which directs GNU CC
  68. to handle string constants the same way most C compilers do.
  69. @samp{-traditional} also has this effect, among others.
  70.  
  71. @item
  72. @code{-2147483648} is positive.
  73.  
  74. This is because 2147483648 cannot fit in the type @code{int}, so
  75. (following the ANSI C rules) its data type is @code{unsigned long int}.
  76. Negating this value yields 2147483648 again.
  77.  
  78. @item
  79. GNU CC does not substitute macro arguments when they appear inside of
  80. string constants.  For example, the following macro in GNU CC
  81.  
  82. @example
  83. #define foo(a) "a"
  84. @end example
  85.  
  86. @noindent
  87. will produce output @code{"a"} regardless of what the argument @var{a} is.
  88.  
  89. The @samp{-traditional} option directs GNU CC to handle such cases
  90. (among others) in the old-fashioned (non-ANSI) fashion.
  91.  
  92. @cindex @code{setjmp} incompatibilities
  93. @cindex @code{longjmp} incompatibilities
  94. @item
  95. When you use @code{setjmp} and @code{longjmp}, the only automatic
  96. variables guaranteed to remain valid are those declared
  97. @code{volatile}.  This is a consequence of automatic register
  98. allocation.  Consider this function:
  99.  
  100. @example
  101. jmp_buf j;
  102.  
  103. foo ()
  104. @{
  105.   int a, b;
  106.  
  107.   a = fun1 ();
  108.   if (setjmp (j))
  109.     return a;
  110.  
  111.   a = fun2 ();
  112.   /* @r{@code{longjmp (j)} may occur in @code{fun3}.} */
  113.   return a + fun3 ();
  114. @}
  115. @end example
  116.  
  117. Here @code{a} may or may not be restored to its first value when the
  118. @code{longjmp} occurs.  If @code{a} is allocated in a register, then
  119. its first value is restored; otherwise, it keeps the last value stored
  120. in it.
  121.  
  122. If you use the @samp{-W} option with the @samp{-O} option, you will
  123. get a warning when GNU CC thinks such a problem might be possible.
  124.  
  125. The @samp{-traditional} option directs GNU C to put variables in
  126. the stack by default, rather than in registers, in functions that
  127. call @code{setjmp}.  This results in the behavior found in
  128. traditional C compilers.
  129.  
  130. @item
  131. Programs that use preprocessor directives in the middle of macro
  132. arguments do not work with GNU CC.  For example, a program like this
  133. will not work:
  134.  
  135. @example
  136. foobar (
  137. #define luser
  138.         hack)
  139. @end example
  140.  
  141. ANSI C does not permit such a construct.  It would make sense to support
  142. it when @samp{-traditional} is used, but it is too much work to
  143. implement.
  144.  
  145. @cindex external declaration scope
  146. @cindex scope of external declarations
  147. @cindex declaration scope
  148. @item
  149. Declarations of external variables and functions within a block apply
  150. only to the block containing the declaration.  In other words, they
  151. have the same scope as any other declaration in the same place.
  152.  
  153. In some other C compilers, a @code{extern} declaration affects all the
  154. rest of the file even if it happens within a block.
  155.  
  156. The @samp{-traditional} option directs GNU C to treat all @code{extern}
  157. declarations as global, like traditional compilers.
  158.  
  159. @item
  160. In traditional C, you can combine @code{long}, etc., with a typedef name,
  161. as shown here:
  162.  
  163. @example
  164. typedef int foo;
  165. typedef long foo bar;
  166. @end example
  167.  
  168. In ANSI C, this is not allowed: @code{long} and other type modifiers
  169. require an explicit @code{int}.  Because this criterion is expressed
  170. by Bison grammar rules rather than C code, the @samp{-traditional}
  171. flag cannot alter it.
  172.  
  173. @cindex typedef names as function parameters
  174. @item
  175. PCC allows typedef names to be used as function parameters.  The
  176. difficulty described immediately above applies here too.
  177.  
  178. @cindex whitespace
  179. @item
  180. PCC allows whitespace in the middle of compound assignment operators
  181. such as @samp{+=}.  GNU CC, following the ANSI standard, does not
  182. allow this.  The difficulty described immediately above applies here
  183. too.
  184.  
  185. @cindex apostrophes
  186. @cindex '
  187. @item
  188. GNU CC will flag unterminated character constants inside of preprocessor
  189. conditionals that fail.  Some programs have English comments enclosed in
  190. conditionals that are guaranteed to fail; if these comments contain
  191. apostrophes, GNU CC will probably report an error.  For example,
  192. this code would produce an error:
  193.  
  194. @example
  195. #if 0
  196. You can't expect this to work.
  197. #endif
  198. @end example
  199.  
  200. The best solution to such a problem is to put the text into an actual
  201. C comment delimited by @samp{/*@dots{}*/}.  However,
  202. @samp{-traditional} suppresses these error messages.
  203.  
  204. @cindex @code{float} as function value type
  205. @item
  206. When compiling functions that return @code{float}, PCC converts it to
  207. a double.  GNU CC actually returns a @code{float}.  If you are concerned
  208. with PCC compatibility, you should declare your functions to return
  209. @code{double}; you might as well say what you mean.
  210.  
  211. @cindex structures
  212. @cindex unions
  213. @item
  214. When compiling functions that return structures or unions, GNU CC
  215. output code normally uses a method different from that used on most
  216. versions of Unix.  As a result, code compiled with GNU CC cannot call
  217. a structure-returning function compiled with PCC, and vice versa.
  218.  
  219. The method used by GNU CC is as follows: a structure or union which is
  220. 1, 2, 4 or 8 bytes long is returned like a scalar.  A structure or union
  221. with any other size is stored into an address supplied by the caller
  222. (usually in a special, fixed register, but on some machines it is passed
  223. on the stack).  The machine-description macros @code{STRUCT_VALUE} and
  224. @code{STRUCT_INCOMING_VALUE} tell GNU CC where to pass this address.
  225.  
  226. By contrast, PCC on most target machines returns structures and unions
  227. of any size by copying the data into an area of static storage, and then
  228. returning the address of that storage as if it were a pointer value.
  229. The caller must copy the data from that memory area to the place where
  230. the value is wanted.  GNU CC does not use this method because it is
  231. slower and nonreentrant.
  232.  
  233. On some newer machines, PCC uses a reentrant convention for all
  234. structure and union returning.  GNU CC on most of these machines uses a
  235. compatible convention when returning structures and unions in memory,
  236. but still returns small structures and unions in registers.
  237.  
  238. You can tell GNU CC to use a compatible convention for all structure and
  239. union returning with the option @samp{-fpcc-struct-return}.
  240. @end itemize
  241.  
  242. @node Disappointments
  243. @section Disappointments and Misunderstandings
  244.  
  245. These problems are perhaps regrettable, but we don't know any practical
  246. way around them.
  247.  
  248. @itemize @bullet
  249. @item
  250. Certain local variables aren't recognized by debuggers when you compile
  251. with optimization.
  252.  
  253. This occurs because sometimes GNU CC optimizes the variable out of
  254. existence.  There is no way to tell the debugger how to compute the
  255. value such a variable ``would have had'', and it is not clear that would
  256. be desirable anyway.  So GNU CC simply does not mention the eliminated
  257. variable when it writes debugging information.
  258.  
  259. You have to expect a certain amount of disagreement between the
  260. executable and your source code, when you use optimization.
  261.  
  262. @cindex conflicting types
  263. @cindex scope of declaration
  264. @item
  265. Users often think it is a bug when GNU CC reports an error for code
  266. like this:
  267.  
  268. @example
  269. int foo (struct mumble *);
  270.  
  271. struct mumble @{ @dots{} @};
  272.  
  273. int foo (struct mumble *x)
  274. @{ @dots{} @}
  275. @end example
  276.  
  277. This code really is erroneous, because the scope of @code{struct
  278. mumble} the prototype is limited to the argument list containing it.
  279. It does not refer to the @code{struct mumble} defined with file scope
  280. immediately below---they are two unrelated types with similar names in
  281. different scopes.
  282.  
  283. But in the definition of @code{foo}, the file-scope type is used
  284. because that is available to be inherited.  Thus, the definition and
  285. the prototype do not match, and you get an error.
  286.  
  287. This behavior may seem silly, but it's what the ANSI standard specifies.
  288. It is easy enough for you to make your code work by moving the
  289. definition of @code{struct mumble} above the prototype.  It's not worth
  290. being incompatible with ANSI C just to avoid an error for the example
  291. shown above.
  292. @end itemize
  293.  
  294. @node Non-bugs,, Disappointments, Trouble
  295. @section Certain Changes We Don't Want to Make
  296.  
  297. This section lists changes that people frequently request, but which
  298. we do not make because we think GNU CC is better without them.
  299.  
  300. @itemize @bullet
  301. @item 
  302. Checking the number and type of arguments to a function which has an
  303. old-fashioned definition and no prototype.
  304.  
  305. Such a feature would work only occasionally---only for calls that appear
  306. in the same file as the called function, following the definition.  The
  307. only way to check all calls reliably is to add a prototype for the
  308. function.  But adding a prototype eliminates the motivation for this
  309. feature.  So the feature is not worthwhile.
  310.  
  311. @item 
  312. Warning about using an expression whose type is signed as a shift count.
  313.  
  314. Shift count operands are probably signed more often than unsigned.
  315. Warning about this would cause far more annoyance than good.
  316.  
  317. @item
  318. Warning about assigning a signed value to an unsigned variable.
  319.  
  320. Such assignments must be very common; warning about them would cause
  321. more annoyance than good.
  322.  
  323. @item
  324. Warning when a non-void function value is ignored.
  325.  
  326. Coming as I do from a Lisp background, I balk at the idea that there is
  327. something dangerous about discarding a value.  There are functions that
  328. return values which some callers may find useful; it makes no sense to
  329. clutter the program with a cast to @code{void} whenever the value isn't
  330. useful.
  331.  
  332. @item
  333. Assuming (for optimization) that the address of an external symbol is
  334. never zero.
  335.  
  336. This assumption is false on certain systems when @samp{#pragma weak} is
  337. used.
  338.  
  339. @item
  340. Making @samp{-fshort-enums} the default.
  341.  
  342. This would cause storage layout to be incompatible with most other C
  343. compilers.  And it doesn't seem very important, given that you can get
  344. the same result in other ways.  The case where it matters most is when
  345. the enumeration-valued object is inside a structure, and in that case
  346. you can specify a field width explicitly.
  347.  
  348. @item
  349. Making bitfields unsigned by default on particular machines where ``the
  350. ABI standard'' says to do so.
  351.  
  352. The ANSI C standard leaves it up to the implementation whether a bitfield
  353. declared plain @code{int} is signed or not.  This in effect creates two
  354. alternative dialects of C.
  355.  
  356. The GNU C compiler supports both dialects; you can specify the dialect
  357. you want with the option @samp{-fsigned-bitfields} or
  358. @samp{-funsigned-bitfields}.  However, this leaves open the question
  359. of which dialect to use by default.
  360.  
  361. Currently, the preferred dialect makes plain bitfields signed, because
  362. this is simplest.  Since @code{int} is the same as @code{signed int} in
  363. every other context, it is cleanest for them to be the same in bitfields
  364. as well.
  365.  
  366. Some computer manufacturers have published Application Binary Interface
  367. standards which specify that plain bitfields should be unsigned.  It is
  368. a mistake, however, to say anything about this issue in an ABI.  This is
  369. because the handling of plain bitfields distinguishes two dialects of C.
  370. Both dialects are meaningful on every type of machine.  Whether a
  371. particular object file was compiled using signed bitfields or unsigned
  372. is of no concern to other object files, even if they access the same
  373. bitfields in the same data structures.
  374.  
  375. A given program is written in one or the other of these two dialects.
  376. The program stands a chance to work on most any machine if it is
  377. compiled with the proper dialect.  It is unlikely to work at all if
  378. compiled with the wrong dialect.
  379.  
  380. Many users appreciate the GNU C compiler because it provides an
  381. environment that is uniform across machines.  These users would be
  382. inconvenienced if the compiler treated plain bitfields differently on
  383. certain machines.
  384.  
  385. Occasionally users write programs intended only for a particular machine
  386. type.  On these occasions, the users would benefit if the GNU C compiler
  387. were to support by default the same dialect as the other compilers on
  388. that machine.  But such applications are rare.  And users writing a
  389. program to run on more than one type of machine cannot possibly benefit
  390. from this kind of compatibility.
  391.  
  392. This is why GNU CC does and will treat plain bitfields in the same
  393. fashion on all types of machines (by default).
  394.  
  395. There are some arguments for making bitfields unsigned by default on all
  396. machines.  If, for example, this becomes a universal de facto standard,
  397. it would make sense for GNU CC to go along with it.  This is something
  398. to be considered in the future.
  399.  
  400. (Of course, users strongly concerned about portability should indicate
  401. explicitly in each bitfield whether it is signed or not.  In this way,
  402. they write programs which have the same meaning in both C dialects.)
  403.  
  404. @item
  405. Undefining @code{__STDC__} when @samp{-ansi} is not used.
  406.  
  407. Currently, GNU CC defines @code{__STDC__} as long as you don't use
  408. @samp{-traditional}.  This provides good results in practice.
  409.  
  410. Programmers normally use conditionals on @code{__STDC__} to ask whether
  411. it is safe to use certain features of ANSI C, such as function
  412. prototypes or ANSI token concatenation.  Since plain @samp{gcc} supports
  413. all the features of ANSI C, the correct answer to these questions is
  414. ``yes''.
  415.  
  416. Some users try to use @code{__STDC__} to check for the availability of
  417. certain library facilities.  This is actually incorrect usage in an ANSI
  418. C program, because the ANSI C standard says that a conforming
  419. freestanding implementation should define @code{__STDC__} even though it
  420. does not have the library facilities.  @samp{gcc -ansi -pedantic} is a
  421. conforming freestanding implementation, and it is therefore required to
  422. define @code{__STDC__}, even though it does not come with an ANSI C
  423. library.
  424.  
  425. Sometimes people say that defining @code{__STDC__} in a compiler that
  426. does not completely conform to the ANSI C standard somehow violates the
  427. standard.  This is illogical.  The standard is a standard for compilers
  428. that claim to support ANSI C, such as @samp{gcc -ansi}---not for other
  429. compilers such as plain @samp{gcc}.  Whatever the ANSI C standard says
  430. is relevant to the design of plain @samp{gcc} without @samp{-ansi} only
  431. for pragmatic reasons, not as a requirement.
  432.  
  433. @item
  434. Undefining @code{__STDC__} in C++.
  435.  
  436. Programs written to compile with C++-to-C translators get the
  437. value of @code{__STDC__} that goes with the C compiler that is
  438. subsequently used.  These programs must test @code{__STDC__}
  439. to determine what kind of C preprocessor that compiler uses:
  440. whether they should concatenate tokens in the ANSI C fashion
  441. or in the traditional fashion.
  442.  
  443. These programs work properly with GNU C++ if @code{__STDC__} is defined.
  444. They would not work otherwise.
  445.  
  446. In addition, many header files are written to provide prototypes in ANSI
  447. C but not in traditional C.  Many of these header files can work without
  448. change in C++ provided @code{__STDC__} is defined.  If @code{__STDC__}
  449. is not defined, they will all fail, and will all need to be changed to
  450. test explicitly for C++ as well.
  451.  
  452. @item
  453. Deleting ``empty'' loops.
  454.  
  455. GNU CC does not delete ``empty'' loops because the most likely reason
  456. you would put one in a program is to have a delay.  Deleting them will
  457. not make real programs run any faster, so it would be pointless.
  458.  
  459. It would be different if optimization of a nonempty loop could produce
  460. an empty one.  But this generally can't happen.
  461. @end itemize
  462.  
  463. @node Bugs
  464. @chapter Reporting Bugs
  465. @cindex bugs
  466. @cindex reporting bugs
  467.  
  468. Your bug reports play an essential role in making GNU CC reliable.
  469.  
  470. When you encounter a problem, the first thing to do is to see if it is
  471. already known.  @xref{Trouble}.  If it isn't known, then you should
  472. report the problem.
  473.  
  474. Reporting a bug may help you by bringing a solution to your problem, or
  475. it may not.  (If it does not, look in the service directory; see
  476. @ref{Service}.)  In any case, the principal function of a bug report is
  477. to help the entire community by making the next version of GNU CC work
  478. better.  Bug reports are your contribution to the maintenance of GNU CC.
  479.  
  480. In order for a bug report to serve its purpose, you must include the
  481. information that makes for fixing the bug.
  482.  
  483. @menu
  484. * Criteria:  Bug Criteria.   Have you really found a bug?
  485. * Where: Bug Lists.         Where to send your bug report.
  486. * Reporting: Bug Reporting.  How to report a bug effectively.
  487. * Patches: Sending Patches.  How to send a patch for GNU CC.
  488. * Known: Trouble.            Known problems.
  489. * Help: Service.             Where to ask for help.
  490. @end menu
  491.  
  492. @node Bug Criteria
  493. @section Have You Found a Bug?
  494. @cindex bug criteria
  495.  
  496. If you are not sure whether you have found a bug, here are some guidelines:
  497.  
  498. @itemize @bullet
  499. @cindex fatal signal
  500. @cindex core dump
  501. @item
  502. If the compiler gets a fatal signal, for any input whatever, that is a
  503. compiler bug.  Reliable compilers never crash.
  504.  
  505. @cindex invalid assembly code
  506. @cindex assembly code, invalid
  507. @item
  508. If the compiler produces invalid assembly code, for any input whatever
  509. (except an @code{asm} statement), that is a compiler bug, unless the
  510. compiler reports errors (not just warnings) which would ordinarily
  511. prevent the assembler from being run.
  512.  
  513. @cindex undefined behavior
  514. @cindex undefined function value
  515. @cindex increment operators
  516. @item
  517. If the compiler produces valid assembly code that does not correctly
  518. execute the input source code, that is a compiler bug.
  519.  
  520. However, you must double-check to make sure, because you may have run
  521. into an incompatibility between GNU C and traditional C
  522. (@pxref{Incompatibilities}).  These incompatibilities might be considered
  523. bugs, but they are inescapable consequences of valuable features.
  524.  
  525. Or you may have a program whose behavior is undefined, which happened
  526. by chance to give the desired results with another C or C++ compiler.
  527.  
  528. For example, in many nonoptimizing compilers, you can write @samp{x;}
  529. at the end of a function instead of @samp{return x;}, with the same
  530. results.  But the value of the function is undefined if @code{return}
  531. is omitted; it is not a bug when GNU CC produces different results.
  532.  
  533. Problems often result from expressions with two increment operators,
  534. as in @code{f (*p++, *p++)}.  Your previous compiler might have
  535. interpreted that expression the way you intended; GNU CC might
  536. interpret it another way.  Neither compiler is wrong.  The bug is
  537. in your code.
  538.  
  539. After you have localized the error to a single source line, it should
  540. be easy to check for these things.  If your program is correct and
  541. well defined, you have found a compiler bug.
  542.  
  543. @item
  544. If the compiler produces an error message for valid input, that is a
  545. compiler bug.
  546.  
  547. @cindex invalid input
  548. @item
  549. If the compiler does not produce an error message for invalid input,
  550. that is a compiler bug.  However, you should note that your idea of
  551. ``invalid input'' might be my idea of ``an extension'' or ``support
  552. for traditional practice''.
  553.  
  554. @item
  555. If you are an experienced user of C or C++ compilers, your suggestions
  556. for improvement of GNU CC or GNU C++ are welcome in any case.
  557. @end itemize
  558.  
  559. @node Bug Lists
  560. @section Where to Report Bugs
  561. @cindex bug report mailing lists
  562.  
  563. Send bug reports for GNU C to one of these addresses:
  564.  
  565. @example
  566. bug-gcc@@prep.ai.mit.edu
  567. @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-gcc
  568. @end example
  569.  
  570. Send bug reports for GNU C++ to one of these addresses:
  571.  
  572. @example
  573. bug-g++@@prep.ai.mit.edu
  574. @{ucbvax|mit-eddie|uunet@}!prep.ai.mit.edu!bug-g++
  575. @end example
  576.  
  577. @strong{Do not send bug reports to @samp{help-gcc}, or to the newsgroup
  578. @samp{gnu.gcc.help}.}  Most users of GNU CC do not want to receive bug
  579. reports.  Those that do, have asked to be on @samp{bug-gcc} and/or
  580. @samp{bug-g++}.
  581.  
  582. The mailing lists @samp{bug-gcc} and @samp{bug-g++} both have newsgroups
  583. which serve as repeaters: @samp{gnu.gcc.bug} and @samp{gnu.g++.bug}.
  584. Each mailing list and its newsgroup carry exactly the same messages.
  585.  
  586. Often people think of posting bug reports to the newsgroup instead of
  587. mailing them.  This appears to work, but it has one problem which can be
  588. crucial: a newsgroup posting does not contain a mail path back to the
  589. sender.  Thus, if maintaners need more information, they may be unable
  590. to reach you.  For this reason, you should always send bug reports by
  591. mail to the proper mailing list.
  592.  
  593. As a last resort, send bug reports on paper to:
  594.  
  595. @example
  596. GNU Compiler Bugs
  597. Free Software Foundation
  598. 675 Mass Ave
  599. Cambridge, MA 02139
  600. @end example
  601.  
  602. @node Bug Reporting
  603. @section How to Report Bugs
  604. @cindex compiler bugs, reporting
  605.  
  606. The fundamental principle of reporting bugs usefully is this:
  607. @strong{report all the facts}.  If you are not sure whether to state a
  608. fact or leave it out, state it!
  609.  
  610. Often people omit facts because they think they know what causes the
  611. problem and they conclude that some details don't matter.  Thus, you might
  612. assume that the name of the variable you use in an example does not matter.
  613. Well, probably it doesn't, but one cannot be sure.  Perhaps the bug is a
  614. stray memory reference which happens to fetch from the location where that
  615. name is stored in memory; perhaps, if the name were different, the contents
  616. of that location would fool the compiler into doing the right thing despite
  617. the bug.  Play it safe and give a specific, complete example.  That is the
  618. easiest thing for you to do, and the most helpful.
  619.  
  620. Keep in mind that the purpose of a bug report is to enable someone to
  621. fix the bug if it is not known.  It isn't very important what happens if
  622. the bug is already known.  Therefore, always write your bug reports on
  623. the assumption that the bug is not known.
  624.  
  625. Sometimes people give a few sketchy facts and ask, ``Does this ring a
  626. bell?''  This cannot help us fix a bug, so it is basically useless.  We
  627. respond by asking for enough details to enable us to investigate.
  628. You might as well expedite matters by sending them to begin with.
  629.  
  630. Try to make your bug report self-contained.  If we have to ask you for
  631. more information, it is best if you include all the previous information
  632. in your response, as well as the information that was missing.
  633.  
  634. To enable someone to investigate the bug, you should include all these
  635. things:
  636.  
  637. @itemize @bullet
  638. @item
  639. The version of GNU CC.  You can get this by running it with the
  640. @samp{-v} option.
  641.  
  642. Without this, we won't know whether there is any point in looking for
  643. the bug in the current version of GNU CC.
  644.  
  645. @item
  646. A complete input file that will reproduce the bug.  If the bug is in the
  647. C preprocessor, send a source file and any header files that it
  648. requires.  If the bug is in the compiler proper (@file{cc1}), run your
  649. source file through the C preprocessor by doing @samp{gcc -E
  650. @var{sourcefile} > @var{outfile}}, then include the contents of
  651. @var{outfile} in the bug report.  (When you do this, use the same
  652. @samp{-I}, @samp{-D} or @samp{-U} options that you used in actual
  653. compilation.)
  654.  
  655. A single statement is not enough of an example.  In order to compile
  656. it, it must be embedded in a function definition; and the bug might
  657. depend on the details of how this is done.
  658.  
  659. Without a real example one can compile, all anyone can do about your bug
  660. report is wish you luck.  It would be futile to try to guess how to
  661. provoke the bug.  For example, bugs in register allocation and reloading
  662. frequently depend on every little detail of the function they happen in.
  663.  
  664. @item
  665. The command arguments you gave GNU CC or GNU C++ to compile that example
  666. and observe the bug.  For example, did you use @samp{-O}?  To guarantee
  667. you won't omit something important, list all the options.
  668.  
  669. If we were to try to guess the arguments, we would probably guess wrong
  670. and then we would not encounter the bug.
  671.  
  672. @item
  673. The type of machine you are using, and the operating system name and
  674. version number.
  675.  
  676. @item
  677. The operands you gave to the @code{configure} command when you installed
  678. the compiler.
  679.  
  680. @item
  681. A complete list of any modifications you have made to the compiler
  682. source.  (We don't promise to investigate the bug unless it happens in
  683. an unmodified compiler.  But if you've made modifications and don't tell
  684. us, then you are sending us on a wild goose chase.)
  685.  
  686. Be precise about these changes---show a context diff for them.
  687.  
  688. Adding files of your own (such as a machine description for a machine we
  689. don't support) is a modification of the compiler source.
  690.  
  691. @item
  692. Details of any other deviations from the standard procedure for installing
  693. GNU CC.
  694.  
  695. @item
  696. A description of what behavior you observe that you believe is
  697. incorrect.  For example, ``The compiler gets a fatal signal,'' or,
  698. ``The assembler instruction at line 208 in the output is incorrect.''
  699.  
  700. Of course, if the bug is that the compiler gets a fatal signal, then one
  701. can't miss it.  But if the bug is incorrect output, the maintainer might
  702. not notice unless it is glaringly wrong.  None of us has time to study
  703. all the assembler code from a 50-line C program just on the chance that
  704. one instruction might be wrong.  We need @code{you} to do this part!
  705.  
  706. Even if the problem you experience is a fatal signal, you should still
  707. say so explicitly.  Suppose something strange is going on, such as, your
  708. copy of the compiler is out of synch, or you have encountered a bug in
  709. the C library on your system.  (This has happened!)  Your copy might
  710. crash and the copy here would not.  If you @i{said} to expect a crash,
  711. then when the compiler here fails to crash, we would know that the bug
  712. was not happening.  If you don't say to expect a crash, then we would
  713. not know whether the bug was happening.  We would not be able to draw
  714. any conclusion from our observations.
  715.  
  716. Often the observed symptom is incorrect output when your program is run.
  717. Sad to say, this is not enough information unless the program is short
  718. and simple.  None of us has time to study a large program to figure out
  719. how it would work if compiled correctly, much less which line of it was
  720. compiled wrong.  So you will have to do that.  Tell us which source line
  721. it is, and what incorrect result happens when that line is executed.  A
  722. person who understands the program can find this as easily as finding a
  723. bug in the program itself.
  724.  
  725. @item
  726. If you send examples of assembler code output from GNU CC or GNU C++,
  727. please use @samp{-g} when you make them.  The debugging information
  728. includes source line numbers which are essential for correlating the
  729. output with the input.
  730.  
  731. @item
  732. If you wish to suggest changes to the GNU CC source, send them as
  733. context diffs.  If you even discuss something in the GNU CC source,
  734. refer to it by context, not by line number.
  735.  
  736. The line numbers in the development sources don't match those in your
  737. sources.  Your line numbers would convey no useful information to the
  738. maintainers.
  739.  
  740. @item
  741. Additional information from a debugger might enable someone to find a
  742. problem on a machine which he does not have available.  However, you
  743. need to think when you collect this information if you want it to have
  744. any chance of being useful.
  745.  
  746. @cindex backtrace for bug reports
  747. For example, many people send just a backtrace, but that is never
  748. useful by itself.  A simple backtrace with arguments conveys little
  749. about GNU CC because the compiler is largely data-driven; the same
  750. functions are called over and over for different RTL insns, doing
  751. different things depending on the details of the insn.
  752.  
  753. Most of the arguments listed in the backtrace are useless because they
  754. are pointers to RTL list structure.  The numeric values of the
  755. pointers, which the debugger prints in the backtrace, have no
  756. significance whatever; all that matters is the contents of the objects
  757. they point to (and most of the contents are other such pointers).
  758.  
  759. In addition, most compiler passes consist of one or more loops that
  760. scan the RTL insn sequence.  The most vital piece of information about
  761. such a loop---which insn it has reached---is usually in a local variable,
  762. not in an argument.
  763.  
  764. @findex debug_rtx
  765. What you need to provide in addition to a backtrace are the values of
  766. the local variables for several stack frames up.  When a local
  767. variable or an argument is an RTX, first print its value and then use
  768. the GDB command @code{pr} to print the RTL expression that it points
  769. to.  (If GDB doesn't run on your machine, use your debugger to call
  770. the function @code{debug_rtx} with the RTX as an argument.)  In
  771. general, whenever a variable is a pointer, its value is no use
  772. without the data it points to.
  773.  
  774. In addition, include a debugging dump from just before the pass
  775. in which the crash happens.  Most bugs involve a series of insns,
  776. not just one.
  777. @end itemize
  778.  
  779. Here are some things that are not necessary:
  780.  
  781. @itemize @bullet
  782. @item
  783. A description of the envelope of the bug.
  784.  
  785. Often people who encounter a bug spend a lot of time investigating
  786. which changes to the input file will make the bug go away and which
  787. changes will not affect it.
  788.  
  789. This is often time consuming and not very useful, because the way we
  790. will find the bug is by running a single example under the debugger with
  791. breakpoints, not by pure deduction from a series of examples.  You might
  792. as well save your time for something else.
  793.  
  794. Of course, if you can find a simpler example to report @emph{instead} of
  795. the original one, that is a convenience.  Errors in the output will be
  796. easier to spot, running under the debugger will take less time, etc.
  797. Most GNU CC bugs involve just one function, so the most straightforward
  798. way to simplify an example is to delete all the function definitions
  799. except the one where the bug occurs.  Those earlier in the file may be
  800. replaced by external declarations if the crucial function depends on
  801. them.  (Exception: inline functions may affect compilation of functions
  802. defined later in the file.)
  803.  
  804. However, simplification is not vital; if you don't want to do this,
  805. report the bug anyway and send the entire test case you used.
  806.  
  807. @item
  808. A patch for the bug.
  809.  
  810. A patch for the bug is useful if it is a good one.  But don't omit the
  811. necessary information, such as the test case, on the assumption that a
  812. patch is all we need.  We might see problems with your patch and decide
  813. to fix the problem another way, or we might not understand it at all.
  814.  
  815. Sometimes with a program as complicated as GNU CC it is very hard to
  816. construct an example that will make the program follow a certain path
  817. through the code.  If you don't send the example, we won't be able to
  818. construct one, so we won't be able to verify that the bug is fixed.
  819.  
  820. And if we can't understand what bug you are trying to fix, or why your
  821. patch should be an improvement, we won't install it.  A test case will
  822. help us to understand.
  823.  
  824. @xref{Sending Patches}, for guidelines on how to make it easy for us to
  825. understand and install your patches.
  826.  
  827. @item
  828. A guess about what the bug is or what it depends on.
  829.  
  830. Such guesses are usually wrong.  Even I can't guess right about such
  831. things without first using the debugger to find the facts.
  832. @end itemize
  833.  
  834. @node Sending Patches,, Bug Reporting, Bugs
  835. @section Sending Patches for GNU CC
  836.  
  837. If you would like to write bug fixes or improvements for the GNU C
  838. compiler, that is very helpful.  When you send your changes, please
  839. follow these guidelines to avoid causing extra work for us in studying
  840. the patches.
  841.  
  842. If you don't follow these guidelines, your information might still be
  843. useful, but using it will take extra work.  Maintaining GNU C is a lot
  844. of work in the best of circumstances, and we can't keep up unless you do
  845. your best to help.
  846.  
  847. @itemize @bullet
  848. @item
  849. Send an explanation with your changes of what problem they fix or what
  850. improvement they bring about.  For a bug fix, just include a copy of the
  851. bug report, and explain why the change fixes the bug.
  852.  
  853. (Referring to a bug report is not as good as including it, because then
  854. we will have to look it up, and we have probably already deleted it if
  855. we've already fixed the bug.)
  856.  
  857. @item
  858. Always include a proper bug report for the problem you think you have
  859. fixed.  We need to convince ourselves that the change is right before
  860. installing it.  Even if it is right, we might have trouble judging it if
  861. we don't have a way to reproduce the problem.
  862.  
  863. @item
  864. Include all the comments that are appropriate to help people reading the
  865. source in the future understand why this change was needed.
  866.  
  867. @item
  868. Don't mix together changes made for different reasons.
  869. Send them @emph{individually}.
  870.  
  871. If you make two changes for separate reasons, then we might not want to
  872. install them both.  We might want to install just one.  If you send them
  873. all jumbled together in a single set of diffs, we have to do extra work
  874. to disentangle them---to figure out which parts of the change serve
  875. which purpose.  If we don't have time for this, we might have to ignore
  876. your changes entirely.
  877.  
  878. If you send each change as soon as you have written it, with its own
  879. explanation, then the two changes never get tangled up, and we can
  880. consider each one properly without any extra work to disentangle them.
  881.  
  882. Ideally, each change you send should be impossible to subdivide into
  883. parts that we might want to consider separately, because each of its
  884. parts gets its motivation from the other parts.
  885.  
  886. @item
  887. Send each change as soon as that change is finished.  Sometimes people
  888. think they are helping us by accumulating many changes to send them all
  889. together.  As explained above, this is absolutely the worst thing you
  890. could do.
  891.  
  892. Since you should send each change separately, you might as well send it
  893. right away.  That gives us the option of installing it immediately if it
  894. is important.
  895.  
  896. @item
  897. Use @samp{diff -c} to make your diffs.  Diffs without context are hard
  898. for us to install reliably.  More than that, they make it hard for us to
  899. study the diffs to decide whether we want to install them.  Unidiff
  900. format is better than contextless diffs, but not as easy to read as
  901. @samp{-c} format.
  902.  
  903. If you have GNU diff, use @samp{diff -cp}, which shows the name of the
  904. function that each change occurs in.
  905.  
  906. @item
  907. Write the change log entries for your changes.  We get lots of changes,
  908. and we don't have time to do all the change log writing ourselves.
  909.  
  910. Read the @file{ChangeLog} file to see what sorts of information to put
  911. in, and to learn the style that we use.  The purpose of the change log
  912. is to show people where to find what was changed.  So you need to be
  913. specific about what functions you changed; in large functions, it's
  914. often helpful to indicate where within the function the change was.
  915.  
  916. On the other hand, once you have shown people where to find the change,
  917. you need not explain its purpose. Thus, if you add a new function, all
  918. you need to say about it is that it is new.  If you feel that the
  919. purpose needs explaining, it probably does---but the explanation will be
  920. much more useful if you put it in comments in the code.
  921.  
  922. If you would like your name to appear in the header line for who made
  923. the change, send us the header line.
  924.  
  925. @item
  926. When you write the fix, keep in mind that I can't install a change that
  927. would break other systems.
  928.  
  929. People often suggest fixing a problem by changing machine-independent
  930. files such as @file{toplev.c} to do something special that a particular
  931. system needs.  Sometimes it is totally obvious that such changes would
  932. break GNU CC for almost all users.  We can't possibly make a change like
  933. that.  At best it might tell us how to write another patch that would
  934. solve the problem acceptably.
  935.  
  936. Sometimes people send fixes that @emph{might} be an improvement in
  937. general---but it is hard to be sure of this.  It's hard to install
  938. such changes because we have to study them very carefully.  Of course,
  939. a good explanation of the reasoning by which you concluded the change
  940. was correct can help convince us.
  941.  
  942. The safest changes are changes to the configuration files for a
  943. particular machine.  These are safe because they can't create new bugs
  944. on other machines.
  945.  
  946. Please help us keep up with the workload by designing the patch in a
  947. form that is good to install.
  948. @end itemize
  949.  
  950. @node Service
  951. @chapter How To Get Help with GNU CC
  952.  
  953. If you need help installing, using or changing GNU CC, there are two
  954. ways to find it:
  955.  
  956. @itemize @bullet
  957. @item
  958. Send a message to a suitable network mailing list.  First try
  959. @code{bug-gcc@@prep.ai.mit.edu}, and if that brings no response, try
  960. @code{help-gcc@@prep.ai.mit.edu}.
  961.  
  962. @item
  963. Look in the service directory for someone who might help you for a fee.
  964. The service directory is found in the file named @file{SERVICE} in the
  965. GNU CC distribution.
  966. @end itemize
  967.  
  968. @node VMS
  969. @chapter Using GNU CC on VMS
  970.  
  971. @menu
  972. * Include Files and VMS::  Where the preprocessor looks for the include files.
  973. * Global Declarations::    How to do globaldef, globalref and globalvalue with
  974.                            GNU CC.
  975. * VMS Misc::           Misc information.
  976. @end menu
  977.  
  978. @node Include Files and VMS
  979. @section Include Files and VMS
  980.  
  981. @cindex include files and VMS
  982. @cindex VMS and include files
  983. @cindex header files and VMS
  984. Due to the differences between the filesystems of Unix and VMS, GNU CC
  985. attempts to translate file names in @samp{#include} into names that VMS
  986. will understand.  The basic strategy is to prepend a prefix to the
  987. specification of the include file, convert the whole filename to a VMS
  988. filename, and then try to open the file.  GNU CC tries various prefixes
  989. one by one until one of them succeeds:
  990.  
  991. @enumerate
  992. @item
  993. The first prefix is the @samp{GNU_CC_INCLUDE:} logical name: this is
  994. where GNU C header files are traditionally stored.  If you wish to store
  995. header files in non-standard locations, then you can assign the logical
  996. @samp{GNU_CC_INCLUDE} to be a search list, where each element of the
  997. list is suitable for use with a rooted logical.
  998.  
  999. @item
  1000. The next prefix tried is @samp{SYS$SYSROOT:[SYSLIB.]}.  This is where
  1001. VAX-C header files are traditionally stored.
  1002.  
  1003. @item 
  1004. If the include file specification by itself is a valid VMS filename, the
  1005. preprocessor then uses this name with no prefix in an attempt to open
  1006. the include file.
  1007.  
  1008. @item
  1009. If the file specification is not a valid VMS filename (i.e. does not
  1010. contain a device or a directory specifier, and contains a @samp{/}
  1011. character), the preprocessor tries to convert it from Unix syntax to 
  1012. VMS syntax.
  1013.  
  1014. Conversion works like this: the first directory name becomes a device,
  1015. and the rest of the directories are converted into VMS-format directory
  1016. names.  For example, @file{X11/foobar.h} is translated to
  1017. @file{X11:[000000]foobar.h} or @file{X11:foobar.h}, whichever one can be
  1018. opened.  This strategy allows you to assign a logical name to point to
  1019. the actual location of the header files.
  1020.  
  1021. @item
  1022. If none of these strategies succeeds, the @samp{#include} fails.
  1023. @end enumerate
  1024.  
  1025. Include directives of the form:
  1026.  
  1027. @example
  1028. #include foobar
  1029. @end example
  1030.  
  1031. @noindent
  1032. are a common source of incompatibility between VAX-C and GNU CC.  VAX-C
  1033. treats this much like a standard @code{#include <foobar.h>} directive.
  1034. That is incompatible with the ANSI C behavior implemented by GNU CC: to
  1035. expand the name @code{foobar} as a macro.  Macro expansion should
  1036. eventually yield one of the two standard formats for @code{#include}:
  1037.  
  1038. @example
  1039. #include "@var{file}"
  1040. #include <@var{file}>
  1041. @end example
  1042.  
  1043. If you have this problem, the best solution is to modify the source to
  1044. convert the @code{#include} directives to one of the two standard forms.
  1045. That will work with either compiler.  If you want a quick and dirty fix,
  1046. define the file names as macros with the proper expansion, like this:
  1047.  
  1048. @example
  1049. #define stdio <stdio.h>
  1050. @end example
  1051.  
  1052. @noindent
  1053. This will work, as long as the name doesn't conflict with anything else
  1054. in the program.
  1055.  
  1056. Another source of incompatibility is that VAX-C assumes that:
  1057.  
  1058. @example
  1059. #include "foobar"
  1060. @end example
  1061.  
  1062. @noindent
  1063. is actually asking for the file @file{foobar.h}.  GNU CC does not
  1064. make this assumption, and instead takes what you ask for literally;
  1065. it tries to read the file @file{foobar}.  The best way to avoid this
  1066. problem is to always specify the desired file extension in your include
  1067. directives.
  1068.  
  1069. GNU CC for VMS is distributed with a set of include files that is
  1070. sufficient to compile most general purpose programs.  Even though the
  1071. GNU CC distribution does not contain header files to define constants
  1072. and structures for some VMS system-specific functions, there is no
  1073. reason why you cannot use GNU CC with any of these functions.  You first
  1074. may have to generate or create header files, either by using the public
  1075. domain utility @code{UNSDL} (which can be found on a DECUS tape), or by
  1076. extracting the relevant modules from one of the system macro libraries,
  1077. and using an editor to construct a C header file.
  1078.  
  1079. @node Global Declarations
  1080. @section Global Declarations and VMS
  1081.  
  1082. @findex GLOBALREF
  1083. @findex GLOBALDEF
  1084. @findex GLOBALVALUEDEF
  1085. @findex GLOBALVALUEREF
  1086. GNU CC does not provide the @code{globalref}, @code{globaldef} and
  1087. @code{globalvalue} keywords of VAX-C.  You can get the same effect with
  1088. an obscure feature of GAS, the GNU assembler.  (This requires GAS
  1089. version 1.39 or later.)  The following macros allow you to use this
  1090. feature in a fairly natural way:
  1091.  
  1092. @smallexample
  1093. #ifdef __GNUC__
  1094. #define GLOBALREF(TYPE,NAME)                      \
  1095.   TYPE NAME                                       \
  1096.   asm ("_$$PsectAttributes_GLOBALSYMBOL$$" #NAME)
  1097. #define GLOBALDEF(TYPE,NAME,VALUE)                \
  1098.   TYPE NAME                                       \
  1099.   asm ("_$$PsectAttributes_GLOBALSYMBOL$$" #NAME) \
  1100.     = VALUE
  1101. #define GLOBALVALUEREF(TYPE,NAME)                 \
  1102.   const TYPE NAME[1]                              \     
  1103.   asm ("_$$PsectAttributes_GLOBALVALUE$$" #NAME)
  1104. #define GLOBALVALUEDEF(TYPE,NAME,VALUE)           \
  1105.   const TYPE NAME[1]                              \
  1106.   asm ("_$$PsectAttributes_GLOBALVALUE$$" #NAME)  \
  1107.     = @{VALUE@}
  1108. #else
  1109. #define GLOBALREF(TYPE,NAME) \
  1110.   globalref TYPE NAME
  1111. #define GLOBALDEF(TYPE,NAME,VALUE) \
  1112.   globaldef TYPE NAME = VALUE
  1113. #define GLOBALVALUEDEF(TYPE,NAME,VALUE) \
  1114.   globalvalue TYPE NAME = VALUE
  1115. #define GLOBALVALUEREF(TYPE,NAME) \
  1116.   globalvalue TYPE NAME
  1117. #endif
  1118. @end smallexample
  1119.  
  1120. @noindent
  1121. (The @code{_$$PsectAttributes_GLOBALSYMBOL} prefix at the start of the
  1122. name is removed by the assembler, after it has modified the attributes
  1123. of the symbol).  These macros are provided in the VMS binaries
  1124. distribution in a header file @file{GNU_HACKS.H}.  An example of the
  1125. usage is:
  1126.  
  1127. @example
  1128. GLOBALREF (int, ijk);
  1129. GLOBALDEF (int, jkl, 0);
  1130. @end example
  1131.  
  1132. The macros @code{GLOBALREF} and @code{GLOBALDEF} cannot be used
  1133. straightforwardly for arrays, since there is no way to insert the array
  1134. dimension into the declaration at the right place.  However, you can
  1135. declare an array with these macros if you first define a typedef for the
  1136. array type, like this:
  1137.  
  1138. @example
  1139. typedef int intvector[10];
  1140. GLOBALREF (intvector, foo);
  1141. @end example
  1142.  
  1143. Array and structure initializers will also break the macros; you can
  1144. define the initializer to be a macro of its own, or you can expand the
  1145. @code{GLOBALDEF} macro by hand.  You may find a case where you wish to
  1146. use the @code{GLOBALDEF} macro with a large array, but you are not
  1147. interested in explicitly initializing each element of the array.  In
  1148. such cases you can use an initializer like: @code{@{0,@}}, which will
  1149. initialize the entire array to @code{0}.
  1150.  
  1151. A shortcoming of this implementation is that a variable declared with
  1152. @code{GLOBALVALUEREF} or @code{GLOBALVALUEDEF} is always an array.  For
  1153. example, the declaration:
  1154.  
  1155. @example
  1156. GLOBALVALUEREF(int, ijk);
  1157. @end example
  1158.  
  1159. @noindent
  1160. declares the variable @code{ijk} as an array of type @code{int [1]}.
  1161. This is done because a globalvalue is actually a constant; its ``value''
  1162. is what the linker would normally consider an address.  That is not how
  1163. an integer value works in C, but it is how an array works.  So treating
  1164. the symbol as an array name gives consistent results---with the
  1165. exception that the value seems to have the wrong type.  @strong{Don't
  1166. try to access an element of the array.}  It doesn't have any elements.
  1167. The array ``address'' may not be the address of actual storage.
  1168.  
  1169. The fact that the symbol is an array may lead to warnings where the
  1170. variable is used.  Insert type casts to avoid the warnings.  Here is an
  1171. example; it takes advantage of the ANSI C feature allowing macros that
  1172. expand to use the same name as the macro itself.
  1173.  
  1174. @example
  1175. GLOBALVALUEREF (int, ss$_normal);
  1176. GLOBALVALUEDEF (int, xyzzy,123);
  1177. #ifdef __GNUC__
  1178. #define ss$_normal ((int) ss$_normal)
  1179. #define xyzzy ((int) xyzzy)
  1180. #endif
  1181. @end example
  1182.  
  1183. Don't use @code{globaldef} or @code{globalref} with a variable whose
  1184. type is an enumeration type; this is not implemented.  Instead, make the
  1185. variable an integer, and use a @code{globalvaluedef} for each of the
  1186. enumeration values.  An example of this would be:
  1187.  
  1188. @example
  1189. #ifdef __GNUC__
  1190. GLOBALDEF (int, color, 0);
  1191. GLOBALVALUEDEF (int, RED, 0);
  1192. GLOBALVALUEDEF (int, BLUE, 1);
  1193. GLOBALVALUEDEF (int, GREEN, 3);
  1194. #else
  1195. enum globaldef color @{RED, BLUE, GREEN = 3@};
  1196. #endif
  1197. @end example
  1198.  
  1199. @node VMS Misc
  1200. @section Other VMS Issues
  1201.  
  1202. @cindex exit status and VMS
  1203. @cindex return value of @code{main}
  1204. @cindex @code{main} and the exit status
  1205. GNU CC automatically arranges for @code{main} to return 1 by default if
  1206. you fail to specify an explicit return value.  This will be interpreted
  1207. by VMS as a status code indicating a normal successful completion.
  1208. Version 1 of GNU CC did not provide this default.
  1209.  
  1210. GNU CC on VMS works only with the GNU assembler, GAS.  You need version
  1211. 1.37 or later of GAS in order to produce value debugging information for
  1212. the VMS debugger.  Use the ordinary VMS linker with the object files
  1213. produced by GAS.
  1214.  
  1215. @cindex shared VMS run time system
  1216. @cindex @file{VAXCRTL}
  1217. Under previous versions of GNU CC, the generated code would occasionally
  1218. give strange results when linked to the sharable @file{VAXCRTL} library.
  1219. Now this should work.
  1220.  
  1221. A caveat for use of @code{const} global variables: the @code{const}
  1222. modifier must be specified in every external declaration of the variable
  1223. in all of the source files that use that variable.  Otherwise the linker
  1224. will issue warnings about conflicting attributes for the variable.  Your
  1225. program will still work despite the warnings, but the variable will be
  1226. placed in writable storage.
  1227.  
  1228. @cindex name augmentation
  1229. @cindex case sensitivity and VMS
  1230. @cindex VMS and case sensitivity
  1231. The VMS linker does not distinguish between upper and lower case letters
  1232. in function and variable names.  However, usual practice in C is to
  1233. distinguish case.  Normally GNU CC (by means of the assembler GAS)
  1234. implements usual C behavior by augmenting each name that is not all
  1235. lower-case.  A name is augmented by truncating it to at most 23
  1236. characters and then adding more characters at the end which encode the
  1237. case pattern the rest.
  1238.  
  1239. Name augmentation yields bad results for programs that use precompiled
  1240. libraries (such as Xlib) which were generated by another compiler.  You
  1241. can use the compiler option @samp{/NOCASE_HACK} to inhibit augmentation;
  1242. it makes external C functions and variables case-independent as is usual
  1243. on VMS.  Alternatively, you could write all references to the functions
  1244. and variables in such libraries using lower case; this will work on VMS,
  1245. but is not portable to other systems.
  1246.  
  1247. Function and variable names are handled somewhat differently with GNU
  1248. C++.  The GNU C++ compiler performs @dfn{name mangling} on function
  1249. names, which means that it adds information to the function name to
  1250. describe the data types of the arguments that the function takes. One
  1251. result of this is that the name of a function can become very long.
  1252. Since the VMS linker only recognizes the first 31 characters in a name,
  1253. special action is taken to ensure that each function and variable has a
  1254. unique name that can be represented in 31 characters.
  1255.  
  1256. If the name (plus a name augmentation, if required) is less than 32
  1257. characters in length, then no special action is performed. If the name
  1258. is longer than 31 characters, the assembler (GAS) will generate a
  1259. hash string based upon the function name, truncate the function name to
  1260. 23 characters, and append the hash string to the truncated name.  If the
  1261. @samp{/VERBOSE} compiler option is used, the assembler will print both
  1262. the full and truncated names of each symbol that is truncated.
  1263.  
  1264. The @samp{/NOCASE_HACK} compiler option should not be used when you are
  1265. compiling programs that use libg++. libg++ has several instances of
  1266. objects (i.e.  @code{Filebuf} and @code{filebuf}) which become
  1267. indistinguishable in a case-insensitive environment.  This leads to
  1268. cases where you need to inhibit augmentation selectively (if you were
  1269. using libg++ and Xlib in the same program, for example).  There is no
  1270. special feature for doing this, but you can get the result by defining a
  1271. macro for each mixed case symbol for which you wish to inhibit
  1272. augmentation.  The macro should expand into the lower case equivalent of
  1273. itself.  For example:
  1274.  
  1275. @example
  1276. #define StuDlyCapS studlycaps
  1277. @end example
  1278.  
  1279. These macro definitions can be placed in a header file to minimize the
  1280. number of changes to your source code.
  1281.  
  1282. @ifset INTERNALS
  1283. @node Portability
  1284. @chapter GNU CC and Portability
  1285. @cindex portability
  1286. @cindex GNU CC and portability
  1287.  
  1288. The main goal of GNU CC was to make a good, fast compiler for machines in
  1289. the class that the GNU system aims to run on: 32-bit machines that address
  1290. 8-bit bytes and have several general registers.  Elegance, theoretical
  1291. power and simplicity are only secondary.
  1292.  
  1293. GNU CC gets most of the information about the target machine from a machine
  1294. description which gives an algebraic formula for each of the machine's
  1295. instructions.  This is a very clean way to describe the target.  But when
  1296. the compiler needs information that is difficult to express in this
  1297. fashion, I have not hesitated to define an ad-hoc parameter to the machine
  1298. description.  The purpose of portability is to reduce the total work needed
  1299. on the compiler; it was not of interest for its own sake.
  1300.  
  1301. @cindex endianness
  1302. @cindex autoincrement addressing, availability
  1303. @findex abort
  1304. GNU CC does not contain machine dependent code, but it does contain code
  1305. that depends on machine parameters such as endianness (whether the most
  1306. significant byte has the highest or lowest address of the bytes in a word)
  1307. and the availability of autoincrement addressing.  In the RTL-generation
  1308. pass, it is often necessary to have multiple strategies for generating code
  1309. for a particular kind of syntax tree, strategies that are usable for different
  1310. combinations of parameters.  Often I have not tried to address all possible
  1311. cases, but only the common ones or only the ones that I have encountered.
  1312. As a result, a new target may require additional strategies.  You will know
  1313. if this happens because the compiler will call @code{abort}.  Fortunately,
  1314. the new strategies can be added in a machine-independent fashion, and will
  1315. affect only the target machines that need them.
  1316. @end ifset
  1317.  
  1318. @ifset INTERNALS
  1319. @node Interface
  1320. @chapter Interfacing to GNU CC Output
  1321. @cindex interfacing to GNU CC output
  1322. @cindex run-time conventions
  1323. @cindex function call conventions
  1324. @cindex conventions, run-time
  1325.  
  1326. GNU CC is normally configured to use the same function calling convention
  1327. normally in use on the target system.  This is done with the
  1328. machine-description macros described (@pxref{Target Macros}).
  1329.  
  1330. @cindex unions, returning
  1331. @cindex structures, returning
  1332. @cindex returning structures and unions
  1333. However, returning of structure and union values is done differently on
  1334. some target machines.  As a result, functions compiled with PCC
  1335. returning such types cannot be called from code compiled with GNU CC,
  1336. and vice versa.  This does not cause trouble often because few Unix
  1337. library routines return structures or unions.
  1338.  
  1339. GNU CC code returns structures and unions that are 1, 2, 4 or 8 bytes
  1340. long in the same registers used for @code{int} or @code{double} return
  1341. values.  (GNU CC typically allocates variables of such types in
  1342. registers also.)  Structures and unions of other sizes are returned by
  1343. storing them into an address passed by the caller (usually in a
  1344. register).  The machine-description macros @code{STRUCT_VALUE} and
  1345. @code{STRUCT_INCOMING_VALUE} tell GNU CC where to pass this address.
  1346.  
  1347. By contrast, PCC on most target machines returns structures and unions
  1348. of any size by copying the data into an area of static storage, and then
  1349. returning the address of that storage as if it were a pointer value.
  1350. The caller must copy the data from that memory area to the place where
  1351. the value is wanted.  This is slower than the method used by GNU CC, and
  1352. fails to be reentrant.
  1353.  
  1354. On some target machines, such as RISC machines and the 80386, the
  1355. standard system convention is to pass to the subroutine the address of
  1356. where to return the value.  On these machines, GNU CC has been
  1357. configured to be compatible with the standard compiler, when this method
  1358. is used.  It may not be compatible for structures of 1, 2, 4 or 8 bytes.
  1359.  
  1360. @cindex argument passing
  1361. @cindex passing arguments
  1362. GNU CC uses the system's standard convention for passing arguments.  On
  1363. some machines, the first few arguments are passed in registers; in
  1364. others, all are passed on the stack.  It would be possible to use
  1365. registers for argument passing on any machine, and this would probably
  1366. result in a significant speedup.  But the result would be complete
  1367. incompatibility with code that follows the standard convention.  So this
  1368. change is practical only if you are switching to GNU CC as the sole C
  1369. compiler for the system.  We may implement register argument passing on
  1370. certain machines once we have a complete GNU system so that we can
  1371. compile the libraries with GNU CC.
  1372.  
  1373. On some machines (particularly the Sparc), certain types of arguments
  1374. are passed ``by invisible reference''.  This means that the value is
  1375. stored in memory, and the address of the memory location is passed to
  1376. the subroutine.
  1377.  
  1378. @cindex @code{longjmp} and automatic variables
  1379. If you use @code{longjmp}, beware of automatic variables.  ANSI C says that
  1380. automatic variables that are not declared @code{volatile} have undefined
  1381. values after a @code{longjmp}.  And this is all GNU CC promises to do,
  1382. because it is very difficult to restore register variables correctly, and
  1383. one of GNU CC's features is that it can put variables in registers without
  1384. your asking it to.
  1385.  
  1386. If you want a variable to be unaltered by @code{longjmp}, and you don't
  1387. want to write @code{volatile} because old C compilers don't accept it,
  1388. just take the address of the variable.  If a variable's address is ever
  1389. taken, even if just to compute it and ignore it, then the variable cannot
  1390. go in a register:
  1391.  
  1392. @example
  1393. @{
  1394.   int careful;
  1395.   &careful;
  1396.   @dots{}
  1397. @}
  1398. @end example
  1399.  
  1400. @cindex arithmetic libraries
  1401. @cindex math libraries
  1402. Code compiled with GNU CC may call certain library routines.  Most of
  1403. them handle arithmetic for which there are no instructions.  This
  1404. includes multiply and divide on some machines, and floating point
  1405. operations on any machine for which floating point support is disabled
  1406. with @samp{-msoft-float}.  Some standard parts of the C library, such as
  1407. @code{bcopy} or @code{memcpy}, are also called automatically.  The usual
  1408. function call interface is used for calling the library routines.
  1409.  
  1410. These library routines should be defined in the library @file{libgcc.a},
  1411. which GNU CC automatically searches whenever it links a program.  On
  1412. machines that have multiply and divide instructions, if hardware
  1413. floating point is in use, normally @file{libgcc.a} is not needed, but it
  1414. is searched just in case.
  1415.  
  1416. Each arithmetic function is defined in @file{libgcc1.c} to use the
  1417. corresponding C arithmetic operator.  As long as the file is compiled
  1418. with another C compiler, which supports all the C arithmetic operators,
  1419. this file will work portably.  However, @file{libgcc1.c} does not work if
  1420. compiled with GNU CC, because each arithmetic function would compile
  1421. into a call to itself!
  1422. @end ifset
  1423.  
  1424. @ifset INTERNALS
  1425. @node Passes
  1426. @chapter Passes and Files of the Compiler
  1427. @cindex passes and files of the compiler
  1428. @cindex files and passes of the compiler
  1429. @cindex compiler passes and files
  1430.  
  1431. @cindex top level of compiler
  1432. The overall control structure of the compiler is in @file{toplev.c}.  This
  1433. file is responsible for initialization, decoding arguments, opening and
  1434. closing files, and sequencing the passes.
  1435.  
  1436. @cindex parsing pass
  1437. The parsing pass is invoked only once, to parse the entire input.  The RTL
  1438. intermediate code for a function is generated as the function is parsed, a
  1439. statement at a time.  Each statement is read in as a syntax tree and then
  1440. converted to RTL; then the storage for the tree for the statement is
  1441. reclaimed.  Storage for types (and the expressions for their sizes),
  1442. declarations, and a representation of the binding contours and how they nest,
  1443. remain until the function is finished being compiled; these are all needed
  1444. to output the debugging information.
  1445.  
  1446. @findex rest_of_compilation
  1447. @findex rest_of_decl_compilation
  1448. Each time the parsing pass reads a complete function definition or
  1449. top-level declaration, it calls the function
  1450. @code{rest_of_compilation} or @code{rest_of_decl_compilation} in
  1451. @file{toplev.c}, which are responsible for all further processing
  1452. necessary, ending with output of the assembler language.  All other
  1453. compiler passes run, in sequence, within @code{rest_of_compilation}.
  1454. When that function returns from compiling a function definition, the
  1455. storage used for that function definition's compilation is entirely
  1456. freed, unless it is an inline function (@pxref{Inline}).
  1457.  
  1458. Here is a list of all the passes of the compiler and their source files.
  1459. Also included is a description of where debugging dumps can be requested
  1460. with @samp{-d} options.
  1461.  
  1462. @itemize @bullet
  1463. @item
  1464. Parsing.  This pass reads the entire text of a function definition,
  1465. constructing partial syntax trees.  This and RTL generation are no longer
  1466. truly separate passes (formerly they were), but it is easier to think
  1467. of them as separate.
  1468.  
  1469. The tree representation does not entirely follow C syntax, because it is
  1470. intended to support other languages as well.
  1471.  
  1472. Language-specific data type analysis is also done in this pass, and every
  1473. tree node that represents an expression has a data type attached.
  1474. Variables are represented as declaration nodes.
  1475.  
  1476. @cindex constant folding
  1477. @cindex arithmetic simplifications
  1478. @cindex simplifications, arithmetic
  1479. Constant folding and some arithmetic simplifications are also done
  1480. during this pass.
  1481.  
  1482. The language-independent source files for parsing are
  1483. @file{stor-layout.c}, @file{fold-const.c}, and @file{tree.c}.
  1484. There are also header files @file{tree.h} and @file{tree.def}
  1485. which define the format of the tree representation.@refill
  1486.  
  1487. The source files for parsing C are @file{c-parse.y}, @file{c-decl.c},
  1488. @file{c-typeck.c}, @file{c-convert.c}, @file{c-lang.c}, and
  1489. @file{c-aux-info.c} along with header files @file{c-lex.h}, and
  1490. @file{c-tree.h}.
  1491.  
  1492. The source files for parsing C++ are @file{cp-parse.y},
  1493. @file{cp-class.c}, @file{cp-cvt.c},@*
  1494. @file{cp-decl.c}, @file{cp-decl.c}, @file{cp-decl2.c},
  1495. @file{cp-dem.c}, @file{cp-except.c},@*
  1496. @file{cp-expr.c}, @file{cp-init.c}, @file{cp-lex.c},
  1497. @file{cp-method.c}, @file{cp-ptree.c},@*
  1498. @file{cp-search.c}, @file{cp-tree.c}, @file{cp-type2.c}, and
  1499. @file{cp-typeck.c}, along with header files @file{cp-tree.def},
  1500. @file{cp-tree.h}, and @file{cp-decl.h}.
  1501.  
  1502. The special source files for parsing Objective C are
  1503. @file{objc-parse.y}, @file{objc-actions.c}, @file{objc-tree.def}, and
  1504. @file{objc-actions.h}.  Certain C-specific files are used for this as
  1505. well.
  1506.  
  1507. The file @file{c-common.c} is also used for all of the above languages.
  1508.  
  1509. @cindex RTL generation
  1510. @item
  1511. RTL generation.  This is the conversion of syntax tree into RTL code.
  1512. It is actually done statement-by-statement during parsing, but for
  1513. most purposes it can be thought of as a separate pass.
  1514.  
  1515. @cindex target-parameter-dependent code
  1516. This is where the bulk of target-parameter-dependent code is found,
  1517. since often it is necessary for strategies to apply only when certain
  1518. standard kinds of instructions are available.  The purpose of named
  1519. instruction patterns is to provide this information to the RTL
  1520. generation pass.
  1521.  
  1522. @cindex tail recursion optimization
  1523. Optimization is done in this pass for @code{if}-conditions that are
  1524. comparisons, boolean operations or conditional expressions.  Tail
  1525. recursion is detected at this time also.  Decisions are made about how
  1526. best to arrange loops and how to output @code{switch} statements.
  1527.  
  1528. The source files for RTL generation include @file{stmt.c},
  1529. @file{function.c}, @file{expr.c}, @file{calls.c}, @file{explow.c},
  1530. @file{expmed.c}, @file{optabs.c} and @file{emit-rtl.c}.  Also, the file
  1531. @file{insn-emit.c}, generated from the machine description by the
  1532. program @code{genemit}, is used in this pass.  The header file
  1533. @file{expr.h} is used for communication within this pass.@refill
  1534.  
  1535. @findex genflags
  1536. @findex gencodes
  1537. The header files @file{insn-flags.h} and @file{insn-codes.h},
  1538. generated from the machine description by the programs @code{genflags}
  1539. and @code{gencodes}, tell this pass which standard names are available
  1540. for use and which patterns correspond to them.@refill
  1541.  
  1542. Aside from debugging information output, none of the following passes
  1543. refers to the tree structure representation of the function (only
  1544. part of which is saved).
  1545.  
  1546. @cindex inline, automatic
  1547. The decision of whether the function can and should be expanded inline
  1548. in its subsequent callers is made at the end of rtl generation.  The
  1549. function must meet certain criteria, currently related to the size of
  1550. the function and the types and number of parameters it has.  Note that
  1551. this function may contain loops, recursive calls to itself
  1552. (tail-recursive functions can be inlined!), gotos, in short, all
  1553. constructs supported by GNU CC.  The file @file{integrate.c} contains
  1554. the code to save a function's rtl for later inlining and to inline that
  1555. rtl when the function is called.  The header file @file{integrate.h}
  1556. is also used for this purpose.
  1557.  
  1558. The option @samp{-dr} causes a debugging dump of the RTL code after
  1559. this pass.  This dump file's name is made by appending @samp{.rtl} to
  1560. the input file name.
  1561.  
  1562. @cindex jump optimization
  1563. @cindex unreachable code
  1564. @cindex dead code
  1565. @item
  1566. Jump optimization.  This pass simplifies jumps to the following
  1567. instruction, jumps across jumps, and jumps to jumps.  It deletes
  1568. unreferenced labels and unreachable code, except that unreachable code
  1569. that contains a loop is not recognized as unreachable in this pass.
  1570. (Such loops are deleted later in the basic block analysis.)  It also
  1571. converts some code originally written with jumps into sequences of
  1572. instructions that directly set values from the results of comparisons,
  1573. if the machine has such instructions.
  1574.  
  1575. Jump optimization is performed two or three times.  The first time is
  1576. immediately following RTL generation.  The second time is after CSE,
  1577. but only if CSE says repeated jump optimization is needed.  The
  1578. last time is right before the final pass.  That time, cross-jumping
  1579. and deletion of no-op move instructions are done together with the
  1580. optimizations described above.
  1581.  
  1582. The source file of this pass is @file{jump.c}.
  1583.  
  1584. The option @samp{-dj} causes a debugging dump of the RTL code after
  1585. this pass is run for the first time.  This dump file's name is made by
  1586. appending @samp{.jump} to the input file name.
  1587.  
  1588. @cindex register use analysis
  1589. @item
  1590. Register scan.  This pass finds the first and last use of each
  1591. register, as a guide for common subexpression elimination.  Its source
  1592. is in @file{regclass.c}.
  1593.  
  1594. @cindex jump threading
  1595. @item
  1596. Jump threading.  This pass detects a condition jump that branches to an
  1597. identical or inverse test.  Such jumps can be @samp{threaded} through
  1598. the second conditional test.  The source code for this pass is in
  1599. @file{jump.c}.  This optimization is only performed if
  1600. @samp{-fthread-jumps} is enabled.
  1601.  
  1602. @cindex common subexpression elimination
  1603. @cindex constant propagation
  1604. @item
  1605. Common subexpression elimination.  This pass also does constant
  1606. propagation.  Its source file is @file{cse.c}.  If constant
  1607. propagation causes conditional jumps to become unconditional or to
  1608. become no-ops, jump optimization is run again when CSE is finished.
  1609.  
  1610. The option @samp{-ds} causes a debugging dump of the RTL code after
  1611. this pass.  This dump file's name is made by appending @samp{.cse} to
  1612. the input file name.
  1613.  
  1614. @cindex loop optimization
  1615. @cindex code motion
  1616. @cindex strength-reduction
  1617. @item
  1618. Loop optimization.  This pass moves constant expressions out of loops,
  1619. and optionally does strength-reduction and loop unrolling as well.
  1620. Its source files are @file{loop.c} and @file{unroll.c}, plus the header
  1621. @file{loop.h} used for communication between them.  Loop unrolling uses
  1622. some functions in @file{integrate.c} and the header @file{integrate.h}.
  1623.  
  1624. The option @samp{-dL} causes a debugging dump of the RTL code after
  1625. this pass.  This dump file's name is made by appending @samp{.loop} to
  1626. the input file name.
  1627.  
  1628. @item
  1629. If @samp{-frerun-cse-after-loop} was enabled, a second common
  1630. subexpression elimination pass is performed after the loop optimization
  1631. pass.  Jump threading is also done again at this time if it was specified.
  1632.  
  1633. The option @samp{-dt} causes a debugging dump of the RTL code after
  1634. this pass.  This dump file's name is made by appending @samp{.cse2} to
  1635. the input file name.
  1636.  
  1637. @cindex register allocation, stupid
  1638. @cindex stupid register allocation
  1639. @item
  1640. Stupid register allocation is performed at this point in a
  1641. nonoptimizing compilation.  It does a little data flow analysis as
  1642. well.  When stupid register allocation is in use, the next pass
  1643. executed is the reloading pass; the others in between are skipped.
  1644. The source file is @file{stupid.c}.
  1645.  
  1646. @cindex data flow analysis
  1647. @cindex analysis, data flow
  1648. @cindex basic blocks
  1649. @item
  1650. Data flow analysis (@file{flow.c}).  This pass divides the program
  1651. into basic blocks (and in the process deletes unreachable loops); then
  1652. it computes which pseudo-registers are live at each point in the
  1653. program, and makes the first instruction that uses a value point at
  1654. the instruction that computed the value.
  1655.  
  1656. @cindex autoincrement/decrement analysis
  1657. This pass also deletes computations whose results are never used, and
  1658. combines memory references with add or subtract instructions to make
  1659. autoincrement or autodecrement addressing.
  1660.  
  1661. The option @samp{-df} causes a debugging dump of the RTL code after
  1662. this pass.  This dump file's name is made by appending @samp{.flow} to
  1663. the input file name.  If stupid register allocation is in use, this
  1664. dump file reflects the full results of such allocation.
  1665.  
  1666. @cindex instruction combination
  1667. @item
  1668. Instruction combination (@file{combine.c}).  This pass attempts to
  1669. combine groups of two or three instructions that are related by data
  1670. flow into single instructions.  It combines the RTL expressions for
  1671. the instructions by substitution, simplifies the result using algebra,
  1672. and then attempts to match the result against the machine description.
  1673.  
  1674. The option @samp{-dc} causes a debugging dump of the RTL code after
  1675. this pass.  This dump file's name is made by appending @samp{.combine}
  1676. to the input file name.
  1677.  
  1678. @cindex instruction scheduling
  1679. @cindex scheduling, instruction
  1680. @item
  1681. Instruction scheduling (@file{sched.c}).  This pass looks for
  1682. instructions whose output will not be available by the time that it is
  1683. used in subsequent instructions.  (Memory loads and floating point
  1684. instructions often have this behavior on RISC machines).  It re-orders
  1685. instructions within a basic block to try to separate the definition and
  1686. use of items that otherwise would cause pipeline stalls.
  1687.  
  1688. Instruction scheduling is performed twice.  The first time is immediately
  1689. after instruction combination and the second is immediately after reload.
  1690.  
  1691. The option @samp{-dS} causes a debugging dump of the RTL code after this
  1692. pass is run for the first time.  The dump file's name is made by
  1693. appending @samp{.sched} to the input file name.
  1694.  
  1695. @cindex register class preference pass
  1696. @item
  1697. Register class preferencing.  The RTL code is scanned to find out
  1698. which register class is best for each pseudo register.  The source
  1699. file is @file{regclass.c}.
  1700.  
  1701. @cindex register allocation
  1702. @cindex local register allocation
  1703. @item
  1704. Local register allocation (@file{local-alloc.c}).  This pass allocates
  1705. hard registers to pseudo registers that are used only within one basic
  1706. block.  Because the basic block is linear, it can use fast and
  1707. powerful techniques to do a very good job.
  1708.  
  1709. The option @samp{-dl} causes a debugging dump of the RTL code after
  1710. this pass.  This dump file's name is made by appending @samp{.lreg} to
  1711. the input file name.
  1712.  
  1713. @cindex global register allocation
  1714. @item
  1715. Global register allocation (@file{global-alloc.c}).  This pass
  1716. allocates hard registers for the remaining pseudo registers (those
  1717. whose life spans are not contained in one basic block).
  1718.  
  1719. @cindex reloading
  1720. @item
  1721. Reloading.  This pass renumbers pseudo registers with the hardware
  1722. registers numbers they were allocated.  Pseudo registers that did not
  1723. get hard registers are replaced with stack slots.  Then it finds
  1724. instructions that are invalid because a value has failed to end up in
  1725. a register, or has ended up in a register of the wrong kind.  It fixes
  1726. up these instructions by reloading the problematical values
  1727. temporarily into registers.  Additional instructions are generated to
  1728. do the copying.
  1729.  
  1730. The reload pass also optionally eliminates the frame pointer and inserts
  1731. instructions to save and restore call-clobbered registers around calls.
  1732.  
  1733. Source files are @file{reload.c} and @file{reload1.c}, plus the header
  1734. @file{reload.h} used for communication between them.
  1735.  
  1736. The option @samp{-dg} causes a debugging dump of the RTL code after
  1737. this pass.  This dump file's name is made by appending @samp{.greg} to
  1738. the input file name.
  1739.  
  1740. @cindex instruction scheduling
  1741. @cindex scheduling, instruction
  1742. @item
  1743. Instruction scheduling is repeated here to try to avoid pipeline stalls
  1744. due to memory loads generated for spilled pseudo registers.
  1745.  
  1746. The option @samp{-dR} causes a debugging dump of the RTL code after
  1747. this pass.  This dump file's name is made by appending @samp{.sched2}
  1748. to the input file name.
  1749.  
  1750. @cindex cross-jumping
  1751. @cindex no-op move instructions
  1752. @item
  1753. Jump optimization is repeated, this time including cross-jumping
  1754. and deletion of no-op move instructions.
  1755.  
  1756. The option @samp{-dJ} causes a debugging dump of the RTL code after
  1757. this pass.  This dump file's name is made by appending @samp{.jump2}
  1758. to the input file name.
  1759.  
  1760. @cindex delayed branch scheduling
  1761. @cindex scheduling, delayed branch
  1762. @item
  1763. Delayed branch scheduling.  This optional pass attempts to find
  1764. instructions that can go into the delay slots of other instructions,
  1765. usually jumps and calls.  The source file name is @file{reorg.c}.  
  1766.  
  1767. The option @samp{-dd} causes a debugging dump of the RTL code after
  1768. this pass.  This dump file's name is made by appending @samp{.dbr}
  1769. to the input file name.
  1770.  
  1771. @cindex register-to-stack conversion
  1772. @item
  1773. Conversion from usage of some hard registers to usage of a register
  1774. stack may be done at this point.  Currently, this is supported only
  1775. for the floating-point registers of the Intel 80387 coprocessor.   The
  1776. source file name is @file{reg-stack.c}.
  1777.  
  1778. The options @samp{-dk} causes a debugging dump of the RTL code after
  1779. this pass.  This dump file's name is made by appending @samp{.stack}
  1780. to the input file name.
  1781.  
  1782. @cindex final pass
  1783. @cindex peephole optimization
  1784. @item
  1785. Final.  This pass outputs the assembler code for the function.  It is
  1786. also responsible for identifying spurious test and compare
  1787. instructions.  Machine-specific peephole optimizations are performed
  1788. at the same time.  The function entry and exit sequences are generated
  1789. directly as assembler code in this pass; they never exist as RTL.
  1790.  
  1791. The source files are @file{final.c} plus @file{insn-output.c}; the
  1792. latter is generated automatically from the machine description by the
  1793. tool @file{genoutput}.  The header file @file{conditions.h} is used
  1794. for communication between these files.
  1795.  
  1796. @cindex debugging information generation
  1797. @item
  1798. Debugging information output.  This is run after final because it must
  1799. output the stack slot offsets for pseudo registers that did not get
  1800. hard registers.  Source files are @file{dbxout.c} for DBX symbol table
  1801. format, @file{sdbout.c} for SDB symbol table format, and
  1802. @file{dwarfout.c} for DWARF symbol table format.
  1803. @end itemize
  1804.  
  1805. Some additional files are used by all or many passes:
  1806.  
  1807. @itemize @bullet
  1808. @item
  1809. Every pass uses @file{machmode.def} and @file{machmode.h} which define
  1810. the machine modes.
  1811.  
  1812. @item
  1813. Several passes use @file{real.h}, which defines the default
  1814. representation of floating point constants and how to operate on them.
  1815.  
  1816. @item
  1817. All the passes that work with RTL use the header files @file{rtl.h}
  1818. and @file{rtl.def}, and subroutines in file @file{rtl.c}.  The tools
  1819. @code{gen*} also use these files to read and work with the machine
  1820. description RTL.
  1821.  
  1822. @findex genconfig
  1823. @item
  1824. Several passes refer to the header file @file{insn-config.h} which
  1825. contains a few parameters (C macro definitions) generated
  1826. automatically from the machine description RTL by the tool
  1827. @code{genconfig}.
  1828.  
  1829. @cindex instruction recognizer
  1830. @item
  1831. Several passes use the instruction recognizer, which consists of
  1832. @file{recog.c} and @file{recog.h}, plus the files @file{insn-recog.c}
  1833. and @file{insn-extract.c} that are generated automatically from the
  1834. machine description by the tools @file{genrecog} and
  1835. @file{genextract}.@refill
  1836.  
  1837. @item
  1838. Several passes use the header files @file{regs.h} which defines the
  1839. information recorded about pseudo register usage, and @file{basic-block.h}
  1840. which defines the information recorded about basic blocks.
  1841.  
  1842. @item
  1843. @file{hard-reg-set.h} defines the type @code{HARD_REG_SET}, a bit-vector
  1844. with a bit for each hard register, and some macros to manipulate it.
  1845. This type is just @code{int} if the machine has few enough hard registers;
  1846. otherwise it is an array of @code{int} and some of the macros expand
  1847. into loops.
  1848.  
  1849. @item
  1850. Several passes use instruction attributes.  A definition of the
  1851. attributes defined for a particular machine is in file
  1852. @file{insn-attr.h}, which is generated from the machine description by
  1853. the program @file{genattr}.  The file @file{insn-attrtab.c} contains
  1854. subroutines to obtain the attribute values for insns.  It is generated
  1855. from the machine description by the program @file{genattrtab}.@refill
  1856. @end itemize
  1857. @end ifset
  1858.  
  1859. @include rtl.texi
  1860. @include md.texi
  1861. @include tm.texi
  1862.  
  1863. @ifset INTERNALS
  1864. @node Config
  1865. @chapter The Configuration File
  1866. @cindex configuration file
  1867. @cindex @file{xm-@var{machine}.h}
  1868.  
  1869. The configuration file @file{xm-@var{machine}.h} contains macro
  1870. definitions that describe the machine and system on which the compiler
  1871. is running, unlike the definitions in @file{@var{machine}.h}, which
  1872. describe the machine for which the compiler is producing output.  Most
  1873. of the values in @file{xm-@var{machine}.h} are actually the same on all
  1874. machines that GNU CC runs on, so large parts of all configuration files
  1875. are identical.  But there are some macros that vary:
  1876.  
  1877. @table @code
  1878. @findex USG
  1879. @item USG
  1880. Define this macro if the host system is System V.
  1881.  
  1882. @findex VMS
  1883. @item VMS
  1884. Define this macro if the host system is VMS.
  1885.  
  1886. @findex FAILURE_EXIT_CODE
  1887. @item FAILURE_EXIT_CODE
  1888. A C expression for the status code to be returned when the compiler
  1889. exits after serious errors.
  1890.  
  1891. @findex SUCCESS_EXIT_CODE
  1892. @item SUCCESS_EXIT_CODE
  1893. A C expression for the status code to be returned when the compiler
  1894. exits without serious errors.
  1895.  
  1896. @findex HOST_WORDS_BIG_ENDIAN
  1897. @item HOST_WORDS_BIG_ENDIAN
  1898. Defined if the host machine stores words of multi-word values in
  1899. big-endian order.  (GNU CC does not depend on the host byte ordering
  1900. within a word.)
  1901.  
  1902. @findex HOST_FLOAT_FORMAT
  1903. @item HOST_FLOAT_FORMAT
  1904. A numeric code distinguishing the floating point format for the host
  1905. machine.  See @code{TARGET_FLOAT_FORMAT} in @ref{Storage Layout} for the
  1906. alternatives and default.
  1907.  
  1908. @findex HOST_BITS_PER_CHAR
  1909. @item HOST_BITS_PER_CHAR
  1910. A C expression for the number of bits in @code{char} on the host
  1911. machine.
  1912.  
  1913. @findex HOST_BITS_PER_SHORT
  1914. @item HOST_BITS_PER_SHORT
  1915. A C expression for the number of bits in @code{short} on the host
  1916. machine.
  1917.  
  1918. @findex HOST_BITS_PER_INT
  1919. @item HOST_BITS_PER_INT
  1920. A C expression for the number of bits in @code{int} on the host
  1921. machine.
  1922.  
  1923. @findex HOST_BITS_PER_LONG
  1924. @item HOST_BITS_PER_LONG
  1925. A C expression for the number of bits in @code{long} on the host
  1926. machine.
  1927.  
  1928. @findex ONLY_INT_FIELDS
  1929. @item ONLY_INT_FIELDS
  1930. Define this macro to indicate that the host compiler only supports
  1931. @code{int} bit fields, rather than other integral types, including
  1932. @code{enum}, as do most C compilers.
  1933.  
  1934. @findex EXECUTABLE_SUFFIX
  1935. @item EXECUTABLE_SUFFIX
  1936. Define this macro if the host system uses a naming convention for
  1937. executable files that involves a common suffix (such as, in some
  1938. systems, @samp{.exe}) that must be mentioned explicitly when you run
  1939. the program.
  1940.  
  1941. @findex OBSTACK_CHUNK_SIZE
  1942. @item OBSTACK_CHUNK_SIZE
  1943. A C expression for the size of ordinary obstack chunks.
  1944. If you don't define this, a usually-reasonable default is used.
  1945.  
  1946. @findex OBSTACK_CHUNK_ALLOC
  1947. @item OBSTACK_CHUNK_ALLOC
  1948. The function used to allocate obstack chunks.
  1949. If you don't define this, @code{xmalloc} is used.
  1950.  
  1951. @findex OBSTACK_CHUNK_FREE
  1952. @item OBSTACK_CHUNK_FREE
  1953. The function used to free obstack chunks.
  1954. If you don't define this, @code{free} is used.
  1955.  
  1956. @findex USE_C_ALLOCA
  1957. @item USE_C_ALLOCA
  1958. Define this macro to indicate that the compiler is running with the
  1959. @code{alloca} implemented in C.  This version of @code{alloca} can be
  1960. found in the file @file{alloca.c}; to use it, you must also alter the
  1961. @file{Makefile} variable @code{ALLOCA}.  (This is done automatically
  1962. for the systems on which we know it is needed.)
  1963.  
  1964. If you do define this macro, you should probably do it as follows:
  1965.  
  1966. @example
  1967. #ifndef __GNUC__
  1968. #define USE_C_ALLOCA
  1969. #else
  1970. #define alloca __builtin_alloca
  1971. #endif
  1972. @end example
  1973.  
  1974. @noindent
  1975. so that when the compiler is compiled with GNU CC it uses the more
  1976. efficient built-in @code{alloca} function.
  1977.  
  1978. @item FUNCTION_CONVERSION_BUG
  1979. @findex FUNCTION_CONVERSION_BUG
  1980. Define this macro to indicate that the host compiler does not properly
  1981. handle converting a function value to a pointer-to-function when it is
  1982. used in an expression.
  1983.  
  1984. @findex HAVE_VPRINTF
  1985. @findex vprintf
  1986. @item HAVE_VPRINTF
  1987. Define this if the library function @code{vprintf} is available on your
  1988. system.
  1989.  
  1990. @findex MULTIBYTE_CHARS
  1991. @item MULTIBYTE_CHARS
  1992. Define this macro to enable support for multibyte characters in the
  1993. input to GNU CC.  This requires that the host system support the ANSI C
  1994. library functions for converting multibyte characters to wide
  1995. characters.
  1996.  
  1997. @findex HAVE_PUTENV
  1998. @findex putenv
  1999. @item HAVE_PUTENV
  2000. Define this if the library function @code{putenv} is available on your
  2001. system.
  2002.  
  2003. @findex NO_SYS_SIGLIST
  2004. @item NO_SYS_SIGLIST
  2005. Define this if your system @emph{does not} provide the variable
  2006. @code{sys_siglist}.
  2007.  
  2008. @vindex sys_siglist
  2009. Some systems do provide this variable, but with a different name such
  2010. as @code{_sys_siglist}.  On these systems, you can define
  2011. @code{sys_siglist} as a macro which expands into the name actually
  2012. provided.
  2013.  
  2014. @findex NO_STAB_H
  2015. @item NO_STAB_H
  2016. Define this if your system does not have the include file
  2017. @file{stab.h}.  If @samp{USG} is defined, @samp{NO_STAB_H} is
  2018. assumed.
  2019. @end table
  2020.  
  2021. @findex bzero
  2022. @findex bcmp
  2023. In addition, configuration files for system V define @code{bcopy},
  2024. @code{bzero} and @code{bcmp} as aliases.  Some files define @code{alloca}
  2025. as a macro when compiled with GNU CC, in order to take advantage of the
  2026. benefit of GNU CC's built-in @code{alloca}.
  2027.  
  2028.  
  2029. @node Index
  2030. @unnumbered Index
  2031. @end ifset
  2032.  
  2033. @ifclear INTERNALS
  2034. @node Index
  2035. @unnumbered Index
  2036. @end ifclear
  2037.  
  2038. @printindex cp
  2039. @contents
  2040. @bye
  2041.