JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


GNU Compiler Models

There are two GNU compiler models: gcc and gpp.



Overview

The following file extensions are supported:

Compiler
model
Modeled native compiler Source file extensions Description
gcc GNU's C/C++ compiler. .c, .C, .cc, .cpp, .cxx, .c++, .i, .ii Source file extensions indicate the source language unless the language is explicitly specified using the -x flag. An extension of (lower case) c or i indicates C; all other extensions (including capital C) indicate C++.
gpp GNU's C/C++ compiler .c, .C, .cc, .cpp, .cxx, .c++, .i, .ii Always compiles the source file as C++ unless the language is explicitly specified using the -x flag.

Availability

Platform Availability The gcc and gpp compiler models are available for all platforms.
Default Recognition/Handling By default, compilations are recognized and handled as follows.
Platform Native Compiler Model Used
All arm-none-eabi-g++(.exe) gpp
All arm-none-eabi-gcc(.exe) gcc
All g++(.exe) gpp
All gcc(.exe) gcc
All gpp(.exe) gpp
All gxx(.exe) gpp
Non-Windows systems only c++ gpp
Windows only g++-3.exe gpp
Windows only g++-4.exe gpp
Windows only gcc-3.exe gcc
Windows only gcc-4.exe gcc
Windows only i686-pc-mingw32-g++.exe gpp
Windows only i686-pc-mingw32-gcc.exe gcc
Windows only x86_64-pc-mingw32-g++.exe gpp
Windows only x86_64-pc-mingw32-gcc.exe gcc
Specifying Additional Mappings If your compiler executable has a different name, specify a corresponding COMPILER_MODELS rule to map your executable name to the gcc or gpp model.

For full details of all native compilers recognized by CodeSonar by default, see section Compilers Recognized by CodeSonar.

Model-Specific ABI Key Format

The model-specific ABI key format for the gcc and gpp compiler models is:

<pointer_size>.<gcc_version>.<gnu_mode>.<gcc_invoke>[.<user_string>]

as

int.int.{0,1}.{0,1}[.string]

If an ABI key with this format is specified for a compilation that is modeled with the gcc or gpp compiler model, the following settings will be applied.

Example

Suppose we are building a CodeSonar project where:

Then the mycc compilation will be modeled by the gcc compiler model, with the following settings.

For more information, see Compiler Models: ABI Keys.

Command Arguments

The following command arguments are interpreted by the gcc and gpp compiler models. Arguments are passed to the gcc invocation that determines predefined macros and include paths unless otherwise noted.

Argument Additional Treatment in Model
name.ext If ext is one of the file extensions recognized by the given compiler model, preprocess and compile the source file name.ext.
@ file
@file
Extracts the options specified in file and appends them to the command line. The @ argument is not passed to gcc.
-ansi
--ansi
Additional handling depends on the modeled compilation mode.
C Mode
C++ Mode
  • Specifies front end option --c++03.
  • Defines macro __STRICT_ANSI__=1.
-arch arg Additional treatment depends on arg as follows.
arg Additional Treatment
ppc
i386
Treat as a compilation to 32-bit target.
ppc64
x86_64
Treat as a compilation to 64-bit target.
other arg No additional handling (but passed to gcc invocation).
-aux_info arg Passed to gcc invocation; no additional handling.
-b arg Passed to gcc invocation; no additional handling.
-C Specifies front end option -C.
-coverage-file arg Passed to gcc invocation; no additional handling.
-D macro
-Dmacro
Defines macro macro to 1. See note on -D, -U evaluation order.
-Dmacro=defn Defines macro macro with defn as its definition. See note on -D, -U evaluation order.
-dependency-file arg Passed to gcc invocation; no additional handling.
-dumpbase arg Passed to gcc invocation; no additional handling.
-dumpbase-ext arg Passed to gcc invocation; no additional handling.
-dumpdir arg Passed to gcc invocation; no additional handling.
-e arg Passed to gcc invocation; no additional handling.
--entry arg Passed to gcc invocation; no additional handling.
-fabi-version
-fabi-version=
-fabi-version=arg
Additional treatment depends on arg as follows.
arg Additional Treatment
1 Use C++ ABI version as for gcc 3.2.
2 Use C++ ABI version as for gcc 3.4.
otherwise
(including no arg)
Use C++ ABI version as for most recent version of gcc.
-fcommon Specifies front end option --default_common_tentative_definitions.
-fdebug-compilation-dir arg Passed to gcc invocation; no additional handling.
-fdollars-in-identifiers Specifies front end option --dollar.
-ferror-limit arg Passed to gcc invocation; no additional handling.
-fexceptions Specifies front end option --exceptions.
-fextended-identifiers Specifies front end option --cs_universal_character_names_allowed.
-ffor-scope Specifies front end option --new_for_init.
-fgnu89-inline Additional handling for C compilations only: specifies front end option --gcc89_inlining, unless
-fimplicit-templates Additional handling for C++ compilations only: specifies front end option --instantiate used, unless there is a subsequent occurrence of -fno-implicit-templates.
-flax-vector-conversions Specifies front end option --cs_allow_gnu_vector_conversion.
-fmacro-backtrace-limit arg Passed to gcc invocation; no additional handling.
-fmessage-length arg Passed to gcc invocation; no additional handling.
-fms-compatibility Specifes front end option --ms_compatibility.
-fms-extensions Specifes front end option --ms_extensions.
-fopenmp Specifies front end option --cs_ext_openmp.
-force-include-file arg Passed to gcc invocation; no additional handling.
-fno-common Specifies front end option --default_nocommon_tentative_definitions.
-fno-exceptions Specifies front end option --no_exceptions.
-fno-for-scope Specifies front end option --old_for_init.
-fno-gnu89-inline Supersedes any previous occurrence of -fgnu89-inline.
-fno-implicit-templates Additional handling for C++ compilations only: specifies front end option --instantiate none, unless there is a subsequent occurrence of -fimplicit-templates. In all other C++ compilations, specifies --instantiate used.
-fno-rtti Specifies front end option --no_rtti.
-fno-short-enums Supersedes any previous occurrence of -fshort-enums.
-fno-signed-bitfields Specifies front end option --cs_targ_plain_int_bit_field_is_unsigned.
-fno-unsigned-bitfields Specifies front end option --cs_targ_plain_int_bit_field_is_signed.
-fpack-struct
-fpack-struct=
-fpack-struct=val
If val is present, specifies front end option --pack_alignment=val. If val is not present, specifies front end option --pack_alignment=1.
-frtti Specifies front end option --rtti.
-fshort-double Specifies front end option --cs_short_double.
-fshort-enums Specifies front end option --short_enums, unless there is a subsequent occurrence of -fno-short-enums.
-fshort-wchar Specifies front end option --cs_targ_wchar_t_int_kind=unsigned_short.
-fsigned-bitfields Specifies front end option --cs_targ_plain_int_bit_field_is_signed.
-fsigned-char Specifies front end option --signed_chars.
-fsyntax-only Specifies front end option --no_code_gen.
-ftemplate-depth num Additional handling in C++ compilations only: specifies front end option --pending_instantiations num.
-ftemplate-depth- num Additional handling in C++ compilations only: specifies front end option --pending_instantiations num.
-funsigned-bitfields Specifies front end option --cs_targ_plain_int_bit_field_is_unsigned.
-funsigned-char Specifies front end option --unsigned_chars.
-fvisibility arg Passed to gcc invocation; no additional handling.
-G arg Passed to gcc invocation; no additional handling.
-H Specifies front end option -H.
-I dir
-Idir
Specifies front end option -Idir.
-I- For all occurrences of -Idir before before -I-, dir is searched only for include files specified with #include "fname" (not #include <fname>).
-idirafter dir
-idirafterdir
Specifies front end option --sys_include dir.
-imacros arg Passed to gcc invocation; no additional handling.
-include hfile
--include hfile
Specifies front end option --preinclude hfile.
-include-pch arg Passed to gcc invocation; no additional handling.
-iprefix arg Passed to gcc invocation; no additional handling.
-iquote dir
-iquotedir
Appends dir to the list of system include directories to be searched only for include files specified with #include "fname" (not #include <fname>).
-isysroot dir
-isysrootdir
Passed to gcc invocation; no additional handling.
-isystem dir
-isystemdir
Prepends directory dir to the list of system include directories using front end option --sys_include dir.
-iwithprefix arg Passed to gcc invocation; no additional handling.
-iwithprefixdir arg Passed to gcc invocation; no additional handling.
-marg Additional treatment depends on arg as follows.
arg Additional Treatment
32 Treat as a compilation to 32-bit target.
64 Treat as a compilation to 64-bit target.
other No additional handling (but passed to gcc invocation).
-main-file-name arg Passed to gcc invocation; no additional handling.
-MF arg Passed to gcc invocation; no additional handling.
-MQ arg Passed to gcc invocation; no additional handling.
-mrelocation-model arg Passed to gcc invocation; no additional handling.
-MT arg Passed to gcc invocation; no additional handling.
-nostdinc Passed to gcc invocation; no additional handling.
-nostdinc++ Passed to gcc invocation; no additional handling.
-O
-Oarg
Additional treatment depends on arg as follows.
arg Additional Treatment
0 No additional handling (but passed to gcc invocation).
s Defines macros __OPTIMIZE__=1 and __OPTIMIZE_SIZE__=1; specifies front end option --optimize.
other (including empty) Defines macro __OPTIMIZE__=1 and __OPTIMIZE_SIZE__=1; specifies front end option --optimize.
-pic-level arg Passed to gcc invocation; no additional handling.
-resource-dir arg Passed to gcc invocation; no additional handling.
-serialize-diagnostic-file arg Passed to gcc invocation; no additional handling.
-stack-protector arg Passed to gcc invocation; no additional handling.
-std=arg
-std arg
--std=arg
--std arg
Always passed to the gcc invocation. Additional treatment depends on arg and on the modeled compilation mode as follows: if there are multiple occurences of -std arg, the last one is used. In most cases, the applicable C or C++ standard also depends on arg.
arg Additional Treatment Standard
C Mode C++ Mode C C++
c89
Specifies front end options --no_alternative_tokens, --no_restrict, and --c89. no additional handling C89 -

c90
iso9899:1990
Specifies front end options --no_alternative_tokens, --no_restrict, and --c89. no additional handling C90 -
iso9899:199409 no additional handling no additional handling C90 -
gnu89
gnu90
no additional handling no additional handling C90 -
c99
c9x
gnu99
gnu9x
iso9899:1999
iso9899:199x
Specifies front end option --c99. no additional handling C99 -
c11
c1x
gnu11
gnu1x
iso9899:2011
Specifies front end option --c11. no additional handling C11 -
c17
c18
gnu17
gnu18
iso9899:2017
iso9899:2018
Specifies front end option --c18. no additional handling C18 -
c2x Specifies front end option --c18. no additional handling C18 -
c++98
gnu++98
no additional handling no additional handling - C++98
c++03
gnu++03
no additional handling Specifies front end option --c++03. - C++03
c++0x
gnu++0x
no additional handling Specifies front end option --c++0x. - C++0x
c++11
gnu++11
no additional handling Specifies front end option --c++11. - C++11
c++14
c++1y
gnu++14
gnu++1y
no additional handling Specifies front end option --c++14. - C++14
c++17
c++1z
gnu++17
gnu++1z
no additional handling Specifies front end option --c++17. - C++17
c++20
c++2a
gnu++20
gnu++2a
no additional handling Specifies front end option --c++20. - C++20
other arg no additional handling no additional handling - -

Note that C standard settings are not used by the gcc and gpp models themselves, but are used by some models based on the gcc model (in particular, the Clang compiler models).

-sysrootdir
-sysrootdir
Passed to gcc invocation; no additional handling.
-T arg Passed to gcc invocation; no additional handling.
-target-cpu arg Passed to gcc invocation; no additional handling.
-target-linker-version arg Passed to gcc invocation; no additional handling.
-trigraphs Specifies front end option --trigraphs.
-triple arg Passed to gcc invocation; no additional handling.
-U macro
-Umacro
Undefines macro macro. See note on -D, -U evaluation order.
-u arg Passed to gcc invocation; no additional handling.
-V arg Passed to gcc invocation; no additional handling.
-v Passed to gcc invocation; no additional handling.
-w Specifies front end option -w.
-Wall
-Werror
Passed to gcc invocation; records that the flag has been seen so that this information can be subsequently used by the Not All Warnings Are Enabled and Warnings Not Treated As Errors checkers.
-Wno-* Passed to gcc invocation; no additional handling.
-Wp,arglist arglist passed to preprocessor; no additional handling.
-x lang
-xlang
Additional treatment depends on lang as follows.
lang Handling in model
Mode for native gcc invocation (if any) Modeled compilation mode
none both C and C++ modes The model will determine the mode from the source file extension.
c
cpp-output
C mode only C mode
c++
c++-cpp-output
C++ mode only C++ mode
other lang CodeSonar will not build a project, or generate any internal representation.
-x not specified The model will determine the mode from the source file extension.
-Xlinker arg Passed to gcc invocation; no additional handling.
-Xpreprocessor arg arg passed to preprocessor; no additional handling.
-z arg Passed to gcc invocation; no additional handling.

Compilation Mode

The modeled compilation mode is determined as follows.

In some cases, the modeled effect of individual command arguments is mode-dependent. These cases are noted in the table above.

C and C++ Standards

The gcc and gpp models have some behaviors that depend on the determined C++ standard, but do not make use of the determined C standard. However, some compiler models based on the gcc model (in particular, the Clang compiler models) make use of both.

The applicable C or C++ standard for the modeled compilation is determined as follows.

Note on -D, -U evaluation order

The evaluation order for -D and -U instances on the command line depends on the version being used.

GNU 3.0 and later Instances of -D and -U on the command line are processed in order of appearance.
Earlier versions All instances of -D on the command line are processed before any -U instances.

No CodeSonar Build

If any of the following are specified, CodeSonar will ignore the compilation and will not generate any corresponding internal representation. If a CodeSonar project is based only on ignored compilations, it will have no contents and so will not be finalized.

Predefined Macros and Include Paths

By default, the gcc and gpp compiler models invoke the modeled native compiler to extract the location of its configuration files, and use this to set up the include path and predefined macros.

These native compiler invocations can be specifically disabled using a special-format ABI key.

Additional predefined macros and include paths are listed below.

Macros The standard CodeSonar predefined macros are defined. Other macros are generally defined by compiler configuration files.
Macros Conditionally Defined
__STRICT_ANSI__ =1 if -ansi is specified.
__OPTIMIZE__ =1 if -O is specified without an argument, or with an argument other than 0.
__OPTIMIZE_SIZE__ =1 if -O is specified without an argument, or with an argument other than 0.
Include Paths Defined by compiler configuration files.
Front End Options Always Specified
Always specified for C compilations:
--gcc unless 'GNU mode' is specifically disabled (via a special-format ABI key)
Always specified for C++ compilations:
--g++ unless 'GNU mode' is specifically disabled (via a special-format ABI key)
--pending_instantiations num Where num is determined by -ftemplate-depth num or -ftemplate-depth-num if specified; 900 otherwise.
--instantiate [used|none] Argument is none if -fno-implicit-templates is specified with no subsequent occurrence of -fimplicit-templates, used in all other cases.
--warn_exception_specification_difference  
Front End Options Conditionally Specified
-C if -C is specified.
--c++03 [C++ compilations only] if -ansi is specified, or -std arg is specified for arg in {c++03,gnu++03}
--c++0x [C++ compilations only] if -std arg is specified for arg in {c++0x,gnu++0x}
--c++11 [C++ compilations only] if -std arg is specified for arg in {c++11,gnu++11}
--c++14 [C++ compilations only] if -std arg is specified for arg in {c++14,c++1y,gnu++14,gnu++1y}, or -std is not specified and the model determines that the GNU version is 6.0 or later.
--c++17 [C++ compilations only] if -std arg is specified for arg in {c++17,c++1z,gnu++17,gnu++1z}
--c++20 [C++ compilations only] if -std arg is specified for arg in {c++20,c++2a,gnu++20,gnu++2a}
--c11 [C compilations only] if -std arg is specified for arg in {c11,c1x,gnu11,gnu1x}, or -std is not specified and the model determines that the GNU version is 5.1 or later.
--c18 [C compilations only] if -std arg is specified for arg in {c17,c18,c2x,gnu17,gnu18,iso9899:2017,iso9899:2018}.
--c89 [C compilations only] if any of the following are specified.
--c99 [C compilations only] if -std arg is specified for arg in {c99,c9x,gnu99,gnu9x,iso9899:1999,iso9899:199x}
--cs_allow_gnu_vector_conversion if -flax-vector-conversions is specified.
--cs_cygwin_path_translation Windows only.
--cs_ext_openmp if -fopenmp is specified.
--cs_fold_expressions [C++ compilations only] if the model determines that the applicable C++ standard is C++0x or later
--cs_short_double if -fshort-double is specified.
--cs_struct_bindings [C++ compilations only] if the model determines that the GNU version is 7.1 or later and the applicable C++ standard is C++0x or later
--cs_targ_plain_int_bit_field_is_unsigned if -fno-signed-bitfields or -funsigned-bitfields is specified.
--cs_targ_plain_int_bit_field_is_signed if -fno-unsigned-bitfields or -fsigned-bitfields is specified.
--cs_targ_wchar_t_int_kind=unsigned_short if -fshort-wchar is specified.
--cs_universal_character_names_allowed if -fextended-identifiers is specified.
--cs_variadic_using_decls [C++ compilations only] if the model determines that the GNU version is 7.1 or later.
--default_common_tentative_definitions if -fcommon is specified.
--default_nocommon_tentative_definitions if -fno-common is specified.
--dollar if -fdollars-in-identifiers is specified.
--exceptions if -fexceptions is specified.
--gcc89_inlining [C compilations only] if -fgnu89-inline is specified with no subsequent occurrence of -fno-gnu89-inline.
-H if -H is specified.
--ms_compatibility if -fms-compatibility is specified.
--ms_extensions if -fms-extensions is specified.
--new_for_init if -ffor-scope is specified.
--no_alternative_tokens [C compilations only] if any of the following are specified.
--no_code_gen if -fsyntax-only is specified.
--no_exceptions if -fno-exceptions is specified.
--no_restrict [C compilations only] if any of the following are specified.
--no_rtti if -fno-rtti is specified.
--old_for_init if -fno-for-scope is specified.
--optimize if -O is specified without an argument, or with an argument other than 0 (zero).
--pack_alignment=val if -fpack-struct is specified, with val depending on the argument to -fpack-struct.
--preinclude hfile if -include hfile or is specified.
--rtti if -frtti is specified.
--short_enums if -fshort-enums is specified with no subsequent occurrence of -fno-short-enums.
--signed_chars if -fsigned-char is specified.
--sys_include dir if -idirafter dir or -isystem dir is specified.
--trigraphs if -trigraphs is specified.
--unicode_source_kind UTF-8 Windows only.
--unsigned_chars if -funsigned-char is specified.
 

To report problems with this documentation, please visit https://support.codesecure.com/.