Skip to content

cpuid.h doesn't like -masm=intel #127271

@Alcaro

Description

@Alcaro
#include <cpuid.h>

unsigned get_cpuid_max(unsigned ext, unsigned* sig)
{
	return __get_cpuid_max(ext, sig);
}

-masm=intel

Expected: Should work, like gcc; the relevant asm supports both at&t and intel syntax https://github.com/gcc-mirror/gcc/blob/master/gcc/config/i386/cpuid.h#L280

Actual: The clang version of that header is at&t syntax only https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/cpuid.h#L271, and returns

In file included from <source>:1:
/opt/compiler-explorer/clang-19.1.0/lib/clang/19/include/cpuid.h:309:5: error: unknown token in expression
  309 |     __cpuid(__leaf, __eax, __ebx, __ecx, __edx);
      |     ^
/opt/compiler-explorer/clang-19.1.0/lib/clang/19/include/cpuid.h:271:12: note: expanded from macro '__cpuid'
  271 |           "  cpuid\n" \
      |            ^
<inline asm>:2:11: note: instantiated into assembly here
    2 |           xchgq  %rbx,rdi
      |                  ^
In file included from <source>:1:
/opt/compiler-explorer/clang-19.1.0/lib/clang/19/include/cpuid.h:309:5: error: unknown token in expression
  309 |     __cpuid(__leaf, __eax, __ebx, __ecx, __edx);
      |     ^
/opt/compiler-explorer/clang-19.1.0/lib/clang/19/include/cpuid.h:270:11: note: expanded from macro '__cpuid'
  270 |     __asm("  xchgq  %%rbx,%q1\n" \
      |           ^
<inline asm>:4:10: note: instantiated into assembly here
    4 |   xchgq  %rbx,rdi
      |          ^

https://godbolt.org/z/qMoPs5cPW

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:headersHeaders provided by Clang, e.g. for intrinsics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions