Skip to content

Commit 5e93314

Browse files
authored
Merge pull request #6024 from davidmrdavid/dev/dajusto/document-oi-requirement-for-memcpy-param-overlap
Highlight the `/Oi` requirement for `memcpy-param-overlap`
2 parents c611b68 + 2cd6fb5 commit 5e93314

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

docs/sanitizers/error-memcpy-param-overlap.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ helpviewer_keywords: ["memcpy-param-overlap error", "AddressSanitizer error memc
99

1010
> Address Sanitizer Error: memcpy-param-overlap
1111
12+
> [!NOTE]
13+
> The `/Oi` flag is required to reliably detect `memcpy-param-overlap` errors. This flag tells the compiler to treat `memcpy` and other functions as intrinsics, which is necessary because some versions of the standard library implement them as such. Since ASan is a dynamic analysis tool, it can only detect errors with an observable runtime effect. Note that when `/O2` is also set, ASan may not be able to reliably detect `memcpy-param-overlap` errors because the intrinsic variant of these functions isn't guaranteed to be used. For more information, see [`/Oi` docs](../build/reference/oi-generate-intrinsic-functions.md).
14+
1215
The CRT function [`memcpy`](../c-runtime-library/reference/memcpy-wmemcpy.md) **doesn't support** overlapping memory. The CRT provides an alternative to `memcpy` that does support overlapping memory: [`memmove`](../c-runtime-library/reference/memmove-wmemmove.md).
1316

1417
A common error is to treat `memmove` as being semantically equivalent to `memcpy`.
@@ -39,8 +42,6 @@ cl example1.cpp /fsanitize=address /Zi /Oi
3942
devenv /debugexe example1.exe
4043
```
4144

42-
The [/Oi flag](../build/reference/oi-generate-intrinsic-functions.md) tells the compiler to treat `memcpy` and `memmove` as intrinsic functions. This is necessary because some versions of the standard library implement `memcpy` and `memmove` in the same way. Because ASAN is a dynamic analysis tool, it only detects errors with an observable runtime effect.
43-
4445
### Resulting error
4546

4647
:::image type="content" source="media/memcpy-param-overlap-example-1.png" alt-text="Screenshot of debugger displaying memcpy-param-overlap error in example 1.":::

0 commit comments

Comments
 (0)