]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/doc/sourcebuild.texi
Update copyright years in gcc/
[thirdparty/gcc.git] / gcc / doc / sourcebuild.texi
1 @c Copyright (C) 2002-2014 Free Software Foundation, Inc.
2 @c This is part of the GCC manual.
3 @c For copying conditions, see the file gcc.texi.
4
5 @node Source Tree
6 @chapter Source Tree Structure and Build System
7
8 This chapter describes the structure of the GCC source tree, and how
9 GCC is built. The user documentation for building and installing GCC
10 is in a separate manual (@uref{http://gcc.gnu.org/install/}), with
11 which it is presumed that you are familiar.
12
13 @menu
14 * Configure Terms:: Configuration terminology and history.
15 * Top Level:: The top level source directory.
16 * gcc Directory:: The @file{gcc} subdirectory.
17 @end menu
18
19 @include configterms.texi
20
21 @node Top Level
22 @section Top Level Source Directory
23
24 The top level source directory in a GCC distribution contains several
25 files and directories that are shared with other software
26 distributions such as that of GNU Binutils. It also contains several
27 subdirectories that contain parts of GCC and its runtime libraries:
28
29 @table @file
30 @item boehm-gc
31 The Boehm conservative garbage collector, used as part of the Java
32 runtime library.
33
34 @item config
35 Autoconf macros and Makefile fragments used throughout the tree.
36
37 @item contrib
38 Contributed scripts that may be found useful in conjunction with GCC@.
39 One of these, @file{contrib/texi2pod.pl}, is used to generate man
40 pages from Texinfo manuals as part of the GCC build process.
41
42 @item fixincludes
43 The support for fixing system headers to work with GCC@. See
44 @file{fixincludes/README} for more information. The headers fixed by
45 this mechanism are installed in @file{@var{libsubdir}/include-fixed}.
46 Along with those headers, @file{README-fixinc} is also installed, as
47 @file{@var{libsubdir}/include-fixed/README}.
48
49 @item gcc
50 The main sources of GCC itself (except for runtime libraries),
51 including optimizers, support for different target architectures,
52 language front ends, and testsuites. @xref{gcc Directory, , The
53 @file{gcc} Subdirectory}, for details.
54
55 @item gnattools
56 Support tools for GNAT.
57
58 @item include
59 Headers for the @code{libiberty} library.
60
61 @item intl
62 GNU @code{libintl}, from GNU @code{gettext}, for systems which do not
63 include it in @code{libc}.
64
65 @item libada
66 The Ada runtime library.
67
68 @item libatomic
69 The runtime support library for atomic operations (e.g. for @code{__sync}
70 and @code{__atomic}).
71
72 @item libcpp
73 The C preprocessor library.
74
75 @item libdecnumber
76 The Decimal Float support library.
77
78 @item libffi
79 The @code{libffi} library, used as part of the Java runtime library.
80
81 @item libgcc
82 The GCC runtime library.
83
84 @item libgfortran
85 The Fortran runtime library.
86
87 @item libgo
88 The Go runtime library. The bulk of this library is mirrored from the
89 @uref{http://code.google.com/@/p/@/go/, master Go repository}.
90
91 @item libgomp
92 The GNU OpenMP runtime library.
93
94 @item libiberty
95 The @code{libiberty} library, used for portability and for some
96 generally useful data structures and algorithms. @xref{Top, ,
97 Introduction, libiberty, @sc{gnu} libiberty}, for more information
98 about this library.
99
100 @item libitm
101 The runtime support library for transactional memory.
102
103 @item libjava
104 The Java runtime library.
105
106 @item libobjc
107 The Objective-C and Objective-C++ runtime library.
108
109 @item libquadmath
110 The runtime support library for quad-precision math operations.
111
112 @item libssp
113 The Stack protector runtime library.
114
115 @item libstdc++-v3
116 The C++ runtime library.
117
118 @item lto-plugin
119 Plugin used by the linker if link-time optimizations are enabled.
120
121 @item maintainer-scripts
122 Scripts used by the @code{gccadmin} account on @code{gcc.gnu.org}.
123
124 @item zlib
125 The @code{zlib} compression library, used by the Java front end, as
126 part of the Java runtime library, and for compressing and uncompressing
127 GCC's intermediate language in LTO object files.
128 @end table
129
130 The build system in the top level directory, including how recursion
131 into subdirectories works and how building runtime libraries for
132 multilibs is handled, is documented in a separate manual, included
133 with GNU Binutils. @xref{Top, , GNU configure and build system,
134 configure, The GNU configure and build system}, for details.
135
136 @node gcc Directory
137 @section The @file{gcc} Subdirectory
138
139 The @file{gcc} directory contains many files that are part of the C
140 sources of GCC, other files used as part of the configuration and
141 build process, and subdirectories including documentation and a
142 testsuite. The files that are sources of GCC are documented in a
143 separate chapter. @xref{Passes, , Passes and Files of the Compiler}.
144
145 @menu
146 * Subdirectories:: Subdirectories of @file{gcc}.
147 * Configuration:: The configuration process, and the files it uses.
148 * Build:: The build system in the @file{gcc} directory.
149 * Makefile:: Targets in @file{gcc/Makefile}.
150 * Library Files:: Library source files and headers under @file{gcc/}.
151 * Headers:: Headers installed by GCC.
152 * Documentation:: Building documentation in GCC.
153 * Front End:: Anatomy of a language front end.
154 * Back End:: Anatomy of a target back end.
155 @end menu
156
157 @node Subdirectories
158 @subsection Subdirectories of @file{gcc}
159
160 The @file{gcc} directory contains the following subdirectories:
161
162 @table @file
163 @item @var{language}
164 Subdirectories for various languages. Directories containing a file
165 @file{config-lang.in} are language subdirectories. The contents of
166 the subdirectories @file{c} (for C), @file{cp} (for C++),
167 @file{objc} (for Objective-C), @file{objcp} (for Objective-C++),
168 and @file{lto} (for LTO) are documented in this
169 manual (@pxref{Passes, , Passes and Files of the Compiler});
170 those for other languages are not. @xref{Front End, ,
171 Anatomy of a Language Front End}, for details of the files in these
172 directories.
173
174 @item common
175 Source files shared between the compiler drivers (such as
176 @command{gcc}) and the compilers proper (such as @file{cc1}). If an
177 architecture defines target hooks shared between those places, it also
178 has a subdirectory in @file{common/config}. @xref{Target Structure}.
179
180 @item config
181 Configuration files for supported architectures and operating
182 systems. @xref{Back End, , Anatomy of a Target Back End}, for
183 details of the files in this directory.
184
185 @item doc
186 Texinfo documentation for GCC, together with automatically generated
187 man pages and support for converting the installation manual to
188 HTML@. @xref{Documentation}.
189
190 @item ginclude
191 System headers installed by GCC, mainly those required by the C
192 standard of freestanding implementations. @xref{Headers, , Headers
193 Installed by GCC}, for details of when these and other headers are
194 installed.
195
196 @item po
197 Message catalogs with translations of messages produced by GCC into
198 various languages, @file{@var{language}.po}. This directory also
199 contains @file{gcc.pot}, the template for these message catalogues,
200 @file{exgettext}, a wrapper around @command{gettext} to extract the
201 messages from the GCC sources and create @file{gcc.pot}, which is run
202 by @samp{make gcc.pot}, and @file{EXCLUDES}, a list of files from
203 which messages should not be extracted.
204
205 @item testsuite
206 The GCC testsuites (except for those for runtime libraries).
207 @xref{Testsuites}.
208 @end table
209
210 @node Configuration
211 @subsection Configuration in the @file{gcc} Directory
212
213 The @file{gcc} directory is configured with an Autoconf-generated
214 script @file{configure}. The @file{configure} script is generated
215 from @file{configure.ac} and @file{aclocal.m4}. From the files
216 @file{configure.ac} and @file{acconfig.h}, Autoheader generates the
217 file @file{config.in}. The file @file{cstamp-h.in} is used as a
218 timestamp.
219
220 @menu
221 * Config Fragments:: Scripts used by @file{configure}.
222 * System Config:: The @file{config.build}, @file{config.host}, and
223 @file{config.gcc} files.
224 * Configuration Files:: Files created by running @file{configure}.
225 @end menu
226
227 @node Config Fragments
228 @subsubsection Scripts Used by @file{configure}
229
230 @file{configure} uses some other scripts to help in its work:
231
232 @itemize @bullet
233 @item The standard GNU @file{config.sub} and @file{config.guess}
234 files, kept in the top level directory, are used.
235
236 @item The file @file{config.gcc} is used to handle configuration
237 specific to the particular target machine. The file
238 @file{config.build} is used to handle configuration specific to the
239 particular build machine. The file @file{config.host} is used to handle
240 configuration specific to the particular host machine. (In general,
241 these should only be used for features that cannot reasonably be tested in
242 Autoconf feature tests.)
243 @xref{System Config, , The @file{config.build}; @file{config.host};
244 and @file{config.gcc} Files}, for details of the contents of these files.
245
246 @item Each language subdirectory has a file
247 @file{@var{language}/config-lang.in} that is used for
248 front-end-specific configuration. @xref{Front End Config, , The Front
249 End @file{config-lang.in} File}, for details of this file.
250
251 @item A helper script @file{configure.frag} is used as part of
252 creating the output of @file{configure}.
253 @end itemize
254
255 @node System Config
256 @subsubsection The @file{config.build}; @file{config.host}; and @file{config.gcc} Files
257
258 The @file{config.build} file contains specific rules for particular systems
259 which GCC is built on. This should be used as rarely as possible, as the
260 behavior of the build system can always be detected by autoconf.
261
262 The @file{config.host} file contains specific rules for particular systems
263 which GCC will run on. This is rarely needed.
264
265 The @file{config.gcc} file contains specific rules for particular systems
266 which GCC will generate code for. This is usually needed.
267
268 Each file has a list of the shell variables it sets, with descriptions, at the
269 top of the file.
270
271 FIXME: document the contents of these files, and what variables should
272 be set to control build, host and target configuration.
273
274 @include configfiles.texi
275
276 @node Build
277 @subsection Build System in the @file{gcc} Directory
278
279 FIXME: describe the build system, including what is built in what
280 stages. Also list the various source files that are used in the build
281 process but aren't source files of GCC itself and so aren't documented
282 below (@pxref{Passes}).
283
284 @include makefile.texi
285
286 @node Library Files
287 @subsection Library Source Files and Headers under the @file{gcc} Directory
288
289 FIXME: list here, with explanation, all the C source files and headers
290 under the @file{gcc} directory that aren't built into the GCC
291 executable but rather are part of runtime libraries and object files,
292 such as @file{crtstuff.c} and @file{unwind-dw2.c}. @xref{Headers, ,
293 Headers Installed by GCC}, for more information about the
294 @file{ginclude} directory.
295
296 @node Headers
297 @subsection Headers Installed by GCC
298
299 In general, GCC expects the system C library to provide most of the
300 headers to be used with it. However, GCC will fix those headers if
301 necessary to make them work with GCC, and will install some headers
302 required of freestanding implementations. These headers are installed
303 in @file{@var{libsubdir}/include}. Headers for non-C runtime
304 libraries are also installed by GCC; these are not documented here.
305 (FIXME: document them somewhere.)
306
307 Several of the headers GCC installs are in the @file{ginclude}
308 directory. These headers, @file{iso646.h},
309 @file{stdarg.h}, @file{stdbool.h}, and @file{stddef.h},
310 are installed in @file{@var{libsubdir}/include},
311 unless the target Makefile fragment (@pxref{Target Fragment})
312 overrides this by setting @code{USER_H}.
313
314 In addition to these headers and those generated by fixing system
315 headers to work with GCC, some other headers may also be installed in
316 @file{@var{libsubdir}/include}. @file{config.gcc} may set
317 @code{extra_headers}; this specifies additional headers under
318 @file{config} to be installed on some systems.
319
320 GCC installs its own version of @code{<float.h>}, from @file{ginclude/float.h}.
321 This is done to cope with command-line options that change the
322 representation of floating point numbers.
323
324 GCC also installs its own version of @code{<limits.h>}; this is generated
325 from @file{glimits.h}, together with @file{limitx.h} and
326 @file{limity.h} if the system also has its own version of
327 @code{<limits.h>}. (GCC provides its own header because it is
328 required of ISO C freestanding implementations, but needs to include
329 the system header from its own header as well because other standards
330 such as POSIX specify additional values to be defined in
331 @code{<limits.h>}.) The system's @code{<limits.h>} header is used via
332 @file{@var{libsubdir}/include/syslimits.h}, which is copied from
333 @file{gsyslimits.h} if it does not need fixing to work with GCC; if it
334 needs fixing, @file{syslimits.h} is the fixed copy.
335
336 GCC can also install @code{<tgmath.h>}. It will do this when
337 @file{config.gcc} sets @code{use_gcc_tgmath} to @code{yes}.
338
339 @node Documentation
340 @subsection Building Documentation
341
342 The main GCC documentation is in the form of manuals in Texinfo
343 format. These are installed in Info format; DVI versions may be
344 generated by @samp{make dvi}, PDF versions by @samp{make pdf}, and
345 HTML versions by @samp{make html}. In addition, some man pages are
346 generated from the Texinfo manuals, there are some other text files
347 with miscellaneous documentation, and runtime libraries have their own
348 documentation outside the @file{gcc} directory. FIXME: document the
349 documentation for runtime libraries somewhere.
350
351 @menu
352 * Texinfo Manuals:: GCC manuals in Texinfo format.
353 * Man Page Generation:: Generating man pages from Texinfo manuals.
354 * Miscellaneous Docs:: Miscellaneous text files with documentation.
355 @end menu
356
357 @node Texinfo Manuals
358 @subsubsection Texinfo Manuals
359
360 The manuals for GCC as a whole, and the C and C++ front ends, are in
361 files @file{doc/*.texi}. Other front ends have their own manuals in
362 files @file{@var{language}/*.texi}. Common files
363 @file{doc/include/*.texi} are provided which may be included in
364 multiple manuals; the following files are in @file{doc/include}:
365
366 @table @file
367 @item fdl.texi
368 The GNU Free Documentation License.
369 @item funding.texi
370 The section ``Funding Free Software''.
371 @item gcc-common.texi
372 Common definitions for manuals.
373 @item gpl_v3.texi
374 The GNU General Public License.
375 @item texinfo.tex
376 A copy of @file{texinfo.tex} known to work with the GCC manuals.
377 @end table
378
379 DVI-formatted manuals are generated by @samp{make dvi}, which uses
380 @command{texi2dvi} (via the Makefile macro @code{$(TEXI2DVI)}).
381 PDF-formatted manuals are generated by @samp{make pdf}, which uses
382 @command{texi2pdf} (via the Makefile macro @code{$(TEXI2PDF)}). HTML
383 formatted manuals are generated by @samp{make html}. Info
384 manuals are generated by @samp{make info} (which is run as part of
385 a bootstrap); this generates the manuals in the source directory,
386 using @command{makeinfo} via the Makefile macro @code{$(MAKEINFO)},
387 and they are included in release distributions.
388
389 Manuals are also provided on the GCC web site, in both HTML and
390 PostScript forms. This is done via the script
391 @file{maintainer-scripts/update_web_docs_svn}. Each manual to be
392 provided online must be listed in the definition of @code{MANUALS} in
393 that file; a file @file{@var{name}.texi} must only appear once in the
394 source tree, and the output manual must have the same name as the
395 source file. (However, other Texinfo files, included in manuals but
396 not themselves the root files of manuals, may have names that appear
397 more than once in the source tree.) The manual file
398 @file{@var{name}.texi} should only include other files in its own
399 directory or in @file{doc/include}. HTML manuals will be generated by
400 @samp{makeinfo --html}, PostScript manuals by @command{texi2dvi}
401 and @command{dvips}, and PDF manuals by @command{texi2pdf}.
402 All Texinfo files that are parts of manuals must
403 be version-controlled, even if they are generated files, for the
404 generation of online manuals to work.
405
406 The installation manual, @file{doc/install.texi}, is also provided on
407 the GCC web site. The HTML version is generated by the script
408 @file{doc/install.texi2html}.
409
410 @node Man Page Generation
411 @subsubsection Man Page Generation
412
413 Because of user demand, in addition to full Texinfo manuals, man pages
414 are provided which contain extracts from those manuals. These man
415 pages are generated from the Texinfo manuals using
416 @file{contrib/texi2pod.pl} and @command{pod2man}. (The man page for
417 @command{g++}, @file{cp/g++.1}, just contains a @samp{.so} reference
418 to @file{gcc.1}, but all the other man pages are generated from
419 Texinfo manuals.)
420
421 Because many systems may not have the necessary tools installed to
422 generate the man pages, they are only generated if the
423 @file{configure} script detects that recent enough tools are
424 installed, and the Makefiles allow generating man pages to fail
425 without aborting the build. Man pages are also included in release
426 distributions. They are generated in the source directory.
427
428 Magic comments in Texinfo files starting @samp{@@c man} control what
429 parts of a Texinfo file go into a man page. Only a subset of Texinfo
430 is supported by @file{texi2pod.pl}, and it may be necessary to add
431 support for more Texinfo features to this script when generating new
432 man pages. To improve the man page output, some special Texinfo
433 macros are provided in @file{doc/include/gcc-common.texi} which
434 @file{texi2pod.pl} understands:
435
436 @table @code
437 @item @@gcctabopt
438 Use in the form @samp{@@table @@gcctabopt} for tables of options,
439 where for printed output the effect of @samp{@@code} is better than
440 that of @samp{@@option} but for man page output a different effect is
441 wanted.
442 @item @@gccoptlist
443 Use for summary lists of options in manuals.
444 @item @@gol
445 Use at the end of each line inside @samp{@@gccoptlist}. This is
446 necessary to avoid problems with differences in how the
447 @samp{@@gccoptlist} macro is handled by different Texinfo formatters.
448 @end table
449
450 FIXME: describe the @file{texi2pod.pl} input language and magic
451 comments in more detail.
452
453 @node Miscellaneous Docs
454 @subsubsection Miscellaneous Documentation
455
456 In addition to the formal documentation that is installed by GCC,
457 there are several other text files in the @file{gcc} subdirectory
458 with miscellaneous documentation:
459
460 @table @file
461 @item ABOUT-GCC-NLS
462 Notes on GCC's Native Language Support. FIXME: this should be part of
463 this manual rather than a separate file.
464 @item ABOUT-NLS
465 Notes on the Free Translation Project.
466 @item COPYING
467 @itemx COPYING3
468 The GNU General Public License, Versions 2 and 3.
469 @item COPYING.LIB
470 @itemx COPYING3.LIB
471 The GNU Lesser General Public License, Versions 2.1 and 3.
472 @item *ChangeLog*
473 @itemx */ChangeLog*
474 Change log files for various parts of GCC@.
475 @item LANGUAGES
476 Details of a few changes to the GCC front-end interface. FIXME: the
477 information in this file should be part of general documentation of
478 the front-end interface in this manual.
479 @item ONEWS
480 Information about new features in old versions of GCC@. (For recent
481 versions, the information is on the GCC web site.)
482 @item README.Portability
483 Information about portability issues when writing code in GCC@. FIXME:
484 why isn't this part of this manual or of the GCC Coding Conventions?
485 @end table
486
487 FIXME: document such files in subdirectories, at least @file{config},
488 @file{c}, @file{cp}, @file{objc}, @file{testsuite}.
489
490 @node Front End
491 @subsection Anatomy of a Language Front End
492
493 A front end for a language in GCC has the following parts:
494
495 @itemize @bullet
496 @item
497 A directory @file{@var{language}} under @file{gcc} containing source
498 files for that front end. @xref{Front End Directory, , The Front End
499 @file{@var{language}} Directory}, for details.
500 @item
501 A mention of the language in the list of supported languages in
502 @file{gcc/doc/install.texi}.
503 @item
504 A mention of the name under which the language's runtime library is
505 recognized by @option{--enable-shared=@var{package}} in the
506 documentation of that option in @file{gcc/doc/install.texi}.
507 @item
508 A mention of any special prerequisites for building the front end in
509 the documentation of prerequisites in @file{gcc/doc/install.texi}.
510 @item
511 Details of contributors to that front end in
512 @file{gcc/doc/contrib.texi}. If the details are in that front end's
513 own manual then there should be a link to that manual's list in
514 @file{contrib.texi}.
515 @item
516 Information about support for that language in
517 @file{gcc/doc/frontends.texi}.
518 @item
519 Information about standards for that language, and the front end's
520 support for them, in @file{gcc/doc/standards.texi}. This may be a
521 link to such information in the front end's own manual.
522 @item
523 Details of source file suffixes for that language and @option{-x
524 @var{lang}} options supported, in @file{gcc/doc/invoke.texi}.
525 @item
526 Entries in @code{default_compilers} in @file{gcc.c} for source file
527 suffixes for that language.
528 @item
529 Preferably testsuites, which may be under @file{gcc/testsuite} or
530 runtime library directories. FIXME: document somewhere how to write
531 testsuite harnesses.
532 @item
533 Probably a runtime library for the language, outside the @file{gcc}
534 directory. FIXME: document this further.
535 @item
536 Details of the directories of any runtime libraries in
537 @file{gcc/doc/sourcebuild.texi}.
538 @item
539 Check targets in @file{Makefile.def} for the top-level @file{Makefile}
540 to check just the compiler or the compiler and runtime library for the
541 language.
542 @end itemize
543
544 If the front end is added to the official GCC source repository, the
545 following are also necessary:
546
547 @itemize @bullet
548 @item
549 At least one Bugzilla component for bugs in that front end and runtime
550 libraries. This category needs to be added to the Bugzilla database.
551 @item
552 Normally, one or more maintainers of that front end listed in
553 @file{MAINTAINERS}.
554 @item
555 Mentions on the GCC web site in @file{index.html} and
556 @file{frontends.html}, with any relevant links on
557 @file{readings.html}. (Front ends that are not an official part of
558 GCC may also be listed on @file{frontends.html}, with relevant links.)
559 @item
560 A news item on @file{index.html}, and possibly an announcement on the
561 @email{gcc-announce@@gcc.gnu.org} mailing list.
562 @item
563 The front end's manuals should be mentioned in
564 @file{maintainer-scripts/update_web_docs_svn} (@pxref{Texinfo Manuals})
565 and the online manuals should be linked to from
566 @file{onlinedocs/index.html}.
567 @item
568 Any old releases or CVS repositories of the front end, before its
569 inclusion in GCC, should be made available on the GCC FTP site
570 @uref{ftp://gcc.gnu.org/pub/gcc/old-releases/}.
571 @item
572 The release and snapshot script @file{maintainer-scripts/gcc_release}
573 should be updated to generate appropriate tarballs for this front end.
574 @item
575 If this front end includes its own version files that include the
576 current date, @file{maintainer-scripts/update_version} should be
577 updated accordingly.
578 @end itemize
579
580 @menu
581 * Front End Directory:: The front end @file{@var{language}} directory.
582 * Front End Config:: The front end @file{config-lang.in} file.
583 * Front End Makefile:: The front end @file{Make-lang.in} file.
584 @end menu
585
586 @node Front End Directory
587 @subsubsection The Front End @file{@var{language}} Directory
588
589 A front end @file{@var{language}} directory contains the source files
590 of that front end (but not of any runtime libraries, which should be
591 outside the @file{gcc} directory). This includes documentation, and
592 possibly some subsidiary programs built alongside the front end.
593 Certain files are special and other parts of the compiler depend on
594 their names:
595
596 @table @file
597 @item config-lang.in
598 This file is required in all language subdirectories. @xref{Front End
599 Config, , The Front End @file{config-lang.in} File}, for details of
600 its contents
601 @item Make-lang.in
602 This file is required in all language subdirectories. @xref{Front End
603 Makefile, , The Front End @file{Make-lang.in} File}, for details of its
604 contents.
605 @item lang.opt
606 This file registers the set of switches that the front end accepts on
607 the command line, and their @option{--help} text. @xref{Options}.
608 @item lang-specs.h
609 This file provides entries for @code{default_compilers} in
610 @file{gcc.c} which override the default of giving an error that a
611 compiler for that language is not installed.
612 @item @var{language}-tree.def
613 This file, which need not exist, defines any language-specific tree
614 codes.
615 @end table
616
617 @node Front End Config
618 @subsubsection The Front End @file{config-lang.in} File
619
620 Each language subdirectory contains a @file{config-lang.in} file.
621 This file is a shell script that may define some variables describing
622 the language:
623
624 @table @code
625 @item language
626 This definition must be present, and gives the name of the language
627 for some purposes such as arguments to @option{--enable-languages}.
628 @item lang_requires
629 If defined, this variable lists (space-separated) language front ends
630 other than C that this front end requires to be enabled (with the
631 names given being their @code{language} settings). For example, the
632 Java front end depends on the C++ front end, so sets
633 @samp{lang_requires=c++}.
634 @item subdir_requires
635 If defined, this variable lists (space-separated) front end directories
636 other than C that this front end requires to be present. For example,
637 the Objective-C++ front end uses source files from the C++ and
638 Objective-C front ends, so sets @samp{subdir_requires="cp objc"}.
639 @item target_libs
640 If defined, this variable lists (space-separated) targets in the top
641 level @file{Makefile} to build the runtime libraries for this
642 language, such as @code{target-libobjc}.
643 @item lang_dirs
644 If defined, this variable lists (space-separated) top level
645 directories (parallel to @file{gcc}), apart from the runtime libraries,
646 that should not be configured if this front end is not built.
647 @item build_by_default
648 If defined to @samp{no}, this language front end is not built unless
649 enabled in a @option{--enable-languages} argument. Otherwise, front
650 ends are built by default, subject to any special logic in
651 @file{configure.ac} (as is present to disable the Ada front end if the
652 Ada compiler is not already installed).
653 @item boot_language
654 If defined to @samp{yes}, this front end is built in stage1 of the
655 bootstrap. This is only relevant to front ends written in their own
656 languages.
657 @item compilers
658 If defined, a space-separated list of compiler executables that will
659 be run by the driver. The names here will each end
660 with @samp{\$(exeext)}.
661 @item outputs
662 If defined, a space-separated list of files that should be generated
663 by @file{configure} substituting values in them. This mechanism can
664 be used to create a file @file{@var{language}/Makefile} from
665 @file{@var{language}/Makefile.in}, but this is deprecated, building
666 everything from the single @file{gcc/Makefile} is preferred.
667 @item gtfiles
668 If defined, a space-separated list of files that should be scanned by
669 @file{gengtype.c} to generate the garbage collection tables and routines for
670 this language. This excludes the files that are common to all front
671 ends. @xref{Type Information}.
672
673 @end table
674
675 @node Front End Makefile
676 @subsubsection The Front End @file{Make-lang.in} File
677
678 Each language subdirectory contains a @file{Make-lang.in} file. It contains
679 targets @code{@var{lang}.@var{hook}} (where @code{@var{lang}} is the
680 setting of @code{language} in @file{config-lang.in}) for the following
681 values of @code{@var{hook}}, and any other Makefile rules required to
682 build those targets (which may if necessary use other Makefiles
683 specified in @code{outputs} in @file{config-lang.in}, although this is
684 deprecated). It also adds any testsuite targets that can use the
685 standard rule in @file{gcc/Makefile.in} to the variable
686 @code{lang_checks}.
687
688 @table @code
689 @item all.cross
690 @itemx start.encap
691 @itemx rest.encap
692 FIXME: exactly what goes in each of these targets?
693 @item tags
694 Build an @command{etags} @file{TAGS} file in the language subdirectory
695 in the source tree.
696 @item info
697 Build info documentation for the front end, in the build directory.
698 This target is only called by @samp{make bootstrap} if a suitable
699 version of @command{makeinfo} is available, so does not need to check
700 for this, and should fail if an error occurs.
701 @item dvi
702 Build DVI documentation for the front end, in the build directory.
703 This should be done using @code{$(TEXI2DVI)}, with appropriate
704 @option{-I} arguments pointing to directories of included files.
705 @item pdf
706 Build PDF documentation for the front end, in the build directory.
707 This should be done using @code{$(TEXI2PDF)}, with appropriate
708 @option{-I} arguments pointing to directories of included files.
709 @item html
710 Build HTML documentation for the front end, in the build directory.
711 @item man
712 Build generated man pages for the front end from Texinfo manuals
713 (@pxref{Man Page Generation}), in the build directory. This target
714 is only called if the necessary tools are available, but should ignore
715 errors so as not to stop the build if errors occur; man pages are
716 optional and the tools involved may be installed in a broken way.
717 @item install-common
718 Install everything that is part of the front end, apart from the
719 compiler executables listed in @code{compilers} in
720 @file{config-lang.in}.
721 @item install-info
722 Install info documentation for the front end, if it is present in the
723 source directory. This target should have dependencies on info files
724 that should be installed.
725 @item install-man
726 Install man pages for the front end. This target should ignore
727 errors.
728 @item install-plugin
729 Install headers needed for plugins.
730 @item srcextra
731 Copies its dependencies into the source directory. This generally should
732 be used for generated files such as Bison output files which are not
733 version-controlled, but should be included in any release tarballs. This
734 target will be executed during a bootstrap if
735 @samp{--enable-generated-files-in-srcdir} was specified as a
736 @file{configure} option.
737 @item srcinfo
738 @itemx srcman
739 Copies its dependencies into the source directory. These targets will be
740 executed during a bootstrap if @samp{--enable-generated-files-in-srcdir}
741 was specified as a @file{configure} option.
742 @item uninstall
743 Uninstall files installed by installing the compiler. This is
744 currently documented not to be supported, so the hook need not do
745 anything.
746 @item mostlyclean
747 @itemx clean
748 @itemx distclean
749 @itemx maintainer-clean
750 The language parts of the standard GNU
751 @samp{*clean} targets. @xref{Standard Targets, , Standard Targets for
752 Users, standards, GNU Coding Standards}, for details of the standard
753 targets. For GCC, @code{maintainer-clean} should delete
754 all generated files in the source directory that are not version-controlled,
755 but should not delete anything that is.
756 @end table
757
758 @file{Make-lang.in} must also define a variable @code{@var{lang}_OBJS}
759 to a list of host object files that are used by that language.
760
761 @node Back End
762 @subsection Anatomy of a Target Back End
763
764 A back end for a target architecture in GCC has the following parts:
765
766 @itemize @bullet
767 @item
768 A directory @file{@var{machine}} under @file{gcc/config}, containing a
769 machine description @file{@var{machine}.md} file (@pxref{Machine Desc,
770 , Machine Descriptions}), header files @file{@var{machine}.h} and
771 @file{@var{machine}-protos.h} and a source file @file{@var{machine}.c}
772 (@pxref{Target Macros, , Target Description Macros and Functions}),
773 possibly a target Makefile fragment @file{t-@var{machine}}
774 (@pxref{Target Fragment, , The Target Makefile Fragment}), and maybe
775 some other files. The names of these files may be changed from the
776 defaults given by explicit specifications in @file{config.gcc}.
777 @item
778 If necessary, a file @file{@var{machine}-modes.def} in the
779 @file{@var{machine}} directory, containing additional machine modes to
780 represent condition codes. @xref{Condition Code}, for further details.
781 @item
782 An optional @file{@var{machine}.opt} file in the @file{@var{machine}}
783 directory, containing a list of target-specific options. You can also
784 add other option files using the @code{extra_options} variable in
785 @file{config.gcc}. @xref{Options}.
786 @item
787 Entries in @file{config.gcc} (@pxref{System Config, , The
788 @file{config.gcc} File}) for the systems with this target
789 architecture.
790 @item
791 Documentation in @file{gcc/doc/invoke.texi} for any command-line
792 options supported by this target (@pxref{Run-time Target, , Run-time
793 Target Specification}). This means both entries in the summary table
794 of options and details of the individual options.
795 @item
796 Documentation in @file{gcc/doc/extend.texi} for any target-specific
797 attributes supported (@pxref{Target Attributes, , Defining
798 target-specific uses of @code{__attribute__}}), including where the
799 same attribute is already supported on some targets, which are
800 enumerated in the manual.
801 @item
802 Documentation in @file{gcc/doc/extend.texi} for any target-specific
803 pragmas supported.
804 @item
805 Documentation in @file{gcc/doc/extend.texi} of any target-specific
806 built-in functions supported.
807 @item
808 Documentation in @file{gcc/doc/extend.texi} of any target-specific
809 format checking styles supported.
810 @item
811 Documentation in @file{gcc/doc/md.texi} of any target-specific
812 constraint letters (@pxref{Machine Constraints, , Constraints for
813 Particular Machines}).
814 @item
815 A note in @file{gcc/doc/contrib.texi} under the person or people who
816 contributed the target support.
817 @item
818 Entries in @file{gcc/doc/install.texi} for all target triplets
819 supported with this target architecture, giving details of any special
820 notes about installation for this target, or saying that there are no
821 special notes if there are none.
822 @item
823 Possibly other support outside the @file{gcc} directory for runtime
824 libraries. FIXME: reference docs for this. The @code{libstdc++} porting
825 manual needs to be installed as info for this to work, or to be a
826 chapter of this manual.
827 @end itemize
828
829 If the back end is added to the official GCC source repository, the
830 following are also necessary:
831
832 @itemize @bullet
833 @item
834 An entry for the target architecture in @file{readings.html} on the
835 GCC web site, with any relevant links.
836 @item
837 Details of the properties of the back end and target architecture in
838 @file{backends.html} on the GCC web site.
839 @item
840 A news item about the contribution of support for that target
841 architecture, in @file{index.html} on the GCC web site.
842 @item
843 Normally, one or more maintainers of that target listed in
844 @file{MAINTAINERS}. Some existing architectures may be unmaintained,
845 but it would be unusual to add support for a target that does not have
846 a maintainer when support is added.
847 @item
848 Target triplets covering all @file{config.gcc} stanzas for the target,
849 in the list in @file{contrib/config-list.mk}.
850 @end itemize
851
852 @node Testsuites
853 @chapter Testsuites
854
855 GCC contains several testsuites to help maintain compiler quality.
856 Most of the runtime libraries and language front ends in GCC have
857 testsuites. Currently only the C language testsuites are documented
858 here; FIXME: document the others.
859
860 @menu
861 * Test Idioms:: Idioms used in testsuite code.
862 * Test Directives:: Directives used within DejaGnu tests.
863 * Ada Tests:: The Ada language testsuites.
864 * C Tests:: The C language testsuites.
865 * libgcj Tests:: The Java library testsuites.
866 * LTO Testing:: Support for testing link-time optimizations.
867 * gcov Testing:: Support for testing gcov.
868 * profopt Testing:: Support for testing profile-directed optimizations.
869 * compat Testing:: Support for testing binary compatibility.
870 * Torture Tests:: Support for torture testing using multiple options.
871 @end menu
872
873 @node Test Idioms
874 @section Idioms Used in Testsuite Code
875
876 In general, C testcases have a trailing @file{-@var{n}.c}, starting
877 with @file{-1.c}, in case other testcases with similar names are added
878 later. If the test is a test of some well-defined feature, it should
879 have a name referring to that feature such as
880 @file{@var{feature}-1.c}. If it does not test a well-defined feature
881 but just happens to exercise a bug somewhere in the compiler, and a
882 bug report has been filed for this bug in the GCC bug database,
883 @file{pr@var{bug-number}-1.c} is the appropriate form of name.
884 Otherwise (for miscellaneous bugs not filed in the GCC bug database),
885 and previously more generally, test cases are named after the date on
886 which they were added. This allows people to tell at a glance whether
887 a test failure is because of a recently found bug that has not yet
888 been fixed, or whether it may be a regression, but does not give any
889 other information about the bug or where discussion of it may be
890 found. Some other language testsuites follow similar conventions.
891
892 In the @file{gcc.dg} testsuite, it is often necessary to test that an
893 error is indeed a hard error and not just a warning---for example,
894 where it is a constraint violation in the C standard, which must
895 become an error with @option{-pedantic-errors}. The following idiom,
896 where the first line shown is line @var{line} of the file and the line
897 that generates the error, is used for this:
898
899 @smallexample
900 /* @{ dg-bogus "warning" "warning in place of error" @} */
901 /* @{ dg-error "@var{regexp}" "@var{message}" @{ target *-*-* @} @var{line} @} */
902 @end smallexample
903
904 It may be necessary to check that an expression is an integer constant
905 expression and has a certain value. To check that @code{@var{E}} has
906 value @code{@var{V}}, an idiom similar to the following is used:
907
908 @smallexample
909 char x[((E) == (V) ? 1 : -1)];
910 @end smallexample
911
912 In @file{gcc.dg} tests, @code{__typeof__} is sometimes used to make
913 assertions about the types of expressions. See, for example,
914 @file{gcc.dg/c99-condexpr-1.c}. The more subtle uses depend on the
915 exact rules for the types of conditional expressions in the C
916 standard; see, for example, @file{gcc.dg/c99-intconst-1.c}.
917
918 It is useful to be able to test that optimizations are being made
919 properly. This cannot be done in all cases, but it can be done where
920 the optimization will lead to code being optimized away (for example,
921 where flow analysis or alias analysis should show that certain code
922 cannot be called) or to functions not being called because they have
923 been expanded as built-in functions. Such tests go in
924 @file{gcc.c-torture/execute}. Where code should be optimized away, a
925 call to a nonexistent function such as @code{link_failure ()} may be
926 inserted; a definition
927
928 @smallexample
929 #ifndef __OPTIMIZE__
930 void
931 link_failure (void)
932 @{
933 abort ();
934 @}
935 #endif
936 @end smallexample
937
938 @noindent
939 will also be needed so that linking still succeeds when the test is
940 run without optimization. When all calls to a built-in function
941 should have been optimized and no calls to the non-built-in version of
942 the function should remain, that function may be defined as
943 @code{static} to call @code{abort ()} (although redeclaring a function
944 as static may not work on all targets).
945
946 All testcases must be portable. Target-specific testcases must have
947 appropriate code to avoid causing failures on unsupported systems;
948 unfortunately, the mechanisms for this differ by directory.
949
950 FIXME: discuss non-C testsuites here.
951
952 @node Test Directives
953 @section Directives used within DejaGnu tests
954
955 @menu
956 * Directives:: Syntax and descriptions of test directives.
957 * Selectors:: Selecting targets to which a test applies.
958 * Effective-Target Keywords:: Keywords describing target attributes.
959 * Add Options:: Features for @code{dg-add-options}
960 * Require Support:: Variants of @code{dg-require-@var{support}}
961 * Final Actions:: Commands for use in @code{dg-final}
962 @end menu
963
964 @node Directives
965 @subsection Syntax and Descriptions of test directives
966
967 Test directives appear within comments in a test source file and begin
968 with @code{dg-}. Some of these are defined within DejaGnu and others
969 are local to the GCC testsuite.
970
971 The order in which test directives appear in a test can be important:
972 directives local to GCC sometimes override information used by the
973 DejaGnu directives, which know nothing about the GCC directives, so the
974 DejaGnu directives must precede GCC directives.
975
976 Several test directives include selectors (@pxref{Selectors, , })
977 which are usually preceded by the keyword @code{target} or @code{xfail}.
978
979 @subsubsection Specify how to build the test
980
981 @table @code
982 @item @{ dg-do @var{do-what-keyword} [@{ target/xfail @var{selector} @}] @}
983 @var{do-what-keyword} specifies how the test is compiled and whether
984 it is executed. It is one of:
985
986 @table @code
987 @item preprocess
988 Compile with @option{-E} to run only the preprocessor.
989 @item compile
990 Compile with @option{-S} to produce an assembly code file.
991 @item assemble
992 Compile with @option{-c} to produce a relocatable object file.
993 @item link
994 Compile, assemble, and link to produce an executable file.
995 @item run
996 Produce and run an executable file, which is expected to return
997 an exit code of 0.
998 @end table
999
1000 The default is @code{compile}. That can be overridden for a set of
1001 tests by redefining @code{dg-do-what-default} within the @code{.exp}
1002 file for those tests.
1003
1004 If the directive includes the optional @samp{@{ target @var{selector} @}}
1005 then the test is skipped unless the target system matches the
1006 @var{selector}.
1007
1008 If @var{do-what-keyword} is @code{run} and the directive includes
1009 the optional @samp{@{ xfail @var{selector} @}} and the selector is met
1010 then the test is expected to fail. The @code{xfail} clause is ignored
1011 for other values of @var{do-what-keyword}; those tests can use
1012 directive @code{dg-xfail-if}.
1013 @end table
1014
1015 @subsubsection Specify additional compiler options
1016
1017 @table @code
1018 @item @{ dg-options @var{options} [@{ target @var{selector} @}] @}
1019 This DejaGnu directive provides a list of compiler options, to be used
1020 if the target system matches @var{selector}, that replace the default
1021 options used for this set of tests.
1022
1023 @item @{ dg-add-options @var{feature} @dots{} @}
1024 Add any compiler options that are needed to access certain features.
1025 This directive does nothing on targets that enable the features by
1026 default, or that don't provide them at all. It must come after
1027 all @code{dg-options} directives.
1028 For supported values of @var{feature} see @ref{Add Options, ,}.
1029
1030 @item @{ dg-additional-options @var{options} [@{ target @var{selector} @}] @}
1031 This directive provides a list of compiler options, to be used
1032 if the target system matches @var{selector}, that are added to the default
1033 options used for this set of tests.
1034 @end table
1035
1036 @subsubsection Modify the test timeout value
1037
1038 The normal timeout limit, in seconds, is found by searching the
1039 following in order:
1040
1041 @itemize @bullet
1042 @item the value defined by an earlier @code{dg-timeout} directive in
1043 the test
1044
1045 @item variable @var{tool_timeout} defined by the set of tests
1046
1047 @item @var{gcc},@var{timeout} set in the target board
1048
1049 @item 300
1050 @end itemize
1051
1052 @table @code
1053 @item @{ dg-timeout @var{n} [@{target @var{selector} @}] @}
1054 Set the time limit for the compilation and for the execution of the test
1055 to the specified number of seconds.
1056
1057 @item @{ dg-timeout-factor @var{x} [@{ target @var{selector} @}] @}
1058 Multiply the normal time limit for compilation and execution of the test
1059 by the specified floating-point factor.
1060 @end table
1061
1062 @subsubsection Skip a test for some targets
1063
1064 @table @code
1065 @item @{ dg-skip-if @var{comment} @{ @var{selector} @} [@{ @var{include-opts} @} [@{ @var{exclude-opts} @}]] @}
1066 Arguments @var{include-opts} and @var{exclude-opts} are lists in which
1067 each element is a string of zero or more GCC options.
1068 Skip the test if all of the following conditions are met:
1069 @itemize @bullet
1070 @item the test system is included in @var{selector}
1071
1072 @item for at least one of the option strings in @var{include-opts},
1073 every option from that string is in the set of options with which
1074 the test would be compiled; use @samp{"*"} for an @var{include-opts} list
1075 that matches any options; that is the default if @var{include-opts} is
1076 not specified
1077
1078 @item for each of the option strings in @var{exclude-opts}, at least one
1079 option from that string is not in the set of options with which the test
1080 would be compiled; use @samp{""} for an empty @var{exclude-opts} list;
1081 that is the default if @var{exclude-opts} is not specified
1082 @end itemize
1083
1084 For example, to skip a test if option @code{-Os} is present:
1085
1086 @smallexample
1087 /* @{ dg-skip-if "" @{ *-*-* @} @{ "-Os" @} @{ "" @} @} */
1088 @end smallexample
1089
1090 To skip a test if both options @code{-O2} and @code{-g} are present:
1091
1092 @smallexample
1093 /* @{ dg-skip-if "" @{ *-*-* @} @{ "-O2 -g" @} @{ "" @} @} */
1094 @end smallexample
1095
1096 To skip a test if either @code{-O2} or @code{-O3} is present:
1097
1098 @smallexample
1099 /* @{ dg-skip-if "" @{ *-*-* @} @{ "-O2" "-O3" @} @{ "" @} @} */
1100 @end smallexample
1101
1102 To skip a test unless option @code{-Os} is present:
1103
1104 @smallexample
1105 /* @{ dg-skip-if "" @{ *-*-* @} @{ "*" @} @{ "-Os" @} @} */
1106 @end smallexample
1107
1108 To skip a test if either @code{-O2} or @code{-O3} is used with @code{-g}
1109 but not if @code{-fpic} is also present:
1110
1111 @smallexample
1112 /* @{ dg-skip-if "" @{ *-*-* @} @{ "-O2 -g" "-O3 -g" @} @{ "-fpic" @} @} */
1113 @end smallexample
1114
1115 @item @{ dg-require-effective-target @var{keyword} [@{ @var{selector} @}] @}
1116 Skip the test if the test target, including current multilib flags,
1117 is not covered by the effective-target keyword.
1118 If the directive includes the optional @samp{@{ @var{selector} @}}
1119 then the effective-target test is only performed if the target system
1120 matches the @var{selector}.
1121 This directive must appear after any @code{dg-do} directive in the test
1122 and before any @code{dg-additional-sources} directive.
1123 @xref{Effective-Target Keywords, , }.
1124
1125 @item @{ dg-require-@var{support} args @}
1126 Skip the test if the target does not provide the required support.
1127 These directives must appear after any @code{dg-do} directive in the test
1128 and before any @code{dg-additional-sources} directive.
1129 They require at least one argument, which can be an empty string if the
1130 specific procedure does not examine the argument.
1131 @xref{Require Support, , }, for a complete list of these directives.
1132 @end table
1133
1134 @subsubsection Expect a test to fail for some targets
1135
1136 @table @code
1137 @item @{ dg-xfail-if @var{comment} @{ @var{selector} @} [@{ @var{include-opts} @} [@{ @var{exclude-opts} @}]] @}
1138 Expect the test to fail if the conditions (which are the same as for
1139 @code{dg-skip-if}) are met. This does not affect the execute step.
1140
1141 @item @{ dg-xfail-run-if @var{comment} @{ @var{selector} @} [@{ @var{include-opts} @} [@{ @var{exclude-opts} @}]] @}
1142 Expect the execute step of a test to fail if the conditions (which are
1143 the same as for @code{dg-skip-if}) are met.
1144 @end table
1145
1146 @subsubsection Expect the test executable to fail
1147
1148 @table @code
1149 @item @{ dg-shouldfail @var{comment} [@{ @var{selector} @} [@{ @var{include-opts} @} [@{ @var{exclude-opts} @}]]] @}
1150 Expect the test executable to return a nonzero exit status if the
1151 conditions (which are the same as for @code{dg-skip-if}) are met.
1152 @end table
1153
1154 @subsubsection Verify compiler messages
1155
1156 @table @code
1157 @item @{ dg-error @var{regexp} [@var{comment} [@{ target/xfail @var{selector} @} [@var{line}] @}]] @}
1158 This DejaGnu directive appears on a source line that is expected to get
1159 an error message, or else specifies the source line associated with the
1160 message. If there is no message for that line or if the text of that
1161 message is not matched by @var{regexp} then the check fails and
1162 @var{comment} is included in the @code{FAIL} message. The check does
1163 not look for the string @samp{error} unless it is part of @var{regexp}.
1164
1165 @item @{ dg-warning @var{regexp} [@var{comment} [@{ target/xfail @var{selector} @} [@var{line}] @}]] @}
1166 This DejaGnu directive appears on a source line that is expected to get
1167 a warning message, or else specifies the source line associated with the
1168 message. If there is no message for that line or if the text of that
1169 message is not matched by @var{regexp} then the check fails and
1170 @var{comment} is included in the @code{FAIL} message. The check does
1171 not look for the string @samp{warning} unless it is part of @var{regexp}.
1172
1173 @item @{ dg-message @var{regexp} [@var{comment} [@{ target/xfail @var{selector} @} [@var{line}] @}]] @}
1174 The line is expected to get a message other than an error or warning.
1175 If there is no message for that line or if the text of that message is
1176 not matched by @var{regexp} then the check fails and @var{comment} is
1177 included in the @code{FAIL} message.
1178
1179 @item @{ dg-bogus @var{regexp} [@var{comment} [@{ target/xfail @var{selector} @} [@var{line}] @}]] @}
1180 This DejaGnu directive appears on a source line that should not get a
1181 message matching @var{regexp}, or else specifies the source line
1182 associated with the bogus message. It is usually used with @samp{xfail}
1183 to indicate that the message is a known problem for a particular set of
1184 targets.
1185
1186 @item @{ dg-excess-errors @var{comment} [@{ target/xfail @var{selector} @}] @}
1187 This DejaGnu directive indicates that the test is expected to fail due
1188 to compiler messages that are not handled by @samp{dg-error},
1189 @samp{dg-warning} or @samp{dg-bogus}. For this directive @samp{xfail}
1190 has the same effect as @samp{target}.
1191
1192 @item @{ dg-prune-output @var{regexp} @}
1193 Prune messages matching @var{regexp} from the test output.
1194 @end table
1195
1196 @subsubsection Verify output of the test executable
1197
1198 @table @code
1199 @item @{ dg-output @var{regexp} [@{ target/xfail @var{selector} @}] @}
1200 This DejaGnu directive compares @var{regexp} to the combined output
1201 that the test executable writes to @file{stdout} and @file{stderr}.
1202 @end table
1203
1204 @subsubsection Specify additional files for a test
1205
1206 @table @code
1207 @item @{ dg-additional-files "@var{filelist}" @}
1208 Specify additional files, other than source files, that must be copied
1209 to the system where the compiler runs.
1210
1211 @item @{ dg-additional-sources "@var{filelist}" @}
1212 Specify additional source files to appear in the compile line
1213 following the main test file.
1214 @end table
1215
1216 @subsubsection Add checks at the end of a test
1217
1218 @table @code
1219 @item @{ dg-final @{ @var{local-directive} @} @}
1220 This DejaGnu directive is placed within a comment anywhere in the
1221 source file and is processed after the test has been compiled and run.
1222 Multiple @samp{dg-final} commands are processed in the order in which
1223 they appear in the source file. @xref{Final Actions, , }, for a list
1224 of directives that can be used within @code{dg-final}.
1225 @end table
1226
1227 @node Selectors
1228 @subsection Selecting targets to which a test applies
1229
1230 Several test directives include @var{selector}s to limit the targets
1231 for which a test is run or to declare that a test is expected to fail
1232 on particular targets.
1233
1234 A selector is:
1235 @itemize @bullet
1236 @item one or more target triplets, possibly including wildcard characters;
1237 use @samp{*-*-*} to match any target
1238 @item a single effective-target keyword (@pxref{Effective-Target Keywords})
1239 @item a logical expression
1240 @end itemize
1241
1242 Depending on the context, the selector specifies whether a test is
1243 skipped and reported as unsupported or is expected to fail. A context
1244 that allows either @samp{target} or @samp{xfail} also allows
1245 @samp{@{ target @var{selector1} xfail @var{selector2} @}}
1246 to skip the test for targets that don't match @var{selector1} and the
1247 test to fail for targets that match @var{selector2}.
1248
1249 A selector expression appears within curly braces and uses a single
1250 logical operator: one of @samp{!}, @samp{&&}, or @samp{||}. An
1251 operand is another selector expression, an effective-target keyword,
1252 a single target triplet, or a list of target triplets within quotes or
1253 curly braces. For example:
1254
1255 @smallexample
1256 @{ target @{ ! "hppa*-*-* ia64*-*-*" @} @}
1257 @{ target @{ powerpc*-*-* && lp64 @} @}
1258 @{ xfail @{ lp64 || vect_no_align @} @}
1259 @end smallexample
1260
1261 @node Effective-Target Keywords
1262 @subsection Keywords describing target attributes
1263
1264 Effective-target keywords identify sets of targets that support
1265 particular functionality. They are used to limit tests to be run only
1266 for particular targets, or to specify that particular sets of targets
1267 are expected to fail some tests.
1268
1269 Effective-target keywords are defined in @file{lib/target-supports.exp} in
1270 the GCC testsuite, with the exception of those that are documented as
1271 being local to a particular test directory.
1272
1273 The @samp{effective target} takes into account all of the compiler options
1274 with which the test will be compiled, including the multilib options.
1275 By convention, keywords ending in @code{_nocache} can also include options
1276 specified for the particular test in an earlier @code{dg-options} or
1277 @code{dg-add-options} directive.
1278
1279 @subsubsection Data type sizes
1280
1281 @table @code
1282 @item ilp32
1283 Target has 32-bit @code{int}, @code{long}, and pointers.
1284
1285 @item lp64
1286 Target has 32-bit @code{int}, 64-bit @code{long} and pointers.
1287
1288 @item llp64
1289 Target has 32-bit @code{int} and @code{long}, 64-bit @code{long long}
1290 and pointers.
1291
1292 @item double64
1293 Target has 64-bit @code{double}.
1294
1295 @item double64plus
1296 Target has @code{double} that is 64 bits or longer.
1297
1298 @item int32plus
1299 Target has @code{int} that is at 32 bits or longer.
1300
1301 @item int16
1302 Target has @code{int} that is 16 bits or shorter.
1303
1304 @item long_neq_int
1305 Target has @code{int} and @code{long} with different sizes.
1306
1307 @item large_double
1308 Target supports @code{double} that is longer than @code{float}.
1309
1310 @item large_long_double
1311 Target supports @code{long double} that is longer than @code{double}.
1312
1313 @item ptr32plus
1314 Target has pointers that are 32 bits or longer.
1315
1316 @item size32plus
1317 Target supports array and structure sizes that are 32 bits or longer.
1318
1319 @item 4byte_wchar_t
1320 Target has @code{wchar_t} that is at least 4 bytes.
1321 @end table
1322
1323 @subsubsection Fortran-specific attributes
1324
1325 @table @code
1326 @item fortran_integer_16
1327 Target supports Fortran @code{integer} that is 16 bytes or longer.
1328
1329 @item fortran_large_int
1330 Target supports Fortran @code{integer} kinds larger than @code{integer(8)}.
1331
1332 @item fortran_large_real
1333 Target supports Fortran @code{real} kinds larger than @code{real(8)}.
1334 @end table
1335
1336 @subsubsection Vector-specific attributes
1337
1338 @table @code
1339 @item vect_condition
1340 Target supports vector conditional operations.
1341
1342 @item vect_double
1343 Target supports hardware vectors of @code{double}.
1344
1345 @item vect_float
1346 Target supports hardware vectors of @code{float}.
1347
1348 @item vect_int
1349 Target supports hardware vectors of @code{int}.
1350
1351 @item vect_long
1352 Target supports hardware vectors of @code{long}.
1353
1354 @item vect_long_long
1355 Target supports hardware vectors of @code{long long}.
1356
1357 @item vect_aligned_arrays
1358 Target aligns arrays to vector alignment boundary.
1359
1360 @item vect_hw_misalign
1361 Target supports a vector misalign access.
1362
1363 @item vect_no_align
1364 Target does not support a vector alignment mechanism.
1365
1366 @item vect_no_int_max
1367 Target does not support a vector max instruction on @code{int}.
1368
1369 @item vect_no_int_add
1370 Target does not support a vector add instruction on @code{int}.
1371
1372 @item vect_no_bitwise
1373 Target does not support vector bitwise instructions.
1374
1375 @item vect_char_mult
1376 Target supports @code{vector char} multiplication.
1377
1378 @item vect_short_mult
1379 Target supports @code{vector short} multiplication.
1380
1381 @item vect_int_mult
1382 Target supports @code{vector int} multiplication.
1383
1384 @item vect_extract_even_odd
1385 Target supports vector even/odd element extraction.
1386
1387 @item vect_extract_even_odd_wide
1388 Target supports vector even/odd element extraction of vectors with elements
1389 @code{SImode} or larger.
1390
1391 @item vect_interleave
1392 Target supports vector interleaving.
1393
1394 @item vect_strided
1395 Target supports vector interleaving and extract even/odd.
1396
1397 @item vect_strided_wide
1398 Target supports vector interleaving and extract even/odd for wide
1399 element types.
1400
1401 @item vect_perm
1402 Target supports vector permutation.
1403
1404 @item vect_shift
1405 Target supports a hardware vector shift operation.
1406
1407 @item vect_widen_sum_hi_to_si
1408 Target supports a vector widening summation of @code{short} operands
1409 into @code{int} results, or can promote (unpack) from @code{short}
1410 to @code{int}.
1411
1412 @item vect_widen_sum_qi_to_hi
1413 Target supports a vector widening summation of @code{char} operands
1414 into @code{short} results, or can promote (unpack) from @code{char}
1415 to @code{short}.
1416
1417 @item vect_widen_sum_qi_to_si
1418 Target supports a vector widening summation of @code{char} operands
1419 into @code{int} results.
1420
1421 @item vect_widen_mult_qi_to_hi
1422 Target supports a vector widening multiplication of @code{char} operands
1423 into @code{short} results, or can promote (unpack) from @code{char} to
1424 @code{short} and perform non-widening multiplication of @code{short}.
1425
1426 @item vect_widen_mult_hi_to_si
1427 Target supports a vector widening multiplication of @code{short} operands
1428 into @code{int} results, or can promote (unpack) from @code{short} to
1429 @code{int} and perform non-widening multiplication of @code{int}.
1430
1431 @item vect_sdot_qi
1432 Target supports a vector dot-product of @code{signed char}.
1433
1434 @item vect_udot_qi
1435 Target supports a vector dot-product of @code{unsigned char}.
1436
1437 @item vect_sdot_hi
1438 Target supports a vector dot-product of @code{signed short}.
1439
1440 @item vect_udot_hi
1441 Target supports a vector dot-product of @code{unsigned short}.
1442
1443 @item vect_pack_trunc
1444 Target supports a vector demotion (packing) of @code{short} to @code{char}
1445 and from @code{int} to @code{short} using modulo arithmetic.
1446
1447 @item vect_unpack
1448 Target supports a vector promotion (unpacking) of @code{char} to @code{short}
1449 and from @code{char} to @code{int}.
1450
1451 @item vect_intfloat_cvt
1452 Target supports conversion from @code{signed int} to @code{float}.
1453
1454 @item vect_uintfloat_cvt
1455 Target supports conversion from @code{unsigned int} to @code{float}.
1456
1457 @item vect_floatint_cvt
1458 Target supports conversion from @code{float} to @code{signed int}.
1459
1460 @item vect_floatuint_cvt
1461 Target supports conversion from @code{float} to @code{unsigned int}.
1462 @end table
1463
1464 @subsubsection Thread Local Storage attributes
1465
1466 @table @code
1467 @item tls
1468 Target supports thread-local storage.
1469
1470 @item tls_native
1471 Target supports native (rather than emulated) thread-local storage.
1472
1473 @item tls_runtime
1474 Test system supports executing TLS executables.
1475 @end table
1476
1477 @subsubsection Decimal floating point attributes
1478
1479 @table @code
1480 @item dfp
1481 Targets supports compiling decimal floating point extension to C.
1482
1483 @item dfp_nocache
1484 Including the options used to compile this particular test, the
1485 target supports compiling decimal floating point extension to C.
1486
1487 @item dfprt
1488 Test system can execute decimal floating point tests.
1489
1490 @item dfprt_nocache
1491 Including the options used to compile this particular test, the
1492 test system can execute decimal floating point tests.
1493
1494 @item hard_dfp
1495 Target generates decimal floating point instructions with current options.
1496 @end table
1497
1498 @subsubsection ARM-specific attributes
1499
1500 @table @code
1501 @item arm32
1502 ARM target generates 32-bit code.
1503
1504 @item arm_eabi
1505 ARM target adheres to the ABI for the ARM Architecture.
1506
1507 @item arm_hf_eabi
1508 ARM target adheres to the VFP and Advanced SIMD Register Arguments
1509 variant of the ABI for the ARM Architecture (as selected with
1510 @code{-mfloat-abi=hard}).
1511
1512 @item arm_hard_vfp_ok
1513 ARM target supports @code{-mfpu=vfp -mfloat-abi=hard}.
1514 Some multilibs may be incompatible with these options.
1515
1516 @item arm_iwmmxt_ok
1517 ARM target supports @code{-mcpu=iwmmxt}.
1518 Some multilibs may be incompatible with this option.
1519
1520 @item arm_neon
1521 ARM target supports generating NEON instructions.
1522
1523 @item arm_neon_hw
1524 Test system supports executing NEON instructions.
1525
1526 @item arm_neonv2_hw
1527 Test system supports executing NEON v2 instructions.
1528
1529 @item arm_neon_ok
1530 @anchor{arm_neon_ok}
1531 ARM Target supports @code{-mfpu=neon -mfloat-abi=softfp} or compatible
1532 options. Some multilibs may be incompatible with these options.
1533
1534 @item arm_neonv2_ok
1535 @anchor{arm_neonv2_ok}
1536 ARM Target supports @code{-mfpu=neon-vfpv4 -mfloat-abi=softfp} or compatible
1537 options. Some multilibs may be incompatible with these options.
1538
1539 @item arm_neon_fp16_ok
1540 @anchor{arm_neon_fp16_ok}
1541 ARM Target supports @code{-mfpu=neon-fp16 -mfloat-abi=softfp} or compatible
1542 options. Some multilibs may be incompatible with these options.
1543
1544 @item arm_thumb1_ok
1545 ARM target generates Thumb-1 code for @code{-mthumb}.
1546
1547 @item arm_thumb2_ok
1548 ARM target generates Thumb-2 code for @code{-mthumb}.
1549
1550 @item arm_vfp_ok
1551 ARM target supports @code{-mfpu=vfp -mfloat-abi=softfp}.
1552 Some multilibs may be incompatible with these options.
1553
1554 @item arm_v8_vfp_ok
1555 ARM target supports @code{-mfpu=fp-armv8 -mfloat-abi=softfp}.
1556 Some multilibs may be incompatible with these options.
1557
1558 @item arm_v8_neon_ok
1559 ARM target supports @code{-mfpu=neon-fp-armv8 -mfloat-abi=softfp}.
1560 Some multilibs may be incompatible with these options.
1561
1562 @item arm_prefer_ldrd_strd
1563 ARM target prefers @code{LDRD} and @code{STRD} instructions over
1564 @code{LDM} and @code{STM} instructions.
1565
1566 @end table
1567
1568 @subsubsection MIPS-specific attributes
1569
1570 @table @code
1571 @item mips64
1572 MIPS target supports 64-bit instructions.
1573
1574 @item nomips16
1575 MIPS target does not produce MIPS16 code.
1576
1577 @item mips16_attribute
1578 MIPS target can generate MIPS16 code.
1579
1580 @item mips_loongson
1581 MIPS target is a Loongson-2E or -2F target using an ABI that supports
1582 the Loongson vector modes.
1583
1584 @item mips_newabi_large_long_double
1585 MIPS target supports @code{long double} larger than @code{double}
1586 when using the new ABI.
1587
1588 @item mpaired_single
1589 MIPS target supports @code{-mpaired-single}.
1590 @end table
1591
1592 @subsubsection PowerPC-specific attributes
1593
1594 @table @code
1595 @item powerpc64
1596 Test system supports executing 64-bit instructions.
1597
1598 @item powerpc_altivec
1599 PowerPC target supports AltiVec.
1600
1601 @item powerpc_altivec_ok
1602 PowerPC target supports @code{-maltivec}.
1603
1604 @item powerpc_fprs
1605 PowerPC target supports floating-point registers.
1606
1607 @item powerpc_hard_double
1608 PowerPC target supports hardware double-precision floating-point.
1609
1610 @item powerpc_ppu_ok
1611 PowerPC target supports @code{-mcpu=cell}.
1612
1613 @item powerpc_spe
1614 PowerPC target supports PowerPC SPE.
1615
1616 @item powerpc_spe_nocache
1617 Including the options used to compile this particular test, the
1618 PowerPC target supports PowerPC SPE.
1619
1620 @item powerpc_spu
1621 PowerPC target supports PowerPC SPU.
1622
1623 @item spu_auto_overlay
1624 SPU target has toolchain that supports automatic overlay generation.
1625
1626 @item powerpc_vsx_ok
1627 PowerPC target supports @code{-mvsx}.
1628
1629 @item powerpc_405_nocache
1630 Including the options used to compile this particular test, the
1631 PowerPC target supports PowerPC 405.
1632
1633 @item vmx_hw
1634 PowerPC target supports executing AltiVec instructions.
1635 @end table
1636
1637 @subsubsection Other hardware attributes
1638
1639 @table @code
1640 @item avx
1641 Target supports compiling @code{avx} instructions.
1642
1643 @item avx_runtime
1644 Target supports the execution of @code{avx} instructions.
1645
1646 @item cell_hw
1647 Test system can execute AltiVec and Cell PPU instructions.
1648
1649 @item coldfire_fpu
1650 Target uses a ColdFire FPU.
1651
1652 @item hard_float
1653 Target supports FPU instructions.
1654
1655 @item sse
1656 Target supports compiling @code{sse} instructions.
1657
1658 @item sse_runtime
1659 Target supports the execution of @code{sse} instructions.
1660
1661 @item sse2
1662 Target supports compiling @code{sse2} instructions.
1663
1664 @item sse2_runtime
1665 Target supports the execution of @code{sse2} instructions.
1666
1667 @item sync_char_short
1668 Target supports atomic operations on @code{char} and @code{short}.
1669
1670 @item sync_int_long
1671 Target supports atomic operations on @code{int} and @code{long}.
1672
1673 @item ultrasparc_hw
1674 Test environment appears to run executables on a simulator that
1675 accepts only @code{EM_SPARC} executables and chokes on @code{EM_SPARC32PLUS}
1676 or @code{EM_SPARCV9} executables.
1677
1678 @item vect_cmdline_needed
1679 Target requires a command line argument to enable a SIMD instruction set.
1680 @end table
1681
1682 @subsubsection Environment attributes
1683
1684 @table @code
1685 @item c
1686 The language for the compiler under test is C.
1687
1688 @item c++
1689 The language for the compiler under test is C++.
1690
1691 @item c99_runtime
1692 Target provides a full C99 runtime.
1693
1694 @item correct_iso_cpp_string_wchar_protos
1695 Target @code{string.h} and @code{wchar.h} headers provide C++ required
1696 overloads for @code{strchr} etc. functions.
1697
1698 @item dummy_wcsftime
1699 Target uses a dummy @code{wcsftime} function that always returns zero.
1700
1701 @item fd_truncate
1702 Target can truncate a file from a file descriptor, as used by
1703 @file{libgfortran/io/unix.c:fd_truncate}; i.e. @code{ftruncate} or
1704 @code{chsize}.
1705
1706 @item freestanding
1707 Target is @samp{freestanding} as defined in section 4 of the C99 standard.
1708 Effectively, it is a target which supports no extra headers or libraries
1709 other than what is considered essential.
1710
1711 @item init_priority
1712 Target supports constructors with initialization priority arguments.
1713
1714 @item inttypes_types
1715 Target has the basic signed and unsigned types in @code{inttypes.h}.
1716 This is for tests that GCC's notions of these types agree with those
1717 in the header, as some systems have only @code{inttypes.h}.
1718
1719 @item lax_strtofp
1720 Target might have errors of a few ULP in string to floating-point
1721 conversion functions and overflow is not always detected correctly by
1722 those functions.
1723
1724 @item mmap
1725 Target supports @code{mmap}.
1726
1727 @item newlib
1728 Target supports Newlib.
1729
1730 @item pow10
1731 Target provides @code{pow10} function.
1732
1733 @item pthread
1734 Target can compile using @code{pthread.h} with no errors or warnings.
1735
1736 @item pthread_h
1737 Target has @code{pthread.h}.
1738
1739 @item run_expensive_tests
1740 Expensive testcases (usually those that consume excessive amounts of CPU
1741 time) should be run on this target. This can be enabled by setting the
1742 @env{GCC_TEST_RUN_EXPENSIVE} environment variable to a non-empty string.
1743
1744 @item simulator
1745 Test system runs executables on a simulator (i.e. slowly) rather than
1746 hardware (i.e. fast).
1747
1748 @item stdint_types
1749 Target has the basic signed and unsigned C types in @code{stdint.h}.
1750 This will be obsolete when GCC ensures a working @code{stdint.h} for
1751 all targets.
1752
1753 @item trampolines
1754 Target supports trampolines.
1755
1756 @item uclibc
1757 Target supports uClibc.
1758
1759 @item unwrapped
1760 Target does not use a status wrapper.
1761
1762 @item vxworks_kernel
1763 Target is a VxWorks kernel.
1764
1765 @item vxworks_rtp
1766 Target is a VxWorks RTP.
1767
1768 @item wchar
1769 Target supports wide characters.
1770 @end table
1771
1772 @subsubsection Other attributes
1773
1774 @table @code
1775 @item automatic_stack_alignment
1776 Target supports automatic stack alignment.
1777
1778 @item cxa_atexit
1779 Target uses @code{__cxa_atexit}.
1780
1781 @item default_packed
1782 Target has packed layout of structure members by default.
1783
1784 @item fgraphite
1785 Target supports Graphite optimizations.
1786
1787 @item fixed_point
1788 Target supports fixed-point extension to C.
1789
1790 @item fopenmp
1791 Target supports OpenMP via @option{-fopenmp}.
1792
1793 @item fpic
1794 Target supports @option{-fpic} and @option{-fPIC}.
1795
1796 @item freorder
1797 Target supports @option{-freorder-blocks-and-partition}.
1798
1799 @item fstack_protector
1800 Target supports @option{-fstack-protector}.
1801
1802 @item gas
1803 Target uses GNU @command{as}.
1804
1805 @item gc_sections
1806 Target supports @option{--gc-sections}.
1807
1808 @item gld
1809 Target uses GNU @command{ld}.
1810
1811 @item keeps_null_pointer_checks
1812 Target keeps null pointer checks, either due to the use of
1813 @option{-fno-delete-null-pointer-checks} or hardwired into the target.
1814
1815 @item lto
1816 Compiler has been configured to support link-time optimization (LTO).
1817
1818 @item naked_functions
1819 Target supports the @code{naked} function attribute.
1820
1821 @item named_sections
1822 Target supports named sections.
1823
1824 @item natural_alignment_32
1825 Target uses natural alignment (aligned to type size) for types of
1826 32 bits or less.
1827
1828 @item target_natural_alignment_64
1829 Target uses natural alignment (aligned to type size) for types of
1830 64 bits or less.
1831
1832 @item nonpic
1833 Target does not generate PIC by default.
1834
1835 @item pcc_bitfield_type_matters
1836 Target defines @code{PCC_BITFIELD_TYPE_MATTERS}.
1837
1838 @item pe_aligned_commons
1839 Target supports @option{-mpe-aligned-commons}.
1840
1841 @item pie
1842 Target supports @option{-pie}, @option{-fpie} and @option{-fPIE}.
1843
1844 @item section_anchors
1845 Target supports section anchors.
1846
1847 @item short_enums
1848 Target defaults to short enums.
1849
1850 @item static
1851 Target supports @option{-static}.
1852
1853 @item static_libgfortran
1854 Target supports statically linking @samp{libgfortran}.
1855
1856 @item string_merging
1857 Target supports merging string constants at link time.
1858
1859 @item ucn
1860 Target supports compiling and assembling UCN.
1861
1862 @item ucn_nocache
1863 Including the options used to compile this particular test, the
1864 target supports compiling and assembling UCN.
1865
1866 @item unaligned_stack
1867 Target does not guarantee that its @code{STACK_BOUNDARY} is greater than
1868 or equal to the required vector alignment.
1869
1870 @item vector_alignment_reachable
1871 Vector alignment is reachable for types of 32 bits or less.
1872
1873 @item vector_alignment_reachable_for_64bit
1874 Vector alignment is reachable for types of 64 bits or less.
1875
1876 @item wchar_t_char16_t_compatible
1877 Target supports @code{wchar_t} that is compatible with @code{char16_t}.
1878
1879 @item wchar_t_char32_t_compatible
1880 Target supports @code{wchar_t} that is compatible with @code{char32_t}.
1881 @end table
1882
1883 @subsubsection Local to tests in @code{gcc.target/i386}
1884
1885 @table @code
1886 @item 3dnow
1887 Target supports compiling @code{3dnow} instructions.
1888
1889 @item aes
1890 Target supports compiling @code{aes} instructions.
1891
1892 @item fma4
1893 Target supports compiling @code{fma4} instructions.
1894
1895 @item ms_hook_prologue
1896 Target supports attribute @code{ms_hook_prologue}.
1897
1898 @item pclmul
1899 Target supports compiling @code{pclmul} instructions.
1900
1901 @item sse3
1902 Target supports compiling @code{sse3} instructions.
1903
1904 @item sse4
1905 Target supports compiling @code{sse4} instructions.
1906
1907 @item sse4a
1908 Target supports compiling @code{sse4a} instructions.
1909
1910 @item ssse3
1911 Target supports compiling @code{ssse3} instructions.
1912
1913 @item vaes
1914 Target supports compiling @code{vaes} instructions.
1915
1916 @item vpclmul
1917 Target supports compiling @code{vpclmul} instructions.
1918
1919 @item xop
1920 Target supports compiling @code{xop} instructions.
1921 @end table
1922
1923 @subsubsection Local to tests in @code{gcc.target/spu/ea}
1924
1925 @table @code
1926 @item ealib
1927 Target @code{__ea} library functions are available.
1928 @end table
1929
1930 @subsubsection Local to tests in @code{gcc.test-framework}
1931
1932 @table @code
1933 @item no
1934 Always returns 0.
1935
1936 @item yes
1937 Always returns 1.
1938 @end table
1939
1940 @node Add Options
1941 @subsection Features for @code{dg-add-options}
1942
1943 The supported values of @var{feature} for directive @code{dg-add-options}
1944 are:
1945
1946 @table @code
1947 @item arm_neon
1948 NEON support. Only ARM targets support this feature, and only then
1949 in certain modes; see the @ref{arm_neon_ok,,arm_neon_ok effective target
1950 keyword}.
1951
1952 @item arm_neon_fp16
1953 NEON and half-precision floating point support. Only ARM targets
1954 support this feature, and only then in certain modes; see
1955 the @ref{arm_neon_ok,,arm_neon_fp16_ok effective target keyword}.
1956
1957 @item bind_pic_locally
1958 Add the target-specific flags needed to enable functions to bind
1959 locally when using pic/PIC passes in the testsuite.
1960
1961 @item c99_runtime
1962 Add the target-specific flags needed to access the C99 runtime.
1963
1964 @item ieee
1965 Add the target-specific flags needed to enable full IEEE
1966 compliance mode.
1967
1968 @item mips16_attribute
1969 @code{mips16} function attributes.
1970 Only MIPS targets support this feature, and only then in certain modes.
1971
1972 @item tls
1973 Add the target-specific flags needed to use thread-local storage.
1974 @end table
1975
1976 @node Require Support
1977 @subsection Variants of @code{dg-require-@var{support}}
1978
1979 A few of the @code{dg-require} directives take arguments.
1980
1981 @table @code
1982 @item dg-require-iconv @var{codeset}
1983 Skip the test if the target does not support iconv. @var{codeset} is
1984 the codeset to convert to.
1985
1986 @item dg-require-profiling @var{profopt}
1987 Skip the test if the target does not support profiling with option
1988 @var{profopt}.
1989
1990 @item dg-require-visibility @var{vis}
1991 Skip the test if the target does not support the @code{visibility} attribute.
1992 If @var{vis} is @code{""}, support for @code{visibility("hidden")} is
1993 checked, for @code{visibility("@var{vis}")} otherwise.
1994 @end table
1995
1996 The original @code{dg-require} directives were defined before there
1997 was support for effective-target keywords. The directives that do not
1998 take arguments could be replaced with effective-target keywords.
1999
2000 @table @code
2001 @item dg-require-alias ""
2002 Skip the test if the target does not support the @samp{alias} attribute.
2003
2004 @item dg-require-ascii-locale ""
2005 Skip the test if the host does not support an ASCII locale.
2006
2007 @item dg-require-compat-dfp ""
2008 Skip this test unless both compilers in a @file{compat} testsuite
2009 support decimal floating point.
2010
2011 @item dg-require-cxa-atexit ""
2012 Skip the test if the target does not support @code{__cxa_atexit}.
2013 This is equivalent to @code{dg-require-effective-target cxa_atexit}.
2014
2015 @item dg-require-dll ""
2016 Skip the test if the target does not support DLL attributes.
2017
2018 @item dg-require-fork ""
2019 Skip the test if the target does not support @code{fork}.
2020
2021 @item dg-require-gc-sections ""
2022 Skip the test if the target's linker does not support the
2023 @code{--gc-sections} flags.
2024 This is equivalent to @code{dg-require-effective-target gc-sections}.
2025
2026 @item dg-require-host-local ""
2027 Skip the test if the host is remote, rather than the same as the build
2028 system. Some tests are incompatible with DejaGnu's handling of remote
2029 hosts, which involves copying the source file to the host and compiling
2030 it with a relative path and "@code{-o a.out}".
2031
2032 @item dg-require-mkfifo ""
2033 Skip the test if the target does not support @code{mkfifo}.
2034
2035 @item dg-require-named-sections ""
2036 Skip the test is the target does not support named sections.
2037 This is equivalent to @code{dg-require-effective-target named_sections}.
2038
2039 @item dg-require-weak ""
2040 Skip the test if the target does not support weak symbols.
2041
2042 @item dg-require-weak-override ""
2043 Skip the test if the target does not support overriding weak symbols.
2044 @end table
2045
2046 @node Final Actions
2047 @subsection Commands for use in @code{dg-final}
2048
2049 The GCC testsuite defines the following directives to be used within
2050 @code{dg-final}.
2051
2052 @subsubsection Scan a particular file
2053
2054 @table @code
2055 @item scan-file @var{filename} @var{regexp} [@{ target/xfail @var{selector} @}]
2056 Passes if @var{regexp} matches text in @var{filename}.
2057 @item scan-file-not @var{filename} @var{regexp} [@{ target/xfail @var{selector} @}]
2058 Passes if @var{regexp} does not match text in @var{filename}.
2059 @item scan-module @var{module} @var{regexp} [@{ target/xfail @var{selector} @}]
2060 Passes if @var{regexp} matches in Fortran module @var{module}.
2061 @end table
2062
2063 @subsubsection Scan the assembly output
2064
2065 @table @code
2066 @item scan-assembler @var{regex} [@{ target/xfail @var{selector} @}]
2067 Passes if @var{regex} matches text in the test's assembler output.
2068
2069 @item scan-assembler-not @var{regex} [@{ target/xfail @var{selector} @}]
2070 Passes if @var{regex} does not match text in the test's assembler output.
2071
2072 @item scan-assembler-times @var{regex} @var{num} [@{ target/xfail @var{selector} @}]
2073 Passes if @var{regex} is matched exactly @var{num} times in the test's
2074 assembler output.
2075
2076 @item scan-assembler-dem @var{regex} [@{ target/xfail @var{selector} @}]
2077 Passes if @var{regex} matches text in the test's demangled assembler output.
2078
2079 @item scan-assembler-dem-not @var{regex} [@{ target/xfail @var{selector} @}]
2080 Passes if @var{regex} does not match text in the test's demangled assembler
2081 output.
2082
2083 @item scan-hidden @var{symbol} [@{ target/xfail @var{selector} @}]
2084 Passes if @var{symbol} is defined as a hidden symbol in the test's
2085 assembly output.
2086
2087 @item scan-not-hidden @var{symbol} [@{ target/xfail @var{selector} @}]
2088 Passes if @var{symbol} is not defined as a hidden symbol in the test's
2089 assembly output.
2090 @end table
2091
2092 @subsubsection Scan optimization dump files
2093
2094 These commands are available for @var{kind} of @code{tree}, @code{rtl},
2095 and @code{ipa}.
2096
2097 @table @code
2098 @item scan-@var{kind}-dump @var{regex} @var{suffix} [@{ target/xfail @var{selector} @}]
2099 Passes if @var{regex} matches text in the dump file with suffix @var{suffix}.
2100
2101 @item scan-@var{kind}-dump-not @var{regex} @var{suffix} [@{ target/xfail @var{selector} @}]
2102 Passes if @var{regex} does not match text in the dump file with suffix
2103 @var{suffix}.
2104
2105 @item scan-@var{kind}-dump-times @var{regex} @var{num} @var{suffix} [@{ target/xfail @var{selector} @}]
2106 Passes if @var{regex} is found exactly @var{num} times in the dump file
2107 with suffix @var{suffix}.
2108
2109 @item scan-@var{kind}-dump-dem @var{regex} @var{suffix} [@{ target/xfail @var{selector} @}]
2110 Passes if @var{regex} matches demangled text in the dump file with
2111 suffix @var{suffix}.
2112
2113 @item scan-@var{kind}-dump-dem-not @var{regex} @var{suffix} [@{ target/xfail @var{selector} @}]
2114 Passes if @var{regex} does not match demangled text in the dump file with
2115 suffix @var{suffix}.
2116 @end table
2117
2118 @subsubsection Verify that an output files exists or not
2119
2120 @table @code
2121 @item output-exists [@{ target/xfail @var{selector} @}]
2122 Passes if compiler output file exists.
2123
2124 @item output-exists-not [@{ target/xfail @var{selector} @}]
2125 Passes if compiler output file does not exist.
2126 @end table
2127
2128 @subsubsection Check for LTO tests
2129
2130 @table @code
2131 @item scan-symbol @var{regexp} [@{ target/xfail @var{selector} @}]
2132 Passes if the pattern is present in the final executable.
2133 @end table
2134
2135 @subsubsection Checks for @command{gcov} tests
2136
2137 @table @code
2138 @item run-gcov @var{sourcefile}
2139 Check line counts in @command{gcov} tests.
2140
2141 @item run-gcov [branches] [calls] @{ @var{opts} @var{sourcefile} @}
2142 Check branch and/or call counts, in addition to line counts, in
2143 @command{gcov} tests.
2144 @end table
2145
2146 @subsubsection Clean up generated test files
2147
2148 @table @code
2149 @item cleanup-coverage-files
2150 Removes coverage data files generated for this test.
2151
2152 @item cleanup-ipa-dump @var{suffix}
2153 Removes IPA dump files generated for this test.
2154
2155 @item cleanup-modules "@var{list-of-extra-modules}"
2156 Removes Fortran module files generated for this test, excluding the
2157 module names listed in keep-modules.
2158 Cleaning up module files is usually done automatically by the testsuite
2159 by looking at the source files and removing the modules after the test
2160 has been executed.
2161 @smallexample
2162 module MoD1
2163 end module MoD1
2164 module Mod2
2165 end module Mod2
2166 module moD3
2167 end module moD3
2168 module mod4
2169 end module mod4
2170 ! @{ dg-final @{ cleanup-modules "mod1 mod2" @} @} ! redundant
2171 ! @{ dg-final @{ keep-modules "mod3 mod4" @} @}
2172 @end smallexample
2173
2174 @item keep-modules "@var{list-of-modules-not-to-delete}"
2175 Whitespace separated list of module names that should not be deleted by
2176 cleanup-modules.
2177 If the list of modules is empty, all modules defined in this file are kept.
2178 @smallexample
2179 module maybe_unneeded
2180 end module maybe_unneeded
2181 module keep1
2182 end module keep1
2183 module keep2
2184 end module keep2
2185 ! @{ dg-final @{ keep-modules "keep1 keep2" @} @} ! just keep these two
2186 ! @{ dg-final @{ keep-modules "" @} @} ! keep all
2187 @end smallexample
2188
2189 @item cleanup-profile-file
2190 Removes profiling files generated for this test.
2191
2192 @item cleanup-repo-files
2193 Removes files generated for this test for @option{-frepo}.
2194
2195 @item cleanup-rtl-dump @var{suffix}
2196 Removes RTL dump files generated for this test.
2197
2198 @item cleanup-saved-temps
2199 Removes files for the current test which were kept for @option{-save-temps}.
2200
2201 @item cleanup-tree-dump @var{suffix}
2202 Removes tree dump files matching @var{suffix} which were generated for
2203 this test.
2204 @end table
2205
2206 @node Ada Tests
2207 @section Ada Language Testsuites
2208
2209 The Ada testsuite includes executable tests from the ACATS
2210 testsuite, publicly available at
2211 @uref{http://www.ada-auth.org/acats.html}.
2212
2213 These tests are integrated in the GCC testsuite in the
2214 @file{ada/acats} directory, and
2215 enabled automatically when running @code{make check}, assuming
2216 the Ada language has been enabled when configuring GCC@.
2217
2218 You can also run the Ada testsuite independently, using
2219 @code{make check-ada}, or run a subset of the tests by specifying which
2220 chapter to run, e.g.:
2221
2222 @smallexample
2223 $ make check-ada CHAPTERS="c3 c9"
2224 @end smallexample
2225
2226 The tests are organized by directory, each directory corresponding to
2227 a chapter of the Ada Reference Manual. So for example, @file{c9} corresponds
2228 to chapter 9, which deals with tasking features of the language.
2229
2230 There is also an extra chapter called @file{gcc} containing a template for
2231 creating new executable tests, although this is deprecated in favor of
2232 the @file{gnat.dg} testsuite.
2233
2234 The tests are run using two @command{sh} scripts: @file{run_acats} and
2235 @file{run_all.sh}. To run the tests using a simulator or a cross
2236 target, see the small
2237 customization section at the top of @file{run_all.sh}.
2238
2239 These tests are run using the build tree: they can be run without doing
2240 a @code{make install}.
2241
2242 @node C Tests
2243 @section C Language Testsuites
2244
2245 GCC contains the following C language testsuites, in the
2246 @file{gcc/testsuite} directory:
2247
2248 @table @file
2249 @item gcc.dg
2250 This contains tests of particular features of the C compiler, using the
2251 more modern @samp{dg} harness. Correctness tests for various compiler
2252 features should go here if possible.
2253
2254 Magic comments determine whether the file
2255 is preprocessed, compiled, linked or run. In these tests, error and warning
2256 message texts are compared against expected texts or regular expressions
2257 given in comments. These tests are run with the options @samp{-ansi -pedantic}
2258 unless other options are given in the test. Except as noted below they
2259 are not run with multiple optimization options.
2260 @item gcc.dg/compat
2261 This subdirectory contains tests for binary compatibility using
2262 @file{lib/compat.exp}, which in turn uses the language-independent support
2263 (@pxref{compat Testing, , Support for testing binary compatibility}).
2264 @item gcc.dg/cpp
2265 This subdirectory contains tests of the preprocessor.
2266 @item gcc.dg/debug
2267 This subdirectory contains tests for debug formats. Tests in this
2268 subdirectory are run for each debug format that the compiler supports.
2269 @item gcc.dg/format
2270 This subdirectory contains tests of the @option{-Wformat} format
2271 checking. Tests in this directory are run with and without
2272 @option{-DWIDE}.
2273 @item gcc.dg/noncompile
2274 This subdirectory contains tests of code that should not compile and
2275 does not need any special compilation options. They are run with
2276 multiple optimization options, since sometimes invalid code crashes
2277 the compiler with optimization.
2278 @item gcc.dg/special
2279 FIXME: describe this.
2280
2281 @item gcc.c-torture
2282 This contains particular code fragments which have historically broken easily.
2283 These tests are run with multiple optimization options, so tests for features
2284 which only break at some optimization levels belong here. This also contains
2285 tests to check that certain optimizations occur. It might be worthwhile to
2286 separate the correctness tests cleanly from the code quality tests, but
2287 it hasn't been done yet.
2288
2289 @item gcc.c-torture/compat
2290 FIXME: describe this.
2291
2292 This directory should probably not be used for new tests.
2293 @item gcc.c-torture/compile
2294 This testsuite contains test cases that should compile, but do not
2295 need to link or run. These test cases are compiled with several
2296 different combinations of optimization options. All warnings are
2297 disabled for these test cases, so this directory is not suitable if
2298 you wish to test for the presence or absence of compiler warnings.
2299 While special options can be set, and tests disabled on specific
2300 platforms, by the use of @file{.x} files, mostly these test cases
2301 should not contain platform dependencies. FIXME: discuss how defines
2302 such as @code{NO_LABEL_VALUES} and @code{STACK_SIZE} are used.
2303 @item gcc.c-torture/execute
2304 This testsuite contains test cases that should compile, link and run;
2305 otherwise the same comments as for @file{gcc.c-torture/compile} apply.
2306 @item gcc.c-torture/execute/ieee
2307 This contains tests which are specific to IEEE floating point.
2308 @item gcc.c-torture/unsorted
2309 FIXME: describe this.
2310
2311 This directory should probably not be used for new tests.
2312 @item gcc.misc-tests
2313 This directory contains C tests that require special handling. Some
2314 of these tests have individual expect files, and others share
2315 special-purpose expect files:
2316
2317 @table @file
2318 @item @code{bprob*.c}
2319 Test @option{-fbranch-probabilities} using
2320 @file{gcc.misc-tests/bprob.exp}, which
2321 in turn uses the generic, language-independent framework
2322 (@pxref{profopt Testing, , Support for testing profile-directed
2323 optimizations}).
2324
2325 @item @code{gcov*.c}
2326 Test @command{gcov} output using @file{gcov.exp}, which in turn uses the
2327 language-independent support (@pxref{gcov Testing, , Support for testing gcov}).
2328
2329 @item @code{i386-pf-*.c}
2330 Test i386-specific support for data prefetch using @file{i386-prefetch.exp}.
2331 @end table
2332
2333 @item gcc.test-framework
2334 @table @file
2335 @item @code{dg-*.c}
2336 Test the testsuite itself using @file{gcc.test-framework/test-framework.exp}.
2337 @end table
2338
2339 @end table
2340
2341 FIXME: merge in @file{testsuite/README.gcc} and discuss the format of
2342 test cases and magic comments more.
2343
2344 @node libgcj Tests
2345 @section The Java library testsuites.
2346
2347 Runtime tests are executed via @samp{make check} in the
2348 @file{@var{target}/libjava/testsuite} directory in the build
2349 tree. Additional runtime tests can be checked into this testsuite.
2350
2351 Regression testing of the core packages in libgcj is also covered by the
2352 Mauve testsuite. The @uref{http://sourceware.org/mauve/,,Mauve Project}
2353 develops tests for the Java Class Libraries. These tests are run as part
2354 of libgcj testing by placing the Mauve tree within the libjava testsuite
2355 sources at @file{libjava/testsuite/libjava.mauve/mauve}, or by specifying
2356 the location of that tree when invoking @samp{make}, as in
2357 @samp{make MAUVEDIR=~/mauve check}.
2358
2359 To detect regressions, a mechanism in @file{mauve.exp} compares the
2360 failures for a test run against the list of expected failures in
2361 @file{libjava/testsuite/libjava.mauve/xfails} from the source hierarchy.
2362 Update this file when adding new failing tests to Mauve, or when fixing
2363 bugs in libgcj that had caused Mauve test failures.
2364
2365 We encourage developers to contribute test cases to Mauve.
2366
2367 @node LTO Testing
2368 @section Support for testing link-time optimizations
2369
2370 Tests for link-time optimizations usually require multiple source files
2371 that are compiled separately, perhaps with different sets of options.
2372 There are several special-purpose test directives used for these tests.
2373
2374 @table @code
2375 @item @{ dg-lto-do @var{do-what-keyword} @}
2376 @var{do-what-keyword} specifies how the test is compiled and whether
2377 it is executed. It is one of:
2378
2379 @table @code
2380 @item assemble
2381 Compile with @option{-c} to produce a relocatable object file.
2382 @item link
2383 Compile, assemble, and link to produce an executable file.
2384 @item run
2385 Produce and run an executable file, which is expected to return
2386 an exit code of 0.
2387 @end table
2388
2389 The default is @code{assemble}. That can be overridden for a set of
2390 tests by redefining @code{dg-do-what-default} within the @code{.exp}
2391 file for those tests.
2392
2393 Unlike @code{dg-do}, @code{dg-lto-do} does not support an optional
2394 @samp{target} or @samp{xfail} list. Use @code{dg-skip-if},
2395 @code{dg-xfail-if}, or @code{dg-xfail-run-if}.
2396
2397 @item @{ dg-lto-options @{ @{ @var{options} @} [@{ @var{options} @}] @} [@{ target @var{selector} @}]@}
2398 This directive provides a list of one or more sets of compiler options
2399 to override @var{LTO_OPTIONS}. Each test will be compiled and run with
2400 each of these sets of options.
2401
2402 @item @{ dg-extra-ld-options @var{options} [@{ target @var{selector} @}]@}
2403 This directive adds @var{options} to the linker options used.
2404
2405 @item @{ dg-suppress-ld-options @var{options} [@{ target @var{selector} @}]@}
2406 This directive removes @var{options} from the set of linker options used.
2407 @end table
2408
2409 @node gcov Testing
2410 @section Support for testing @command{gcov}
2411
2412 Language-independent support for testing @command{gcov}, and for checking
2413 that branch profiling produces expected values, is provided by the
2414 expect file @file{lib/gcov.exp}. @command{gcov} tests also rely on procedures
2415 in @file{lib/gcc-dg.exp} to compile and run the test program. A typical
2416 @command{gcov} test contains the following DejaGnu commands within comments:
2417
2418 @smallexample
2419 @{ dg-options "-fprofile-arcs -ftest-coverage" @}
2420 @{ dg-do run @{ target native @} @}
2421 @{ dg-final @{ run-gcov sourcefile @} @}
2422 @end smallexample
2423
2424 Checks of @command{gcov} output can include line counts, branch percentages,
2425 and call return percentages. All of these checks are requested via
2426 commands that appear in comments in the test's source file.
2427 Commands to check line counts are processed by default.
2428 Commands to check branch percentages and call return percentages are
2429 processed if the @command{run-gcov} command has arguments @code{branches}
2430 or @code{calls}, respectively. For example, the following specifies
2431 checking both, as well as passing @option{-b} to @command{gcov}:
2432
2433 @smallexample
2434 @{ dg-final @{ run-gcov branches calls @{ -b sourcefile @} @} @}
2435 @end smallexample
2436
2437 A line count command appears within a comment on the source line
2438 that is expected to get the specified count and has the form
2439 @code{count(@var{cnt})}. A test should only check line counts for
2440 lines that will get the same count for any architecture.
2441
2442 Commands to check branch percentages (@code{branch}) and call
2443 return percentages (@code{returns}) are very similar to each other.
2444 A beginning command appears on or before the first of a range of
2445 lines that will report the percentage, and the ending command
2446 follows that range of lines. The beginning command can include a
2447 list of percentages, all of which are expected to be found within
2448 the range. A range is terminated by the next command of the same
2449 kind. A command @code{branch(end)} or @code{returns(end)} marks
2450 the end of a range without starting a new one. For example:
2451
2452 @smallexample
2453 if (i > 10 && j > i && j < 20) /* @r{branch(27 50 75)} */
2454 /* @r{branch(end)} */
2455 foo (i, j);
2456 @end smallexample
2457
2458 For a call return percentage, the value specified is the
2459 percentage of calls reported to return. For a branch percentage,
2460 the value is either the expected percentage or 100 minus that
2461 value, since the direction of a branch can differ depending on the
2462 target or the optimization level.
2463
2464 Not all branches and calls need to be checked. A test should not
2465 check for branches that might be optimized away or replaced with
2466 predicated instructions. Don't check for calls inserted by the
2467 compiler or ones that might be inlined or optimized away.
2468
2469 A single test can check for combinations of line counts, branch
2470 percentages, and call return percentages. The command to check a
2471 line count must appear on the line that will report that count, but
2472 commands to check branch percentages and call return percentages can
2473 bracket the lines that report them.
2474
2475 @node profopt Testing
2476 @section Support for testing profile-directed optimizations
2477
2478 The file @file{profopt.exp} provides language-independent support for
2479 checking correct execution of a test built with profile-directed
2480 optimization. This testing requires that a test program be built and
2481 executed twice. The first time it is compiled to generate profile
2482 data, and the second time it is compiled to use the data that was
2483 generated during the first execution. The second execution is to
2484 verify that the test produces the expected results.
2485
2486 To check that the optimization actually generated better code, a
2487 test can be built and run a third time with normal optimizations to
2488 verify that the performance is better with the profile-directed
2489 optimizations. @file{profopt.exp} has the beginnings of this kind
2490 of support.
2491
2492 @file{profopt.exp} provides generic support for profile-directed
2493 optimizations. Each set of tests that uses it provides information
2494 about a specific optimization:
2495
2496 @table @code
2497 @item tool
2498 tool being tested, e.g., @command{gcc}
2499
2500 @item profile_option
2501 options used to generate profile data
2502
2503 @item feedback_option
2504 options used to optimize using that profile data
2505
2506 @item prof_ext
2507 suffix of profile data files
2508
2509 @item PROFOPT_OPTIONS
2510 list of options with which to run each test, similar to the lists for
2511 torture tests
2512
2513 @item @{ dg-final-generate @{ @var{local-directive} @} @}
2514 This directive is similar to @code{dg-final}, but the
2515 @var{local-directive} is run after the generation of profile data.
2516
2517 @item @{ dg-final-use @{ @var{local-directive} @} @}
2518 The @var{local-directive} is run after the profile data have been
2519 used.
2520 @end table
2521
2522 @node compat Testing
2523 @section Support for testing binary compatibility
2524
2525 The file @file{compat.exp} provides language-independent support for
2526 binary compatibility testing. It supports testing interoperability of
2527 two compilers that follow the same ABI, or of multiple sets of
2528 compiler options that should not affect binary compatibility. It is
2529 intended to be used for testsuites that complement ABI testsuites.
2530
2531 A test supported by this framework has three parts, each in a
2532 separate source file: a main program and two pieces that interact
2533 with each other to split up the functionality being tested.
2534
2535 @table @file
2536 @item @var{testname}_main.@var{suffix}
2537 Contains the main program, which calls a function in file
2538 @file{@var{testname}_x.@var{suffix}}.
2539
2540 @item @var{testname}_x.@var{suffix}
2541 Contains at least one call to a function in
2542 @file{@var{testname}_y.@var{suffix}}.
2543
2544 @item @var{testname}_y.@var{suffix}
2545 Shares data with, or gets arguments from,
2546 @file{@var{testname}_x.@var{suffix}}.
2547 @end table
2548
2549 Within each test, the main program and one functional piece are
2550 compiled by the GCC under test. The other piece can be compiled by
2551 an alternate compiler. If no alternate compiler is specified,
2552 then all three source files are all compiled by the GCC under test.
2553 You can specify pairs of sets of compiler options. The first element
2554 of such a pair specifies options used with the GCC under test, and the
2555 second element of the pair specifies options used with the alternate
2556 compiler. Each test is compiled with each pair of options.
2557
2558 @file{compat.exp} defines default pairs of compiler options.
2559 These can be overridden by defining the environment variable
2560 @env{COMPAT_OPTIONS} as:
2561
2562 @smallexample
2563 COMPAT_OPTIONS="[list [list @{@var{tst1}@} @{@var{alt1}@}]
2564 @dots{}[list @{@var{tstn}@} @{@var{altn}@}]]"
2565 @end smallexample
2566
2567 where @var{tsti} and @var{alti} are lists of options, with @var{tsti}
2568 used by the compiler under test and @var{alti} used by the alternate
2569 compiler. For example, with
2570 @code{[list [list @{-g -O0@} @{-O3@}] [list @{-fpic@} @{-fPIC -O2@}]]},
2571 the test is first built with @option{-g -O0} by the compiler under
2572 test and with @option{-O3} by the alternate compiler. The test is
2573 built a second time using @option{-fpic} by the compiler under test
2574 and @option{-fPIC -O2} by the alternate compiler.
2575
2576 An alternate compiler is specified by defining an environment
2577 variable to be the full pathname of an installed compiler; for C
2578 define @env{ALT_CC_UNDER_TEST}, and for C++ define
2579 @env{ALT_CXX_UNDER_TEST}. These will be written to the
2580 @file{site.exp} file used by DejaGnu. The default is to build each
2581 test with the compiler under test using the first of each pair of
2582 compiler options from @env{COMPAT_OPTIONS}. When
2583 @env{ALT_CC_UNDER_TEST} or
2584 @env{ALT_CXX_UNDER_TEST} is @code{same}, each test is built using
2585 the compiler under test but with combinations of the options from
2586 @env{COMPAT_OPTIONS}.
2587
2588 To run only the C++ compatibility suite using the compiler under test
2589 and another version of GCC using specific compiler options, do the
2590 following from @file{@var{objdir}/gcc}:
2591
2592 @smallexample
2593 rm site.exp
2594 make -k \
2595 ALT_CXX_UNDER_TEST=$@{alt_prefix@}/bin/g++ \
2596 COMPAT_OPTIONS="@var{lists as shown above}" \
2597 check-c++ \
2598 RUNTESTFLAGS="compat.exp"
2599 @end smallexample
2600
2601 A test that fails when the source files are compiled with different
2602 compilers, but passes when the files are compiled with the same
2603 compiler, demonstrates incompatibility of the generated code or
2604 runtime support. A test that fails for the alternate compiler but
2605 passes for the compiler under test probably tests for a bug that was
2606 fixed in the compiler under test but is present in the alternate
2607 compiler.
2608
2609 The binary compatibility tests support a small number of test framework
2610 commands that appear within comments in a test file.
2611
2612 @table @code
2613 @item dg-require-*
2614 These commands can be used in @file{@var{testname}_main.@var{suffix}}
2615 to skip the test if specific support is not available on the target.
2616
2617 @item dg-options
2618 The specified options are used for compiling this particular source
2619 file, appended to the options from @env{COMPAT_OPTIONS}. When this
2620 command appears in @file{@var{testname}_main.@var{suffix}} the options
2621 are also used to link the test program.
2622
2623 @item dg-xfail-if
2624 This command can be used in a secondary source file to specify that
2625 compilation is expected to fail for particular options on particular
2626 targets.
2627 @end table
2628
2629 @node Torture Tests
2630 @section Support for torture testing using multiple options
2631
2632 Throughout the compiler testsuite there are several directories whose
2633 tests are run multiple times, each with a different set of options.
2634 These are known as torture tests.
2635 @file{lib/torture-options.exp} defines procedures to
2636 set up these lists:
2637
2638 @table @code
2639 @item torture-init
2640 Initialize use of torture lists.
2641 @item set-torture-options
2642 Set lists of torture options to use for tests with and without loops.
2643 Optionally combine a set of torture options with a set of other
2644 options, as is done with Objective-C runtime options.
2645 @item torture-finish
2646 Finalize use of torture lists.
2647 @end table
2648
2649 The @file{.exp} file for a set of tests that use torture options must
2650 include calls to these three procedures if:
2651
2652 @itemize @bullet
2653 @item It calls @code{gcc-dg-runtest} and overrides @var{DG_TORTURE_OPTIONS}.
2654
2655 @item It calls @var{$@{tool@}}@code{-torture} or
2656 @var{$@{tool@}}@code{-torture-execute}, where @var{tool} is @code{c},
2657 @code{fortran}, or @code{objc}.
2658
2659 @item It calls @code{dg-pch}.
2660 @end itemize
2661
2662 It is not necessary for a @file{.exp} file that calls @code{gcc-dg-runtest}
2663 to call the torture procedures if the tests should use the list in
2664 @var{DG_TORTURE_OPTIONS} defined in @file{gcc-dg.exp}.
2665
2666 Most uses of torture options can override the default lists by defining
2667 @var{TORTURE_OPTIONS} or add to the default list by defining
2668 @var{ADDITIONAL_TORTURE_OPTIONS}. Define these in a @file{.dejagnurc}
2669 file or add them to the @file{site.exp} file; for example
2670
2671 @smallexample
2672 set ADDITIONAL_TORTURE_OPTIONS [list \
2673 @{ -O2 -ftree-loop-linear @} \
2674 @{ -O2 -fpeel-loops @} ]
2675 @end smallexample