clang/win: Stop force-including intrin.h everywhere.

MSVC and clang-cl offer a bunch of functions that are built-in to the compiler: Intrinsics.
When an intrinsic is called, the compiler can emit specialized code for intrinsics.
(It's free to emit a regular call to a function too though.)

intrin.h includes prototypes (and with clang-cl, definitions) for intrinsics. MSVC also supports
`#pragma intrinsics(name)`, which allows marking the intrinsic named "name" as something
that should preferably be treated as an intrinsic (roughly ~inlined) instead of as a call.  With this,
it is possible to manually declare an intrinsic and then use that pragma, and since it'll be
treated as an intrinsic, no linker error will happen.

clang-cl doesn't yet implement `#pragma intrinsic`, so e.g.

  void __cpuidex(int CPUInfo[4], int info_type, int ecxvalue);
  #pragma intrinsic(__cpuidex)
  // later, call __cpuidex()

will result in a linker error, since clang-cl sees the declaration for __cpuidex(), but then
clang-cl ignores the pragma line, and then later it thinks the call is just a call to a function
that isn't defined anywhere.

This is not a problem: Just #include <intrin.h> instead of manually declaring the function.
With clang-cl, intrin.h contains a definition of __cpuidex (and the other intrinsics), and
no linker error will be emitted (and the definition is always_inline, so it's fast).

There is just one wrinkle: Some system headers (e.g. windows.h) do manually declare
intrinsics, mark them `#pragma intrinsic`, and then call them from other inline functions
defined in system headers.  So if some of our code calls one of these other inline functions,
it needs intrin.h without us knowing about it.  Luckily, we know only a single function where
this is an issue in practice: SecureZeroMemory(), which calls __stosb.  So we had to add
explicit and mysterious includes for <intrin.h> to the two files that call that function. If
more examples of this pop up, we can reevaluate if we want to force-include this header
everywhere, but for now it seems overkill to inject this header into every translation unit
just because two translation units need it.

BUG=592745

Review-Url: https://codereview.chromium.org/2076483002
Cr-Original-Commit-Position: refs/heads/master@{#401613}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: ac7670452f51ecfd1061749b3d5e15f8544a55ee
This commit is contained in:
thakis 2016-06-23 08:35:42 -07:00 коммит произвёл Commit bot
Родитель f367ccd9e1
Коммит b73a5f100d
2 изменённых файлов: 0 добавлений и 12 удалений

Просмотреть файл

@ -5820,11 +5820,6 @@
# pattern.
'-Wno-missing-field-initializers',
# Many files use intrinsics without including this header.
# TODO(hans): Fix those files, or move this to sub-GYPs,
# https://crbug.com/592745
'/FIintrin.h',
# TODO(hans): Make this list shorter eventually, http://crbug.com/504657
'-Wno-microsoft-enum-value', # http://crbug.com/505296
'-Wno-unknown-pragmas', # http://crbug.com/505314

Просмотреть файл

@ -65,13 +65,6 @@ config("compiler") {
# experimental. See crbug.com/82385.
# Keep this in sync with the similar block in build/common.gypi
if (is_clang) {
cflags += [
# Many files use intrinsics without including this header.
# TODO(hans): Fix those files, or move this to sub-GYPs,
# https://crbug.com/592745
"/FIintrin.h",
]
if (visual_studio_version == "2013") {
cflags += [ "-fmsc-version=1800" ]
} else if (visual_studio_version == "2015") {