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


Clang Compiler Models

There are two Clang compiler models: clang and clangpp.



Overview

The clang compiler model is based on the gcc model. The clangpp compiler model is based on the clang model, and thus transitively on the gcc model.

The only difference between the clang and clangpp models is is that compilations modeled with the clangpp model are always modeled in C++ mode unless the language is explicitly specified using the -x flag.

The following file extensions are supported.

Compiler
model
Modeled native compiler Source file extensions
clang Clang C compiler Source file extensions indicate the source language unless the language is otherwise specified using the -x flag or --driver_mode=g++.
  • .c, .i (case sensitive)
C mode
  • .C (case sensitive)
  • .cc, .cpp, .cxx, .c++, .ii (case insensitive)
C++ mode
clangpp Clang C++ compiler
  • .i (case sensitive)
  • .c, .cc, .cpp, .cxx, .c++, .ii (case insensitive)
C++ mode unless the language is explicitly specified using the -x flag or --driver_mode=g++.

Availability

Platform Availability The clang and clangpp 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 clang(.exe) clang
All clang++(.exe) clangpp
Specifying Additional Mappings If your compiler executable has a different name, specify a corresponding COMPILER_MODELS rule to map your executable name to the clang or clangpp 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 clang and clangpp compiler models are based on the gcc model, so you can associate an ABI key in the gcc-model-specific format with any compilation handled by the clang or clangpp model. The key structure and interpretation are described in GNU Compiler Models: Model-Specific ABI Key Format.

LLVM Clang vs Apple Clang

The clang and clangpp compiler models can be used for both LLVM Clang and Apple Clang compilations. However, there are some differences between the two, so the models attempt to invoke the native compiler to determine which of the two it corresponds to.

If this determination cannot be performed, the model defaults to assuming that you are using LLVM Clang.

If the model determines that you are using Apple Clang, it performs two additional actions.

The default C++ standard also depends on whether or not the modeled native compiler is determined to be Apple Clang.

Command Arguments

Command argument handling for the clang and clangpp compiler models is the same as that for the gcc model (described in GNU Compiler Models: Command Arguments), with the following additions.

Argument Additional Treatment in Model
-ansi
--ansi
In addition to the handling specified for -ansi in the gcc model, specifies front end option --cs_c11_atomic_keyword. addition
-c-isystem=dir
-c-isystem dir
[C mode only] Specifies front end option --sys_include dir. addition
-cxx-isystem=dir
-cxx-isystem dir
[C++ mode only] Specifies front end option --sys_include dir. addition
--driver_mode=mode
--driver_mode mode
Handling depends on value of mode:
g++ Modeled compilation mode for source files appearing before the first occurence of -x in the build command line is C++. If -x is not specified, modeled compilation mode is C++ for all source files.
otherwise Command line position relative to -x does not affect the compilation mode for a source file. Supersedes any previous occurrence of --driver_mode=g++
addition
-emit-obj Accepted, but incurs no additional handling and is not passed to the native compiler invocation. addition
-fdeclspec
Specifes front end option --cs_declspec. addition
-fnodeclspec
Specifes front end option --cs_no_declspec. addition
-ObjC
-ObjC++
The compilation is ignored. addition
-std=arg
-std arg
--std=arg
--std arg
Handling is the same as that for -std in the gcc compiler model, but note that the clang and clangpp models have behaviors that depend on both the applicable C standard and the applicable C++ standard. -
-target arg
-targetarg
If arg contains substring windows and the applicable C++ standard is before C++11, specifies front end options --cs_declspec and --cs_static_assert. -
-x lang
-xlang
Handling is the same as that for -x in the gcc compiler model; this table entry is provided for navigation purposes only. -
-Xclang=arg
-Xclang arg
Handling depends on the value of arg as follows.
  • If arg is objective-c or objective-c++, the compilation is ignored.
  • Otherwise, passed to the native compiler invocation with no additional handling.
addition

Compilation Mode

The modeled compilation mode is determined as follows.

--driver_mode=g++ specified
(and not subsequently superseded)?
YES NO
-x lang specified? YES The modeled compilation mode for each source file F depends on whether F appears before or after the first occurence of -x in the build command line.
  • before: compilation mode for F is C++.
  • after: compilation mode for F depends on lang as described in the rightmost column.
Modeled compilation mode will depend on lang as follows.
lang Modeled compilation mode
c
cpp-output
C mode
c++
c++-cpp-output
C++ mode
none The model will determine the mode from the source file extension.
other lang CodeSonar will ignore the compilation.
NO Modeled compilation mode for all source files is C++. Modeled compilation mode determination depends on the model:
clang mode is determined from the source file extension.
clangpp mode is always C++.

C and C++ Standards

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

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, Include Paths, Front End Options

Predefined macros for the clang and clangpp compiler models are the same as those for the gcc model (described in GNU Compiler Models: Predefined Macros and Include Paths), with the following exceptions.

If you are using Apple Clang (as opposed to LLVM Clang), note that the "Clang version" upon which some conditional definitions depend is the version resulting from the translation described above.

Macros always defined As for the gcc model, with the following additions.
__has_warning(x) =0 hard-defined.
_Atomic(x) =x hard-defined.
Macros Conditionally Defined As for the gcc model, with the following additions.
__building_module(x) =0 if the model determines that the Clang version is 3.3 or later.
Include Paths Defined by compiler configuration files.
Front End Options Always Specified As for the gcc model, with the following additions and modifications.
Always specified for C compilations: relationship to gcc
--cs_ext_c99_for_init   addition
--cs_clang_tweaks   addition
--clang   addition
--clang_version ver Where ver is the Clang version determined by the model. addition
-restrict   addition
Always specified for C++ compilations:  
--cs_clang_tweaks   addition
--clang   addition
--clang_version ver Where ver is the Clang version determined by the model. addition
--pending_instantiations num Where num is determined by -ftemplate-depth num or -ftemplate-depth-num if specified; 1024 otherwise. modification
Front End Options Conditionally Specified As for the gcc model, with the following additions and modifications.
Option Conditions Relationship to gcc
--auto_type [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--c99 [C compilations only] if -std arg is specified for arg in {c99,c9x,gnu99,gnu9x,iso9899:1999,iso9899:199x}, or -std is not specified and the model determines that the Clang version is earlier than 3.6. modification
--c11 [C compilations only] if -std arg is specified for arg in {c99,c9x,gnu99,gnu9x,iso9899:1999,iso9899:199x}, or -std is not specified and the model determines that the Clang version is 3.6 or later. modification
--c++11 [C++ compilations only] if -std arg is specified for arg in {c++11,gnu++11}. modification
--c++11_sfinae [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--c++11_sfinae_ignore_access [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--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 Clang version is 6.0 or later and the native compiler is not Apple Clang. modification
--cs_apple_clang if the model determines that the native compiler is Apple (rather than LLVM) Clang. addition
--cs_c11_atomic_keyword [C++ compilations only] if -ansi is specified. modification
--cs_capture_star_this [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 3.9 or later. addition
--cs_constexpr_if [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 3.9 or later. addition
--cs_constexpr_lambdas [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 5.0 or later. addition
--cs_declspec if -fdeclspec is specified,
or
-target arg is specified with arg containing substring windows and the model determines that the applicable C++ standard is before C++11.
addition
--cs_decltype_auto [C++ compilations only] if the model determines that the applicable C++ standard is before C++14 and that the Clang version is 3.3 or later. addition
--cs_deleted_functions [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--cs_enum_qualifiers [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--cs_explicit_enum_base [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--cs_explicit_conversion_functions [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 3.0 or later. addition
--cs_ext_binary_number [C++ compilations only] if the model determines that the applicable C++ standard is before C++14 and that the Clang version is 2.9 or later. addition
--cs_extern_template_allowed [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--cs_false_is_null_pointer_constant [C++ compilations only] if -std is not specified and the model determines that the Clang version is earlier than 6.0 or that the native compiler is Apple Clang. addition
--cs_fold_expressions [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 4.0 or later. modification
--cs_inline_namespaces [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--cs_inline_variables_allowed [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 3.9 or later. addition
--cs_list_init [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 3.1 or later. addition
--cs_local_types_as_template_args [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--cs_namespace_attributes [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 3.6 or later. addition
--cs_no_alignas [C++ compilations only] if the model determines that the applicable C++ standard is before C++11. addition
--cs_no_char_t_keywords [C++ compilations only] if the model determines that the applicable C++ standard is before C++11. addition
--cs_no_constexpr [C++ compilations only] if the model determines that the applicable C++ standard is before C++11. addition
--cs_no_declspec if -fnodeclspec is specified. addition
--cs_no_noexcept [C++ compilations only] if the model determines that the applicable C++ standard is before C++11. addition
--cs_no_relaxed_constexpr [C++ compilations only] if the model determines that the applicable C++ standard is before C++14. addition
--cs_no_static_assert [C++ compilations only] if the model determines that the applicable C++ standard is before C++11. addition
--cs_range_based_for [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 3.0 or later. addition
--cs_ref_qualifiers [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 3.0 or later. addition
--cs_relaxed_range_based_for [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 3.9 or later. addition
--cs_rvalue_allowed_with_const_qual_memptr [C++ compilations only] if the model determines that the applicable C++ standard is before C++20 and that the Clang version is 6.0 or later. addition
--cs_selection_initializers [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 3.9 or later. addition
--cs_static_assert [C++ compilations only] if -target arg is specified with arg containing substring windows and the model determines that the applicable C++ standard is before C++11. modification
--cs_struct_bindings [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 4.0 or later. modification
--cs_underscore_decltype_only [C++ compilations only] if the model determines that the applicable C++ standard is before C++0x. addition
--cs_using_attribute_namespaces [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 3.6 or later. addition
--cs_variable_templates [C++ compilations only] if the model determines that the applicable C++ standard is before C++14 and that the Clang version is 3.4 or later. addition
--cs_variadic_using_decls [C++ compilations only] if the model determines that the applicable C++ standard is before C++17 and that the Clang version is 4.0 or later. modification
--no_nullptr [C++ compilations only] if the model determines that the applicable C++ standard is before C++11. addition
--no_thread_local_storage [C++ compilations only] if the model determines that the applicable C++ standard is before C++11. addition
--rvalue_refs [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
--variadic_templates [C++ compilations only] if the model determines that the applicable C++ standard is before C++11 and that the Clang version is 2.9 or later. addition
 

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