[PATCH] D158348: [clang][X86] Add __cpuidex function to cpuid.h

Aiden Grossman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Aug 19 13:48:00 PDT 2023


aidengrossman added reviewers: aaron.ballman, glandium, mstorsjo, craig.topper.
aidengrossman added a comment.

This is an updated version of https://reviews.llvm.org/D150646 that uses `__has_builtin` instead of checking for a definition of `_MSC_EXTENSIONS`. This fixes the cases that I have received so far and shouldn't cause any other issues.

There is one thing that needs some discussion: include order relating to `intrin.h`. When using a MSVC target triple with `-fms-extensions` (and maybe in other cases), `intrin.h` needs to be included to get the declaration of the built-in (or otherwise `__has_builtin` won't detect it and it will error out later). This means that the way the patch is setup currently `intrin.h` needs to be included before `cpuid.h`. The only way I see to fix this is to use the MSVC `__cpuidex` signature which drops the `static` keyword. This makes the implementation slightly different from the GCC implementation (where they include `static`), but it would allow us to declare the function outside of the preprocessor conditional in `cpuid.h` which would make `cpuid.h` include-order-agnostic again with respect to `intrin.h`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158348/new/

https://reviews.llvm.org/D158348



More information about the cfe-commits mailing list