Skip to content

stb_image.h __cpuid fails to compile with clang-cl #978

@bernhardmgruber

Description

@bernhardmgruber

stb_image.h contains the function static int stbi__cpuid3(void) (on line 657 in my copy) to eventually detect if the CPU supports SSE. When _MSC_VER is defined, a different implementation is used, which runs fine when compiling with MSVC.

#ifdef _MSC_VER
#if _MSC_VER >= 1400  // not VC6
#include <intrin.h> // __cpuid
static int stbi__cpuid3(void)
{
   int info[4];
   __cpuid(info,1);
   return info[3];
}
#else
static int stbi__cpuid3(void)
{
   int res;
   __asm {
      mov  eax,1
      cpuid
      mov  res,edx
   }
   return res;
}
#endif
#else
... // gcc version
#endif

However, when compiling with clang-cl, which also defines _MSC_VER, a different intrin.h is used, where __cpuid does not take 2 arguments. Thus clang-cl fails to compile.

What worked for me is to exclude clang-cl and extend the prerocessor switch from

#ifdef _MSC_VER

to

#if defined(_MSC_VER) && !defined(__clang__)  // exclude clang-cl

.

Please adopt such a fix to support compiling with clang-cl.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions