-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Open
Labels
c++23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issueDoes the clang frontend diverge from gcc on this issuelambdaC++11 lambda expressionsC++11 lambda expressions
Description
Here is a snippet of C++23 code that compiles successfully with GCC 13 or later with -std=c++23 but fails to compile with Clang 17 or later (even with the std=c++23 option):
#include <stddef.h>
#include <stdint.h>
#include <immintrin.h>
__m128i __attribute__((__target__("sse4.2"))) SomeFunc(
const int32_t* src_ptr, size_t num_of_vectors) {
auto process_func = [](const int32_t* p) static __attribute__((__target__("sse4.2"))) {
__m128i v = _mm_loadu_si128(reinterpret_cast<const __m128i*>(p));
return _mm_mullo_epi32(v, _mm_set_epi32(15752961, 3969, 63, 1));
};
__m128i h = _mm_setzero_si128();
for (size_t i = 0; i < num_of_vectors; i++) {
h = _mm_add_epi32(_mm_sub_epi32(_mm_slli_epi32(h, 6), h),
process_func(src_ptr + 4 * i));
}
return h;
}
The results of compiling the above snippet with GCC 13, Clang 17, and Clang trunk can be found at https://godbolt.org/z/WfoqnnPqc.
Should Clang be updated to allow __attribute__((__target__("sse4.2"))) after the static specifier in C++23 lambda expressions?
On the other hand, the below snippet successfully compiles with Clang 17 or later in C++23 mode but fails to compile with GCC 13 in C++23 mode:
#include <stddef.h>
#include <stdint.h>
#include <immintrin.h>
__m128i __attribute__((__target__("sse4.2"))) SomeFunc(
const int32_t* src_ptr, size_t num_of_vectors) {
auto process_func = [](const int32_t* p) __attribute__((__target__("sse4.2"))) static {
__m128i v = _mm_loadu_si128(reinterpret_cast<const __m128i*>(p));
return _mm_mullo_epi32(v, _mm_set_epi32(15752961, 3969, 63, 1));
};
__m128i h = _mm_setzero_si128();
for (size_t i = 0; i < num_of_vectors; i++) {
h = _mm_add_epi32(_mm_sub_epi32(_mm_slli_epi32(h, 6), h),
process_func(src_ptr + 4 * i));
}
return h;
}
The results of compiling the above snippet with GCC 13, Clang 17, and Clang trunk can be found at https://godbolt.org/z/9ooT8bj1f.
Metadata
Metadata
Assignees
Labels
c++23clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issueDoes the clang frontend diverge from gcc on this issuelambdaC++11 lambda expressionsC++11 lambda expressions