Skip to content

Commit 82dd8d2

Browse files
author
Colin Robertson
authored
Merge pull request #3473 from MicrosoftDocs/master637707807765690245
Repo sync for protected CLA branch
2 parents ceefc34 + 2996bd0 commit 82dd8d2

35 files changed

+3543
-3120
lines changed

docs/build/reference/compiler-options-listed-alphabetically.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ This table contains an alphabetical list of compiler options. For a list of comp
5353
| [`/FR`](fr-fr-create-dot-sbr-file.md)<br /><br /> [`/Fr`](fr-fr-create-dot-sbr-file.md) | Generates browser files. **`/Fr`** is deprecated. |
5454
| [`/FS`](fs-force-synchronous-pdb-writes.md) | Forces serialization of all writes to the program database (PDB) file through MSPDBSRV.EXE. |
5555
| [`/fsanitize`](fsanitize.md) | Enables compilation of sanitizer instrumentation such as AddressSanitizer. |
56+
| [`/fsanitize-coverage`](fsanitize-coverage.md) | Enables compilation of code coverage instrumentation for libraries such as LibFuzzer. |
5657
| [`/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. |
5758
| [`/Fx`](fx-merge-injected-code.md) | Merges injected code with source file. |
5859
| [`/GA`](ga-optimize-for-windows-application.md) | Optimizes code for Windows application. |

docs/build/reference/compiler-options-listed-by-category.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ This article contains a categorical list of compiler options. For an alphabetica
169169
| [`/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. |
170170
| [`/FS`](fs-force-synchronous-pdb-writes.md) | Forces writes to the PDB file to be serialized through *MSPDBSRV.EXE*. |
171171
| [`/fsanitize`](fsanitize.md) | Enables compilation of sanitizer instrumentation such as AddressSanitizer. |
172+
| [`/fsanitize-coverage`](fsanitize-coverage.md) | Enables compilation of code coverage instrumentation for libraries such as LibFuzzer. |
172173
| [`/H`](h-restrict-length-of-external-names.md) | Deprecated. Restricts the length of external (public) names. |
173174
| [`/HELP`](help-compiler-command-line-help.md) | Lists the compiler options. |
174175
| [`/J`](j-default-char-type-is-unsigned.md) | Changes the default **`char`** type. |

docs/build/reference/fp-specify-floating-point-behavior.md

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,54 @@ Specifies how the compiler treats floating-point expressions, optimizations, and
1212

1313
## Syntax
1414

15+
::: moniker range=">msvc-160"
16+
17+
**`/fp:contract`**
18+
**`/fp:except`**\[**`-`**]\
19+
**`/fp:fast`**\
1520
**`/fp:precise`**\
1621
**`/fp:strict`**\
17-
**`/fp:fast`**\
22+
23+
::: moniker-end
24+
::: moniker range="<=msvc-160"
25+
1826
**`/fp:except`**\[**`-`**]
27+
**`/fp:fast`**\
28+
**`/fp:precise`**\
29+
**`/fp:strict`**\
30+
31+
::: moniker-end
1932

2033
### Arguments
2134

35+
::: moniker range=">msvc-160"
36+
37+
#### <a name="contract"></a> `/fp:contract`
38+
39+
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.
40+
41+
By default, the **`/fp:fast`** option enables **`/fp:contract`**. The **`/fp:contract`** option isn't compatible with **`/fp:strict`**.
42+
43+
The **`/fp:contract`** option is new in Visual Studio 2022.
44+
45+
::: moniker-end
46+
2247
#### <a name="precise"></a> `/fp:precise`
2348

2449
By default, the compiler uses **`/fp:precise`** behavior.
2550

2651
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.
2752

28-
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`**.
53+
::: moniker range=">msvc-160"
54+
55+
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`**.
56+
57+
::: moniker-end
58+
::: moniker range="<=msvc-160"
59+
60+
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`**.
61+
62+
::: moniker-end
2963

3064
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.
3165

@@ -49,7 +83,7 @@ Under **`/fp:fast`**, the compiler generates code intended to run in the default
4983

5084
#### <a name="except"></a> `/fp:except`
5185

52-
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-`**.
86+
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-`**.
5387

5488
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).
5589

@@ -63,11 +97,26 @@ The [`/Za`](za-ze-disable-language-extensions.md) (ANSI compatibility) option is
6397

6498
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.
6599

66-
| Option | float_control(precise) | float_control(except) | fenv_access | fp_contract |
100+
::: moniker range=">msvc-160"
101+
102+
| Option | `float_control(precise, *)` | `float_control(except, *)` | `fenv_access(*)` | `fp_contract(*)` |
103+
|--|--|--|--|--|
104+
| `/fp:fast` | `off` | `off` | `off` | `on` |
105+
| `/fp:precise` | `on` | `off` | `off` | `off`\* |
106+
| `/fp:strict` | `on` | `on` | `on` | `off` |
107+
108+
\* In versions of Visual Studio before Visual Studio 2022, the **`/fp:precise`** behavior defaulted to `fp_contract(on)`.
109+
110+
::: moniker-end
111+
::: moniker range=">msvc-160"
112+
113+
| Option | `float_control(precise, *)` | `float_control(except, *)` | `fenv_access(*)` | `fp_contract(*)` |
67114
|--|--|--|--|--|
68-
| `/fp:fast` | off | off | off | on |
69-
| `/fp:precise` | on | off | off | on |
70-
| `/fp:strict` | on | on | on | off |
115+
| `/fp:fast` | `off` | `off` | `off` | `on` |
116+
| `/fp:precise` | `on` | `off` | `off` | `on` |
117+
| `/fp:strict` | `on` | `on` | `on` | `off` |
118+
119+
::: moniker-end
71120

72121
### The default floating point environment
73122

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
description: "Learn more about the /fsanitize-coverage (Configure sanitizer coverage) compiler option."
3+
title: "/fsanitize-coverage (Configure sanitizer coverage)"
4+
ms.date: 09/15/2021
5+
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"]
6+
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"]
7+
---
8+
# `/fsanitize-coverage` (Configure sanitizer coverage)
9+
10+
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).
11+
12+
## Syntax
13+
14+
> **`/fsanitize-coverage=edge`**\
15+
> **`/fsanitize-coverage=inline-8bit-counters`**\
16+
> **`/fsanitize-coverage=trace-cmp`**\
17+
> **`/fsanitize-coverage=trace-div`**\
18+
> **`/fno-sanitize-coverage=edge`**\
19+
> **`/fno-sanitize-coverage=inline-8bit-counters`**\
20+
> **`/fno-sanitize-coverage=trace-cmp`**\
21+
> **`/fno-sanitize-coverage=trace-div`**
22+
23+
## Remarks
24+
25+
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.
26+
27+
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.
28+
29+
The **`/fsanitize-coverage`** options are available beginning in Visual Studio 2022 version 17.0.
30+
31+
### Code coverage
32+
33+
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.
34+
35+
### Inline counters
36+
37+
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.
38+
39+
### Trace comparisons
40+
41+
The **`/fsanitize-coverage=trace-cmp`** compiler option instructs the compiler to insert calls to the following functions:
42+
43+
```C
44+
// Before each comparison instruction of the stated size.
45+
void __sanitizer_cov_trace_cmp1(uint8_t Arg1, uint8_t Arg2);
46+
void __sanitizer_cov_trace_cmp2(uint16_t Arg1, uint16_t Arg2);
47+
void __sanitizer_cov_trace_cmp4(uint32_t Arg1, uint32_t Arg2);
48+
void __sanitizer_cov_trace_cmp8(uint64_t Arg1, uint64_t Arg2);
49+
50+
// Before each comparison instruction of the stated size, if one of the operands (Arg1) is constant.
51+
void __sanitizer_cov_trace_const_cmp1(uint8_t Arg1, uint8_t Arg2);
52+
void __sanitizer_cov_trace_const_cmp2(uint16_t Arg1, uint16_t Arg2);
53+
void __sanitizer_cov_trace_const_cmp4(uint32_t Arg1, uint32_t Arg2);
54+
void __sanitizer_cov_trace_const_cmp8(uint64_t Arg1, uint64_t Arg2);
55+
```
56+
57+
Use **`/fno-sanitize-coverage=trace-cmp`** to disable this option if it's already provided or implied by another option.
58+
59+
### Trace divisions
60+
61+
The **`/fsanitize-coverage=trace-div`** compiler option instructs the compiler to insert calls to the following functions:
62+
63+
```C
64+
// Before a division instruction of the stated size.
65+
void __sanitizer_cov_trace_div4(uint32_t Val);
66+
void __sanitizer_cov_trace_div8(uint64_t Val);
67+
```
68+
69+
Use **`/fno-sanitize-coverage=trace-div`** to disable this option if it's already provided or implied by another option.
70+
71+
### To set the advanced compiler options
72+
73+
1. Open your project's **Property Pages** dialog box.
74+
75+
1. Select the **Configuration Properties** > **C/C++** > **Command Line** property page.
76+
77+
1. Modify the **Additional Options** property to set **/fsanitize-coverage** options.
78+
79+
1. Choose **OK** or **Apply** to save your changes.
80+
81+
## See also
82+
83+
[MSVC compiler options](compiler-options.md)\
84+
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)\
85+
[`/fsanitize` (Enable Sanitizers)](fsanitize.md)\
86+
[AddressSanitizer build and language reference](../../sanitizers/asan-building.md)

docs/build/reference/fsanitize.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
---
22
description: "Learn more about the /fsanitize (enable sanitizers) compiler option"
33
title: "/fsanitize (Enable sanitizers)"
4-
ms.date: 02/24/2021
5-
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"]
4+
ms.date: 09/15/2021
5+
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"]
66
helpviewer_keywords: ["/fsanitize [C++]", "-fsanitize=address [C++]", "address sanitizer compiler option [C++]", "/fsanitize-address-use-after-return", "/fno-sanitize-address-vcasan-lib"]
77
---
88
# `/fsanitize` (Enable sanitizers)
99

10-
Use the **`/fsanitize`** compiler options to enable sanitizers. As of Visual Studio 2019 16.9, the only supported sanitizer is [AddressSanitizer](../../sanitizers/asan.md).
10+
Use the **`/fsanitize`** compiler options to enable sanitizers.
1111

1212
## Syntax
1313

1414
> **`/fsanitize=address`**\
15+
> **`/fsanitize=fuzzer`**\
1516
> **`/fsanitize-address-use-after-return`**\
1617
> **`/fno-sanitize-address-vcasan-lib`**
1718
1819
## Remarks
1920

20-
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).
21+
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.
2122

22-
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).
23+
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.
24+
25+
The **`/fsanitize`** option doesn't allow comma-separated syntax, for example: **`/fsanitize=address,fuzzer`**. These options must be specified individually.
2326

24-
The **`/fsanitize`** options are available beginning in Visual Studio 2019 version 16.9.
27+
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).
2528

2629
### To set the **`/fsanitize=address`** compiler option in the Visual Studio development environment
2730

@@ -33,6 +36,16 @@ The **`/fsanitize`** options are available beginning in Visual Studio 2019 versi
3336

3437
1. Choose **OK** or **Apply** to save your changes.
3538

39+
### To set the **`/fsanitize=fuzzer`** compiler option in the Visual Studio development environment
40+
41+
1. Open your project's **Property Pages** dialog box.
42+
43+
1. Select the **Configuration Properties** > **C/C++** > **General** property page.
44+
45+
1. Modify the **Enable Fuzzer** property. To enable it, choose **Yes (/fsanitize=fuzzer)**.
46+
47+
1. Choose **OK** or **Apply** to save your changes.
48+
3649
### To set the advanced compiler options
3750

3851
1. Open your project's **Property Pages** dialog box.
@@ -52,6 +65,7 @@ The **`/fsanitize`** options are available beginning in Visual Studio 2019 versi
5265
[MSVC compiler options](compiler-options.md)\
5366
[MSVC compiler command-line syntax](compiler-command-line-syntax.md)\
5467
[`/INFERASANLIBS` (Use inferred sanitizer libs)](./inferasanlibs.md)\
68+
[`/fsanitize-coverage` (Configure sanitizer coverage)](fsanitize-coverage.md)\
5569
[AddressSanitizer overview](../../sanitizers/asan.md)\
5670
[AddressSanitizer known issues](../../sanitizers/asan-known-issues.md)\
5771
[AddressSanitizer build and language reference](../../sanitizers/asan-building.md)

0 commit comments

Comments
 (0)