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++


The cl Compiler Model

The Windows cl compiler model models the behavior of the Microsoft Visual C compiler.



Overview

The cl compiler model supports the following file extensions:

Compiler
model
Modeled native compiler Source file extensions Description
cl cl .c, .cpp, .cxx (case insensitive) Microsoft's C/C++ compiler. Source file extensions indicate the source language. Extension .c indicates the C language; extensions .cpp and .cxx indicate C++. The language can be explicitly specified by /TC or /Tcfile (for C) or /TP or /Tpfile (for C++).

Availability

Platform Availability The cl compiler model is available for all platforms.
Default Recognition/Handling By default, compilations are recognized and handled as follows.
Platform Native Compiler Model Used
Windows only cl.exe cl
Windows only clarm.exe cl
Windows only clmips.exe cl
Windows only clsh.exe cl
Windows only clthumb.exe cl
Specifying Additional Mappings If your compiler executable has a different name, specify a corresponding COMPILER_MODELS rule to map your executable name to the cl 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 cl compiler model is:

<build_target>.<cl_version>.<cl_build>[.<user_string>]

as

{x86,x64,itanium,arm}.int.int[.string]

If an ABI key with this format is specified for a compilation that is modeled with the cl compiler model, the following settings will be applied. These settings take precedence over those determined by invoking cl.

Example

Suppose we want to specify that cl compilations should be modeled as if the target is x64, the cl version is 1600, and the cl build number is 40219 (that is, Visual C++ 10.0 SP1). Then we add the following rule to the configuration file.

COMPILER_MODELS += cl.exe -> cl:x64.1600.40219

For more information, see Compiler Models: ABI Keys.

Command Arguments

The following table lists command arguments that receive additional treatment in the cl compiler model.

Argument Additional Treatment in Model
@file Extracts the options specified in file and appends them to the command line.
/AIdirname -AIdirname Passed to native compiler invocation; no additional handling in model.
/arch[:arg] -arch[:arg] Controls value of macro _M_IX86_FP.
/await -await Specifies front end option --ms_await.
/C -C Specifies front end option -C.
/clr[:arg] -clr[:arg] Handling depends on the version and on the value of arg if specified, as shown in the following table.
version arg handling
version < Visual Studio 2005 any value, including no :arg CodeSonar will ignore the compilation and will not generate any corresponding internal representation.
Visual Studio 2005 ≤ version < Visual Studio 2015 oldSyntax CodeSonar will ignore the compilation and will not generate any corresponding internal representation.
any other value, including no :arg Specifies front end option --cppcli and defines macros __abstract, __delegate, __gc, __nogc, __pin, __property, __sealed, and __value.
Visual Studio 2015 ≤ version oldSyntax CodeSonar will ignore the compilation and will not generate any corresponding internal representation.
any other value, including no :arg Specifies front end option --cppcli.
/constexpr:deptharg
/constexpr:backtracearg
/constexpr:stepsarg
-constexpr:deptharg
-constexpr:backtracearg
-constexpr:stepsarg
Passed to native compiler invocation; no additional handling in model.
/Dmacro -Dmacro Defines macro macro to 1. See note on /D, /U evaluation order.
/Dmacro=defn -Dmacro=defn Defines macro macro with defn as its definition. See note on /D, /U evaluation order.
/EHa -EHa Defines macro _CPPUNWIND.
/EHa- -EHa- Undefines macro _CPPUNWIND.
/EHs -EHs Defines macro _CPPUNWIND.
/EHs- -EHs- Undefines macro _CPPUNWIND.
/experimental:preprocessor -experimental:preprocessor Specifies front end option --ms_std_preprocessor.
/Farg -Farg Passed to native compiler invocation; no additional handling in model.
/Feprojname -Feprojname Sets the CodeSonar project name to projname.
/FIfilename -FIfilename Specifies front end option --preinclude filename.
/Fparg -Fparg Specifies front end option --cs_pch_name arg.
/FUfilename -FUfilename Specifies front end option --preusing filename.
/G5 -G5
  • [32-bit] Defines macro _M_IX86=500
  • [64-bit] Defines macro _M_IA64
/G6 -G6
  • [32-bit] Defines macro _M_IX86=600
  • [64-bit] Defines macro _M_IA64
/G7 -G7
  • [32-bit] Defines macro _M_IX86=700
  • [64-bit] Defines macro _M_IA64
/GB -GB
  • [32-bit] Defines macro _M_IX86=600
  • [64-bit] Defines macro _M_IA64
/Gd -Gd Specifies front end option --default_calling_convention __cdecl.
/Gr -Gr Specifies front end option --default_calling_convention __stdcall.
/GR -GR Defines macro _CPPRTTI and specifies front end option --rtti.
/GR- -GR- Affects definition of macro _CPPRTTI.
/GX -GX Defines macro _CPPUNWIND.
/GX- -GX- Undefines macro _CPPUNWIND.
/Gz -Gz Specifies front end option --default_calling_convention __fastcall.
/Harg -Harg Passed to native compiler invocation; no additional handling in model.
/Idir -Idir Append directory dir to the list of directories searched for include files.
/J -J Defines macro _CHAR_UNSIGNED and specifies front end option --unsigned_chars.
/kernel -kernel Specifies front end options --no_exceptions and --no_rtti; defines macro _KERNEL_MODE.
/kernel- -kernel- Any earlier occurrence of /kernel will not incur the described additional treatment.
/LDd -LDd If version is Visual C++ 7.0 or later, defines macro _DEBUG.
/MD, /MDd -MD, -MDd Defines macros _DLL and _MT. If /MDd, also defines macro _DEBUG.
/MLd -MLd Defines macro _DEBUG.
/MT, /MTd -MT, -MTd Defines macro_MT. If /MTd, also defines macro _DEBUG.
/openmp -openmp If version is Visual Studio 2005 or later, defines macro _OPENMP=200203.
/RTC -RTC Defines macro__MSVC_RUNTIME_CHECKS=1.
/std:c11 -std:c11 Specifies front end option --ms_c11.
/std:c17 -std:c17 Specifies front end option --c17.
/std:c++14 -std:c++14 Specifies front end option --ms_c++14; affects setting of macro _MSVC_LANG.
/std:c++17 -std:c++17 Specifies front end option --ms_c++17; affects setting of macro _MSVC_LANG.
/std:c++latest -std:c++latest Specifies front end option --ms_c++latest; affects setting of macro _MSVC_LANG.
/TC -TC Compile all files as C (takes precedence over /Tpfname).
/Tcfname -Tcfname Treat fname as a C source file.
/TP -TP Compile all files as C++ (takes precedence over /Tcfname ).
/Tpfname -Tpfname Treat fname as a C++ source file.
/Umacro -Umacro Undefines macro macro. See note on /D, /U evaluation order.
/Varg -Varg Passed to native compiler invocation; no additional handling in model.
/w -w Passed to native compiler invocation; no additional handling in model.
/w1arg
/w2arg
/w3arg
/w4arg
-w1arg
-w2arg
-w3arg
-w4arg
Passed to native compiler invocation; no additional handling in model.
/wdarg
/woarg
-wdarg
-woarg
Passed to native compiler invocation; no additional handling in model.
/Wearg -Wearg Passed to native compiler invocation; no additional handling in model.
/Wp64 -Wp64 If version is Visual C++ 7.0, 7.1, 8.0 or 9.0, defines macro_Wp64=1.
/Yc
/Ycarg
-Yc
/Ycarg
Specifies front end option --cs_create_pch.
If arg is present, also specifies front end option --cs_create_pch_hdrstop arg.
/Yu
/Yuarg
-Yu
/Yuarg
Specifies front end option --cs_use_pch.
If arg is present, also specifies front end option --cs_use_pch_hdrstop arg.
/Za -Za Defines macro _MSC_EXTENSIONS.
/Zc:forscope -Zc:forscope Specifies front end option --new_for_init.
/Zc:forscope- -Zc:forscope- Specifies front end option --old_for_init.
/Zc:preprocessor -Zc:preprocessor Specifies front end option --ms_std_preprocessor.
/Zc:ternary -Zc:ternary Specifies front end option --ms_strict_ternary.
/Zc:ternary- -Zc:ternary- Specifies front end option --no_ms_strict_ternary.
/Zc:wchar_t -Zc:wchar_t Specifies front end option --wchar_t_keyword.
/Zc:wchar_t- -Zc:wchar_t- Specifies front end option --no_wchar_t_keyword.
/Zl -Zl If version is Visual C++ 8.0 and later, defines macro_VC_NODEFAULTLIB=1.
/Zs -Zs Specifies front end option --no_code_gen.

Note on /D, /U evaluation order

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

Visual C++ 7.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 Flags and Paths

Predefined macros and include paths are listed below.

Paths The cl compiler model...
  • ...uses the directories specified by the INCLUDE environment variable when searching for header files. If this environment variable is not defined, it uses the directories stored in the Windows registry.
  • ...uses the Windows linker LINK. Make sure the directory that contains LINK (usually the /bin subdirectory of the Visual Studio installation directory) is set in the PATH, otherwise CodeSonar will not be able to use it. If LINK is not installed on the build machine, the cl command will fail.
  • ...searches for library files ( *.lib files) in the following order:
    1. The current directory (or if the library is specified with its full path, that path).
    2. The directory specified by the /LIBPATH flag. (Note that /LIBPATH is not a cl compiler option; it is only a link option.)
    3. The directories specified by the LIB environment variable.
Macros Always Defined The cl compiler model defines the following in addition to the standard CodeSonar predefined macros.
__based(x) =
__event =
__identifier(x) =___##x
__inline =
_INTEGRAL_MAX_BITS =64
_MSC_VER = the version number.
__ptr32 =
__ptr64 =
__raise =
__unaligned =
_WIN32 =1
Conditionally Defined Macros
__abstract = if /clr is specified and version is earlier than Visual Studio 2015.
_CHAR_UNSIGNED =1 if /J is specified.
_CPPUNWIND =1 if /GX, /EHa, or /EHs is specified (and /GX-, /EHa- or /EHs- is not subsequently specified).
_CPPRTTI =1 if /GR is specified or version is Visual Studio 2008 or higher, and /GR- is not subsequently specified, and /kernel is not specified (or has subsequent /kernel-).
_DEBUG =1 if /MDd or /MLd or /MTd is specified, or version is Visual C ++ 7.0 or higher and /LD is specified.
__delegate = if /clr is specified and version is earlier than Visual Studio 2015.
_DLL =1 if /MD or /MDd is specified.
__gc = if /clr is specified and version is earlier than Visual Studio 2015.
_KERNEL_MODE =1 if /kernel is specified and /kernel- is not subsequently specified.
_M_AMD64 =100 if version number is 1300 (Visual C++ 7.0) or higher and build target is not in {x86, itanium, arm, arm64, motorola_68k, powerpc}.
_M_ARM =7 if build target is arm.
_M_ARM64 =1 if build target is arm64.
_M_HYBRID =1 if the native compiler invocation determines that macro _M_HYBRID is predefined (to a non-zero value).
_M_IA64 = if
_M_IX86 =num if
  • the build target is x86, or
  • build environment is 32-bit and any of {/G5, /G6, /G7, /GB} is specified, or
  • version number is lower than 1300 (Visual C++ 7.0) and build target is not in {x86, itanium, arm, arm64, motorola_68k, powerpc}.
The value of num is determined as follows.
build environment other conditions num
32-bit /G5 is specified 500
/G6 is specified 600
/G7 is specified 700
/GB is specified 600
none of {/G5, /G6, /G7, /GB} are specified and build target is x86 600
none of {/G5, /G6, /G7, /GB} are specified and version number is lower than 1300 (Visual C++ 7.0) and build target is not in {x86, itanium, arm, arm64, motorola_68k, powerpc} 600
64-bit build target is x86 600
version number is lower than 1300 (Visual C++ 7.0) and build target is not in {x86, itanium, arm, arm64, motorola_68k, powerpc} 600
_M_IX86_FP =num if version is Visual Studio 2005 SP1 and higher. num depends on the specified /arch argument, if any:
argument num
/arch:SSE 1
/arch:SSEn n
all other cases 0
_M_M68K =1 if build target is motorola_68k.
_M_MPPC =1 if build target is power_pc.
_M_X64 =100 if version number is 1300 (Visual C++ 7.0) or higher and build target is not in {x86, itanium, arm, arm64, motorola_68k, powerpc}.
_MSC_BUILD =rnum in Visual C++ 9.0 and later, where rnum is the revision number.
_MSC_EXTENSIONS =1 unless /Za is specified without subsequent /Ze.
_MSC_FULL_VER = Vb in version 12.00.8804 or higher. V is the version number and b the build number. See note on version and build numbers.
_MSVC_LANG =val if
  • version is 19.00.24210 (Visual Studio 2015 Update 3) or higher, or
  • one of the following is specified: {std:c++14, std:c++17, std:c++latest}.
The value of val is determined as follows.
argument val
/std:c++14 201402L
/std:c++17 201703L
/std:c++latest depends on version number:
version number =1900 201403L
1910 ≤ version number < 1920 201704L
otherwise 201705L
none of the above and version is 19.00.24210 or higher 201402L
__MSVC_RUNTIME_CHECKS =1 if /RTC is specified.
_MT =1 if version is Visual Studio 2005 and higher, or one of the following is specified: /LD, /MD, /MDd, /MT, /MTd.
_NATIVE_NULLPTR_SUPPORTED =1 if version is Visual C++ 10.0 or higher.
__nogc = if /clr is specified and version is earlier than Visual Studio 2015.
_OPENMP =200203 if version is Visual Studio 2005 or higher and /openmp is specified.
__pin = if /clr is specified and version is earlier than Visual Studio 2015.
__property = if /clr is specified and version is earlier than Visual Studio 2015.
__sealed = if /clr is specified and version is earlier than Visual Studio 2015.
_SIZE_T_DEFINED =1 in C++ mode.
__sptr =1 if version is Visual Studio 2005 SP1 or higher.
__uptr =1 if version is Visual Studio 2005 SP1 or higher.
_VC_NODEFAULTLIB =1 if version is Visual Studio 2005 or higher and /Zl is specified.
__value = if /clr is specified and version is earlier than Visual Studio 2015.
_Wp64 =1 if version is Visual C++ 7.0 or later and /Wp64 is specified.
_WIN64 =1 in 64-bit build environment.
Front End Options The following front end options are always specified.
--microsoft  
--microsoft_bugs  
--microsoft_build_number bnum where bnum is the build number
--microsoft_version vnum where vnum is the version number
Environment Variables The Visual C++ setup program creates a batch file called VCVARS32.BAT (for MS Visual Studio version 6) or VSVARS32.BAT (for MS Visual Studio .NET) which automatically sets up all of the Visual Studio environment variables that the cl compiler model relies upon. This batch file can be found in the /bin subdirectory of the Visual Studio installation directory.

Note on Build Target and Version/Build/Revision Numbers

The cl compiler model determines version number, build number, revision number, and build target as follows, in order of precedence.

The build environment is 64-bit if the build target is x64, itanium, or ddk64; 32-bit otherwise.

 

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