Skip to content

_xend() declaration in intrin.h may cause function multiversioning error on Windows #95133

@stampho

Description

@stampho

This is a simplified example to reproduce the issue:

#include <immintrin.h>

#pragma clang attribute push(__attribute__((target("avx"))), apply_to=function)
#include <atomic>
#pragma clang attribute pop

int main()
{
    return 0;
}

Build the example with:
clang-cl.exe /c main.cpp /Fomain.obj /nologo /std:c++20
or
clang-cl.exe /c main.cpp /Fomain.obj /nologo -D__RTM__

The result is:

In file included from main.cpp:1:
In file included from C:\tools\LLVM-18.1.6\lib\clang\18\include\immintrin.h:603:
C:\tools\LLVM-18.1.6\lib\clang\18\include\rtmintrin.h(36,1): error: attribute 'target' multiversioning cannot be combined with attribute 'always_inline'
   36 | _xend(void)
      | ^
C:\tools\LLVM-18.1.6\lib\clang\18\include\intrin.h(167,6): note: function multiversioning caused by this declaration
  167 | void _xend(void);
      |      ^
1 error generated.

I reproduce this with:

clang version 18.1.6
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Tools\LLVM-18.1.6\bin

and

Visual Studio Community 2022
17.10.1

The example is artificial, I have the same issue when building skia ( https://github.com/google/skia ) with clang-cl and c++20 enabled.
I'm not absolutely sure if this is really a clang issue but it seems reasonable to me to push attributes before including a header which declares a set of functions which also happen to use standard library functions.
Does the declaration of _xend() in intrin.h really necessary if the intrinsics are enabled?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions