diff --git a/docs/build/reference/compiler-options-listed-alphabetically.md b/docs/build/reference/compiler-options-listed-alphabetically.md index 2aea452174c..462eaf975a5 100644 --- a/docs/build/reference/compiler-options-listed-alphabetically.md +++ b/docs/build/reference/compiler-options-listed-alphabetically.md @@ -53,6 +53,7 @@ This table contains an alphabetical list of compiler options. For a list of comp | [`/FR`](fr-fr-create-dot-sbr-file.md)

[`/Fr`](fr-fr-create-dot-sbr-file.md) | Generates browser files. **`/Fr`** is deprecated. | | [`/FS`](fs-force-synchronous-pdb-writes.md) | Forces serialization of all writes to the program database (PDB) file through MSPDBSRV.EXE. | | [`/fsanitize`](fsanitize.md) | Enables compilation of sanitizer instrumentation such as AddressSanitizer. | +| [`/fsanitize-coverage`](fsanitize-coverage.md) | Enables compilation of code coverage instrumentation for libraries such as LibFuzzer. | | [`/FU`](fu-name-forced-hash-using-file.md) | Forces the use of a file name as if it had been passed to the [`#using`](../../preprocessor/hash-using-directive-cpp.md) directive. | | [`/Fx`](fx-merge-injected-code.md) | Merges injected code with source file. | | [`/GA`](ga-optimize-for-windows-application.md) | Optimizes code for Windows application. | diff --git a/docs/build/reference/compiler-options-listed-by-category.md b/docs/build/reference/compiler-options-listed-by-category.md index ec95e10c9b3..8ff74ddebca 100644 --- a/docs/build/reference/compiler-options-listed-by-category.md +++ b/docs/build/reference/compiler-options-listed-by-category.md @@ -169,6 +169,7 @@ This article contains a categorical list of compiler options. For an alphabetica | [`/FC`](fc-full-path-of-source-code-file-in-diagnostics.md) | Displays the full path of source code files passed to *cl.exe* in diagnostic text. | | [`/FS`](fs-force-synchronous-pdb-writes.md) | Forces writes to the PDB file to be serialized through *MSPDBSRV.EXE*. | | [`/fsanitize`](fsanitize.md) | Enables compilation of sanitizer instrumentation such as AddressSanitizer. | +| [`/fsanitize-coverage`](fsanitize-coverage.md) | Enables compilation of code coverage instrumentation for libraries such as LibFuzzer. | | [`/H`](h-restrict-length-of-external-names.md) | Deprecated. Restricts the length of external (public) names. | | [`/HELP`](help-compiler-command-line-help.md) | Lists the compiler options. | | [`/J`](j-default-char-type-is-unsigned.md) | Changes the default **`char`** type. | diff --git a/docs/build/reference/fp-specify-floating-point-behavior.md b/docs/build/reference/fp-specify-floating-point-behavior.md index ed48ef13ad8..d23d5228430 100644 --- a/docs/build/reference/fp-specify-floating-point-behavior.md +++ b/docs/build/reference/fp-specify-floating-point-behavior.md @@ -12,20 +12,54 @@ Specifies how the compiler treats floating-point expressions, optimizations, and ## Syntax +::: moniker range=">msvc-160" + +**`/fp:contract`** +**`/fp:except`**\[**`-`**]\ +**`/fp:fast`**\ **`/fp:precise`**\ **`/fp:strict`**\ -**`/fp:fast`**\ + +::: moniker-end +::: moniker range="<=msvc-160" + **`/fp:except`**\[**`-`**] +**`/fp:fast`**\ +**`/fp:precise`**\ +**`/fp:strict`**\ + +::: moniker-end ### Arguments +::: moniker range=">msvc-160" + +#### `/fp:contract` + +The **`/fp:contract`** option allows the compiler to generate floating-point contractions when you specify the **`/fp:precise`** and **`/fp:except`** options. A *contraction* is a machine instruction that combines floating-point operations, such as Fused-Multiply-Add (FMA). FMA, defined as a basic operation by IEEE-754, doesn't round the intermediate product before the addition, so the result can differ from separate multiplication and addition operations. Since it's implemented as a single instruction, it can be faster than separate instructions. The speed comes at a cost of bitwise exact results, and an inability to examine the intermediate value. + +By default, the **`/fp:fast`** option enables **`/fp:contract`**. The **`/fp:contract`** option isn't compatible with **`/fp:strict`**. + +The **`/fp:contract`** option is new in Visual Studio 2022. + +::: moniker-end + #### `/fp:precise` By default, the compiler uses **`/fp:precise`** behavior. Under **`/fp:precise`**, the compiler preserves the source expression ordering and rounding properties of floating-point code when it generates and optimizes object code for the target machine. The compiler rounds to source code precision at four specific points during expression evaluation: at assignments, typecasts, when floating-point arguments get passed to a function call, and when a function call returns a floating-point value. Intermediate computations may be performed at machine precision. Typecasts can be used to explicitly round intermediate computations. -The compiler doesn't perform algebraic transformations on floating-point expressions, such as reassociation or distribution, unless it can guarantee the transformation produces a bitwise identical result. Expressions that involve special values (NaN, +infinity, -infinity, -0.0) are processed according to IEEE-754 specifications. For example, `x != x` evaluates to **`true`** if `x` is NaN. Floating-point *contractions*, machine instructions that combine floating-point operations, may be generated under **`/fp:precise`**. +::: moniker range=">msvc-160" + +The compiler doesn't perform algebraic transformations on floating-point expressions, such as reassociation or distribution, unless it can guarantee the transformation produces a bitwise identical result. Expressions that involve special values (NaN, +infinity, -infinity, -0.0) are processed according to IEEE-754 specifications. For example, `x != x` evaluates to **`true`** if `x` is NaN. Floating-point contractions aren't generated by default under **`/fp:precise`**. This behavior is new in Visual Studio 2022. Previous compiler versions could generate contractions by default under **`/fp:precise`**. + +::: moniker-end +::: moniker range="<=msvc-160" + +The compiler doesn't perform algebraic transformations on floating-point expressions, such as reassociation or distribution, unless it can guarantee the transformation produces a bitwise identical result. Expressions that involve special values (NaN, +infinity, -infinity, -0.0) are processed according to IEEE-754 specifications. For example, `x != x` evaluates to **`true`** if `x` is NaN. Floating-point contractions may be generated under **`/fp:precise`**. + +::: moniker-end The compiler generates code intended to run in the [default floating-point environment](#the-default-floating-point-environment). It also assumes the floating-point environment isn't accessed or modified at runtime. That is, it assumes the code doesn't unmask floating-point exceptions, read or write floating-point status registers, or change rounding modes. @@ -49,7 +83,7 @@ Under **`/fp:fast`**, the compiler generates code intended to run in the default #### `/fp:except` -The **`/fp:except`** option generates code to ensures that any unmasked floating-point exceptions are raised at the exact point at which they occur, and that no other floating-point exceptions are raised. By default, the **`/fp:strict`** option enables **`/fp:except`**, and **`/fp:precise`** doesn't. The **`/fp:except`** option isn't compatible with **`/fp:fast`**. The option can be explicitly disabled by us of **`/fp:except-`**. +The **`/fp:except`** option generates code to ensures that any unmasked floating-point exceptions are raised at the exact point at which they occur, and that no other floating-point exceptions are raised. By default, the **`/fp:strict`** option enables **`/fp:except`**, and **`/fp:precise`** doesn't. The **`/fp:except`** option isn't compatible with **`/fp:fast`**. The option can be explicitly disabled by use of **`/fp:except-`**. By itself, **`/fp:except`** doesn't enable any floating-point exceptions. However, it's required for programs to enable floating-point exceptions. For more information on how to enable floating-point exceptions, see [`_controlfp`](../../c-runtime-library/reference/control87-controlfp-control87-2.md). @@ -63,11 +97,26 @@ The [`/Za`](za-ze-disable-language-extensions.md) (ANSI compatibility) option is The compiler provides three pragma directives to override the floating-point behavior specified on the command line: [`float_control`](../../preprocessor/float-control.md), [`fenv_access`](../../preprocessor/fenv-access.md), and [`fp_contract`](../../preprocessor/fp-contract.md). You can use these directives to control floating-point behavior at function-level, not within a function. These directives don't correspond directly to the **`/fp`** options. This table shows how the **`/fp`** options and pragma directives map to each other. For more information, see the documentation for the individual options and pragma directives. -| Option | float_control(precise) | float_control(except) | fenv_access | fp_contract | +::: moniker range=">msvc-160" + +| Option | `float_control(precise, *)` | `float_control(except, *)` | `fenv_access(*)` | `fp_contract(*)` | +|--|--|--|--|--| +| `/fp:fast` | `off` | `off` | `off` | `on` | +| `/fp:precise` | `on` | `off` | `off` | `off`\* | +| `/fp:strict` | `on` | `on` | `on` | `off` | + +\* In versions of Visual Studio before Visual Studio 2022, the **`/fp:precise`** behavior defaulted to `fp_contract(on)`. + +::: moniker-end +::: moniker range=">msvc-160" + +| Option | `float_control(precise, *)` | `float_control(except, *)` | `fenv_access(*)` | `fp_contract(*)` | |--|--|--|--|--| -| `/fp:fast` | off | off | off | on | -| `/fp:precise` | on | off | off | on | -| `/fp:strict` | on | on | on | off | +| `/fp:fast` | `off` | `off` | `off` | `on` | +| `/fp:precise` | `on` | `off` | `off` | `on` | +| `/fp:strict` | `on` | `on` | `on` | `off` | + +::: moniker-end ### The default floating point environment diff --git a/docs/build/reference/fsanitize-coverage.md b/docs/build/reference/fsanitize-coverage.md new file mode 100644 index 00000000000..8232ceb89d7 --- /dev/null +++ b/docs/build/reference/fsanitize-coverage.md @@ -0,0 +1,86 @@ +--- +description: "Learn more about the /fsanitize-coverage (Configure sanitizer coverage) compiler option." +title: "/fsanitize-coverage (Configure sanitizer coverage)" +ms.date: 09/15/2021 +f1_keywords: ["/fsanitize-coverage", "-fsanitize-coverage", "/fsanitize-coverage=inline-8bit-counters", "/fsanitize-coverage=edge", "/fsanitize-coverage=trace-cmp", "/fsanitize-coverage=trace-div", "/fno-sanitize-coverage=inline-8bit-counters", "/fno-sanitize-coverage=edge", "/fno-sanitize-coverage=trace-cmp", "/fno-sanitize-coverage=trace-div"] +helpviewer_keywords: ["/fsanitize-coverage [C++]", "sanitizer compiler option [C++]", "/fsanitize-coverage=inline-8bit-counters", "/fsanitize-coverage=edge", "/fsanitize-coverage=trace-cmp", "/fsanitize-coverage=trace-div", "/fno-sanitize-coverage=inline-8bit-counters", "/fno-sanitize-coverage=edge", "/fno-sanitize-coverage=trace-cmp", "/fno-sanitize-coverage=trace-div"] +--- +# `/fsanitize-coverage` (Configure sanitizer coverage) + +The **`/fsanitize-coverage`** compiler options instruct the compiler to add various kinds of instrumentation points where user-defined functions are called. These options are useful for fuzzing scenarios that use **`/fsanitize=fuzzer`**, like OneFuzz. For more information, see the [OneFuzz documentation](https://www.microsoft.com/en-us/research/project/project-onefuzz/) and [OneFuzz GitHub project](https://github.com/microsoft/onefuzz). + +## Syntax + +> **`/fsanitize-coverage=edge`**\ +> **`/fsanitize-coverage=inline-8bit-counters`**\ +> **`/fsanitize-coverage=trace-cmp`**\ +> **`/fsanitize-coverage=trace-div`**\ +> **`/fno-sanitize-coverage=edge`**\ +> **`/fno-sanitize-coverage=inline-8bit-counters`**\ +> **`/fno-sanitize-coverage=trace-cmp`**\ +> **`/fno-sanitize-coverage=trace-div`** + +## Remarks + +The experimental **`/fsanitize-coverage`** compiler options offer code coverage support and various options to modify which compiler-provided instrumentation is generated. All these options are automatically set when the [`/fsanitize=fuzzer`](fsanitize.md) option is specified. The **`/fsanitize=fuzzer`** option requires the same instrumentation points and callbacks mentioned in these options. + +The **`/fsanitize-coverage`** options don't allow comma-separated syntax, for example: **`/fsanitize-coverage=edge,inline-8bit-counters,trace-cmp,trace-div`**. Specify these options individually. + +The **`/fsanitize-coverage`** options are available beginning in Visual Studio 2022 version 17.0. + +### Code coverage + +The **`/fsanitize-coverage=edge`** compiler option enables code coverage instrumentation along all non-redundant edges. Use **`/fno-sanitize-coverage=edge`** to disable this option if it's already provided or implied by another option. + +### Inline counters + +The **`/fsanitize-coverage=inline-8bit-counters`** compiler option instructs the compiler to add an inline counter increment on every relevant edge. This option also adds a call to `extern "C" void __sanitizer_cov_8bit_counters_init(uint8_t *start, uint8_t *stop)` that you must implement. The arguments correspond to the start and end of an array that contains all the 8-bit counters created. Use **`/fno-sanitize-coverage=inline-8bit-counters`** to disable this option if it's already provided or implied by another option. + +### Trace comparisons + +The **`/fsanitize-coverage=trace-cmp`** compiler option instructs the compiler to insert calls to the following functions: + +```C +// Before each comparison instruction of the stated size. +void __sanitizer_cov_trace_cmp1(uint8_t Arg1, uint8_t Arg2); +void __sanitizer_cov_trace_cmp2(uint16_t Arg1, uint16_t Arg2); +void __sanitizer_cov_trace_cmp4(uint32_t Arg1, uint32_t Arg2); +void __sanitizer_cov_trace_cmp8(uint64_t Arg1, uint64_t Arg2); + +// Before each comparison instruction of the stated size, if one of the operands (Arg1) is constant. +void __sanitizer_cov_trace_const_cmp1(uint8_t Arg1, uint8_t Arg2); +void __sanitizer_cov_trace_const_cmp2(uint16_t Arg1, uint16_t Arg2); +void __sanitizer_cov_trace_const_cmp4(uint32_t Arg1, uint32_t Arg2); +void __sanitizer_cov_trace_const_cmp8(uint64_t Arg1, uint64_t Arg2); +``` + +Use **`/fno-sanitize-coverage=trace-cmp`** to disable this option if it's already provided or implied by another option. + +### Trace divisions + +The **`/fsanitize-coverage=trace-div`** compiler option instructs the compiler to insert calls to the following functions: + +```C +// Before a division instruction of the stated size. +void __sanitizer_cov_trace_div4(uint32_t Val); +void __sanitizer_cov_trace_div8(uint64_t Val); +``` + +Use **`/fno-sanitize-coverage=trace-div`** to disable this option if it's already provided or implied by another option. + +### To set the advanced compiler options + +1. Open your project's **Property Pages** dialog box. + +1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page. + +1. Modify the **Additional Options** property to set **/fsanitize-coverage** options. + +1. Choose **OK** or **Apply** to save your changes. + +## See also + +[MSVC compiler options](compiler-options.md)\ +[MSVC compiler command-line syntax](compiler-command-line-syntax.md)\ +[`/fsanitize` (Enable Sanitizers)](fsanitize.md)\ +[AddressSanitizer build and language reference](../../sanitizers/asan-building.md) diff --git a/docs/build/reference/fsanitize.md b/docs/build/reference/fsanitize.md index eeb828ebfe2..e4a146577b2 100644 --- a/docs/build/reference/fsanitize.md +++ b/docs/build/reference/fsanitize.md @@ -1,27 +1,30 @@ --- description: "Learn more about the /fsanitize (enable sanitizers) compiler option" title: "/fsanitize (Enable sanitizers)" -ms.date: 02/24/2021 -f1_keywords: ["/fsanitize", "-fsanitize", "/fsanitize=address", "/fsanitize-address-use-after-return", "-fsanitize-address-use-after-return", "/fno-sanitize-address-vcasan-lib", "-fno-sanitize-address-vcasan-lib"] +ms.date: 09/15/2021 +f1_keywords: ["/fsanitize", "-fsanitize", "/fsanitize=address", "/fsanitize=fuzzer", "/fsanitize-address-use-after-return", "-fsanitize-address-use-after-return", "/fno-sanitize-address-vcasan-lib", "-fno-sanitize-address-vcasan-lib"] helpviewer_keywords: ["/fsanitize [C++]", "-fsanitize=address [C++]", "address sanitizer compiler option [C++]", "/fsanitize-address-use-after-return", "/fno-sanitize-address-vcasan-lib"] --- # `/fsanitize` (Enable sanitizers) -Use the **`/fsanitize`** compiler options to enable sanitizers. As of Visual Studio 2019 16.9, the only supported sanitizer is [AddressSanitizer](../../sanitizers/asan.md). +Use the **`/fsanitize`** compiler options to enable sanitizers. ## Syntax > **`/fsanitize=address`**\ +> **`/fsanitize=fuzzer`**\ > **`/fsanitize-address-use-after-return`**\ > **`/fno-sanitize-address-vcasan-lib`** ## Remarks -The **`/fsanitize=address`** compiler option enables [AddressSanitizer](../../sanitizers/asan.md), a powerful compiler and runtime technology to light up [hard-to-find bugs](../../sanitizers/asan.md#error-types). +The **`/fsanitize=address`** compiler option enables [AddressSanitizer](../../sanitizers/asan.md), a powerful compiler and runtime technology to uncover [hard-to-find bugs](../../sanitizers/asan.md#error-types). Support for the **`/fsanitize=address`** option is available starting in Visual Studio 2019 version 16.9. -The **`/fsanitize-address-use-after-return`** and **`/fno-sanitize-address-vcasan-lib`** compiler options, and the [`/INFERASANLIBS` (Use inferred sanitizer libs)](./inferasanlibs.md) and **`/INFERASANLIBS:NO`** linker options offer support for advanced users. For more information, see [AddressSanitizer build and language reference](../../sanitizers/asan-building.md). +The **`/fsanitize=fuzzer`** compiler option enables experimental support for [LibFuzzer](https://releases.llvm.org/3.8.0/docs/LibFuzzer.html). LibFuzzer is a coverage-guided fuzzing library that can be used to find bugs and crashes caused by user-provided input. We recommended you use **`/fsanitize=address`** with LibFuzzer. This option is useful for fuzzing tools such as OneFuzz. For more information, see the [OneFuzz documentation](https://www.microsoft.com/en-us/research/project/project-onefuzz/) and [OneFuzz GitHub project](https://github.com/microsoft/onefuzz). Support for the **`/fsanitize=fuzzer`** option is available starting in Visual Studio 2022 version 17.0. + +The **`/fsanitize`** option doesn't allow comma-separated syntax, for example: **`/fsanitize=address,fuzzer`**. These options must be specified individually. -The **`/fsanitize`** options are available beginning in Visual Studio 2019 version 16.9. +The **`/fsanitize-address-use-after-return`** and **`/fno-sanitize-address-vcasan-lib`** compiler options, and the [`/INFERASANLIBS` (Use inferred sanitizer libs)](./inferasanlibs.md) and **`/INFERASANLIBS:NO`** linker options offer support for advanced users. For more information, see [AddressSanitizer build and language reference](../../sanitizers/asan-building.md). ### To set the **`/fsanitize=address`** compiler option in the Visual Studio development environment @@ -33,6 +36,16 @@ The **`/fsanitize`** options are available beginning in Visual Studio 2019 versi 1. Choose **OK** or **Apply** to save your changes. +### To set the **`/fsanitize=fuzzer`** compiler option in the Visual Studio development environment + +1. Open your project's **Property Pages** dialog box. + +1. Select the **Configuration Properties** > **C/C++** > **General** property page. + +1. Modify the **Enable Fuzzer** property. To enable it, choose **Yes (/fsanitize=fuzzer)**. + +1. Choose **OK** or **Apply** to save your changes. + ### To set the advanced compiler options 1. Open your project's **Property Pages** dialog box. @@ -52,6 +65,7 @@ The **`/fsanitize`** options are available beginning in Visual Studio 2019 versi [MSVC compiler options](compiler-options.md)\ [MSVC compiler command-line syntax](compiler-command-line-syntax.md)\ [`/INFERASANLIBS` (Use inferred sanitizer libs)](./inferasanlibs.md)\ +[`/fsanitize-coverage` (Configure sanitizer coverage)](fsanitize-coverage.md)\ [AddressSanitizer overview](../../sanitizers/asan.md)\ [AddressSanitizer known issues](../../sanitizers/asan-known-issues.md)\ [AddressSanitizer build and language reference](../../sanitizers/asan-building.md) diff --git a/docs/build/reference/std-specify-language-standard-version.md b/docs/build/reference/std-specify-language-standard-version.md index d305e2f28f8..9fa24310b7f 100644 --- a/docs/build/reference/std-specify-language-standard-version.md +++ b/docs/build/reference/std-specify-language-standard-version.md @@ -1,7 +1,7 @@ --- title: "/std (Specify Language Standard Version)" description: "The MSVC compiler option /std specifies the C or C++ language standard supported by the compiler." -ms.date: 06/14/2021 +ms.date: 10/22/2021 f1_keywords: ["/std", "-std", "/std:c++14", "/std:c++17", "/std:c11", "/std:c17", "VC.Project.VCCLCompilerTool.CppLanguageStandard"] --- # `/std` (Specify Language Standard Version) @@ -51,7 +51,7 @@ The **`/std:c++20`** option disables compiler and standard library support for f **`/std:c++latest`**\ The **`/std:c++latest`** option enables all currently implemented compiler and standard library features proposed for the next draft standard, as well as some in-progress and experimental features. This option is available starting in Visual Studio 2015 Update 3. -Depending on the MSVC compiler version or update level, C++17 or C++20 features may not be fully implemented or fully conforming when you specify the **`/std:c++latest`** option. For an overview of C++ language conformance in Visual C++ by release version, see [Microsoft C/C++ language conformance](../../overview/visual-cpp-language-conformance.md). +Depending on the MSVC compiler version or update level, C++17, C++20, or proposed C++23 features may not be fully implemented or fully conforming when you specify the **`/std:c++latest`** option. We recommend you use the latest version of Visual Studio for maximum standards conformance. For an overview of C++ language and library conformance in Visual C++ by release version, see [Microsoft C/C++ language conformance](../../overview/visual-cpp-language-conformance.md). In versions of Visual Studio 2019 before version 16.11, **`/std:c++latest`** is required to enable all the compiler and standard library features of C++20. diff --git a/docs/build/toc.yml b/docs/build/toc.yml index 127c19fe656..2a6e186b5e6 100644 --- a/docs/build/toc.yml +++ b/docs/build/toc.yml @@ -563,6 +563,8 @@ items: href: ../build/reference/fs-force-synchronous-pdb-writes.md - name: /fsanitize (Enable sanitizers) href: ../build/reference/fsanitize.md + - name: /fsanitize-coverage (Configure sanitizer coverage) + href: ../build/reference/fsanitize-coverage.md - name: /GA (Optimize for Windows application) href: ../build/reference/ga-optimize-for-windows-application.md - name: /Gd, /Gr, /Gv, /Gz (Calling convention) diff --git a/docs/build/vscpp-step-0-installation.md b/docs/build/vscpp-step-0-installation.md index ab35617c382..0fc6e1e719e 100644 --- a/docs/build/vscpp-step-0-installation.md +++ b/docs/build/vscpp-step-0-installation.md @@ -188,5 +188,3 @@ When Visual Studio is running, you're ready to continue to the next step. > [!div class="nextstepaction"] > [Create a C++ project](vscpp-step-1-create.md) - -