diff options
Diffstat (limited to 'clang/test/SemaCXX')
19 files changed, 1024 insertions, 12 deletions
diff --git a/clang/test/SemaCXX/alloc-token.cpp b/clang/test/SemaCXX/alloc-token.cpp index be7acb7..2a11e33 100644 --- a/clang/test/SemaCXX/alloc-token.cpp +++ b/clang/test/SemaCXX/alloc-token.cpp @@ -1,7 +1,10 @@ // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -falloc-token-max=0 // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -fexperimental-new-constant-interpreter // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -falloc-token-mode=typehash -DMODE_TYPEHASH // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++23 -fsyntax-only -verify %s -falloc-token-max=2 -DTOKEN_MAX=2 +// RUN: %clang_cc1 -triple arm-linux-androideabi -std=c++23 -fsyntax-only -verify %s -falloc-token-max=2 -DTOKEN_MAX=2 +// RUN: %clang_cc1 -triple arm-linux-androideabi -std=c++23 -fsyntax-only -verify %s -falloc-token-max=2 -DTOKEN_MAX=2 -fexperimental-new-constant-interpreter #if !__has_builtin(__builtin_infer_alloc_token) #error "missing __builtin_infer_alloc_token" diff --git a/clang/test/SemaCXX/attr-cleanup.cpp b/clang/test/SemaCXX/attr-cleanup.cpp index 32d1068..6048b4e 100644 --- a/clang/test/SemaCXX/attr-cleanup.cpp +++ b/clang/test/SemaCXX/attr-cleanup.cpp @@ -27,3 +27,28 @@ namespace E { int v1 __attribute__((cleanup(c3))); // expected-error {{'c3' is not a single function}} } } + +namespace F { + int open() { return 0; } + void close(decltype(open()) *) {} + + void test1() { + auto fd [[gnu::cleanup(close)]] = open(); + } + + template <typename Ty> + void test2() { + Ty fd [[gnu::cleanup(close)]] = open(); + } + + template <typename Ty> + void test3() { + Ty fd [[gnu::cleanup(close)]] = open(); // #TEST3_CLEANUP + } + + int main() { + test2<int>(); + test3<float>(); // expected-error@#TEST3_CLEANUP {{'cleanup' function 'close' parameter has type 'decltype(open()) *' (aka 'int *') which is incompatible with type 'float *'}} \ + expected-note {{in instantiation of function template specialization 'F::test3<float>' requested here}} + } +} diff --git a/clang/test/SemaCXX/attr-malloc_span.cpp b/clang/test/SemaCXX/attr-malloc_span.cpp new file mode 100644 index 0000000..86622f6 --- /dev/null +++ b/clang/test/SemaCXX/attr-malloc_span.cpp @@ -0,0 +1,132 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s + +struct span_with_static { + void *ptr; + int n; + static int static_field; +}; + +span_with_static returns_span_with_static (void) __attribute((malloc_span)); // no-warning + +class SomeClass { +public: + int Data; +}; + +// Returning pointers to data members is not allowed. +struct DataMemberSpan { + int SomeClass::* member_ptr; + int n; +}; + +// expected-warning@+2 {{attribute only applies to functions that return span-like structures}} +// expected-note@+1 {{returned struct fields are not a supported combination}} +DataMemberSpan returns_data_member_span(void) __attribute((malloc_span)) { + return DataMemberSpan{}; +} + +// Returning pointers to member functions is not allowed. +struct MemberFuncSpan { + void (SomeClass::*member_func_ptr)(); + int n; +}; + +// expected-warning@+2 {{attribute only applies to functions that return span-like structures}} +// expected-note@+1 {{returned struct fields are not a supported combination}} +MemberFuncSpan returns_member_func_span(void) __attribute((malloc_span)) { + return MemberFuncSpan{}; +} + +template<typename FirstType, typename SecondType> +struct Pair { + FirstType first; + SecondType second; +}; + +Pair<int*, int> returns_templated_span1(void) __attribute((malloc_span)) { // no-warning + return Pair<int*, int>{}; +} + +Pair<int*, int*> returns_templated_span2(void) __attribute((malloc_span)) { // no-warning + return Pair<int*, int*>{}; +} + +// expected-warning@+2 {{attribute only applies to functions that return span-like structures}} +// expected-note@+1 {{returned struct fields are not a supported combination for a span-like type}} +Pair<int, int> returns_templated_span3(void) __attribute((malloc_span)) { + return Pair<int, int>{}; +} + +// Verify that semantic checks are done on dependent types. + +struct GoodSpan { + void *ptr; + int n; +}; + +struct BadSpan { + int n; +}; + +template <typename T> +// expected-warning@+2 {{'malloc_span' attribute only applies to functions that return span-like structures}} +// expected-note@+1 {{returned struct has 1 fields, expected 2}} +T produce_span() __attribute((malloc_span)) { + return T{}; +} + +void TestGoodBadSpan() { + produce_span<GoodSpan>(); // no-warnings + // expected-note@+1 {{in instantiation of function template specialization 'produce_span<BadSpan>' requested here}} + produce_span<BadSpan>(); +} + +// Ensure that trailing return types are also supported. +__attribute__((malloc_span)) auto trailing_return_type(int size) -> GoodSpan { // no-warning + return GoodSpan{}; +} + +template<typename T> +// expected-warning@+2 {{'malloc_span' attribute only applies to functions that return span-like structures}} +// expected-note@+1 {{returned struct has 1 fields, expected 2}} +__attribute__((malloc_span)) auto templated_trailing_return_type() -> T { + return T{}; +} + +void TestGoodBadTrailingReturnType() { + templated_trailing_return_type<GoodSpan>(); // no-warnings + // expected-note@+1 {{in instantiation of function template specialization 'templated_trailing_return_type<BadSpan>' requested here}} + templated_trailing_return_type<BadSpan>(); +} + +__attribute((malloc_span)) auto trailing_return_temmplate_good(void) -> Pair<int*, int> { // no-warning + return Pair<int*, int>{}; +} + +// expected-warning@+2 {{attribute only applies to functions that return span-like structures}} +// expected-note@+1 {{returned struct fields are not a supported combination for a span-like type}} +__attribute((malloc_span)) auto trailing_return_temmplate_bad(void) -> Pair<int, int> { + return Pair<int, int>{}; +} + +struct Base { + void *other_p; +}; + +struct ChildSpan : Base { + void *p; + int n; +}; + +// expected-warning@+2 {{attribute only applies to functions that return span-like structures}} +// expected-note@+1 {{returned type inherits from a base class}} +__attribute((malloc_span)) ChildSpan return_child_span(void); + +class VirtualBaseSpan : public virtual Base { + void *p; + int n; +}; + +// expected-warning@+2 {{attribute only applies to functions that return span-like structures}} +// expected-note@+1 {{returned type inherits from a base class}} +__attribute((malloc_span)) VirtualBaseSpan return_virtual_base_span(void); diff --git a/clang/test/SemaCXX/builtin-bswapg.cpp b/clang/test/SemaCXX/builtin-bswapg.cpp new file mode 100644 index 0000000..9d8d103 --- /dev/null +++ b/clang/test/SemaCXX/builtin-bswapg.cpp @@ -0,0 +1,230 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s + +void test_basic_type_checks() { + static_assert(__is_same(char, decltype(__builtin_bswapg((char)0))), ""); + static_assert(__is_same(unsigned char, decltype(__builtin_bswapg((unsigned char)0))), ""); + static_assert(__is_same(short, decltype(__builtin_bswapg((short)0))), ""); + static_assert(__is_same(unsigned short, decltype(__builtin_bswapg((unsigned short)0))), ""); + static_assert(__is_same(int, decltype(__builtin_bswapg((int)0))), ""); + static_assert(__is_same(unsigned int, decltype(__builtin_bswapg((unsigned int)0))), ""); + static_assert(__is_same(long, decltype(__builtin_bswapg((long)0))), ""); + static_assert(__is_same(unsigned long, decltype(__builtin_bswapg((unsigned long)0))), ""); + static_assert(__is_same(_BitInt(8), decltype(__builtin_bswapg((_BitInt(8))0))), ""); + static_assert(__is_same(_BitInt(16), decltype(__builtin_bswapg((_BitInt(16))0))), ""); + static_assert(__is_same(_BitInt(32), decltype(__builtin_bswapg((_BitInt(32))0))), ""); + static_assert(__is_same(_BitInt(64), decltype(__builtin_bswapg((_BitInt(64))0))), ""); + static_assert(__is_same(_BitInt(128), decltype(__builtin_bswapg((_BitInt(128))0))), ""); +} + +template<typename T> +void test_template_type_check() { + static_assert(__is_same(T, decltype(__builtin_bswapg(T{}))), + "bswapg should return the same type as its argument"); + constexpr T zero{}; + constexpr T max = ~T{}; + constexpr T one = T{1}; + + static_assert(__is_same(T, decltype(__builtin_bswapg(zero))), ""); + static_assert(__is_same(T, decltype(__builtin_bswapg(max))), ""); + static_assert(__is_same(T, decltype(__builtin_bswapg(one))), ""); +} +template void test_template_type_check<char>(); +template void test_template_type_check<unsigned char>(); +template void test_template_type_check<short>(); +template void test_template_type_check<unsigned short>(); +template void test_template_type_check<int>(); +template void test_template_type_check<unsigned int>(); +template void test_template_type_check<long>(); +template void test_template_type_check<_BitInt(8)>(); +template void test_template_type_check<_BitInt(16)>(); +template void test_template_type_check<_BitInt(32)>(); +template void test_template_type_check<_BitInt(64)>(); +template void test_template_type_check<_BitInt(128)>(); + +void test_lambda_type_checks() { + auto lambda = [](auto x) { + static_assert(__is_same(decltype(x), decltype(__builtin_bswapg(x))), + "bswapg in lambda should preserve type"); + return __builtin_bswapg(x); + }; + auto result_long = lambda(42UL); + static_assert(__is_same(unsigned long, decltype(result_long)), ""); + + auto result_int = lambda(42); + static_assert(__is_same(int, decltype(result_int)), ""); + + auto result_short = lambda(static_cast<short>(42)); + static_assert(__is_same(short, decltype(result_short)), ""); + + auto result_char = lambda(static_cast<char>(42)); + static_assert(__is_same(char, decltype(result_char)), ""); +} + +decltype(auto) test_decltype_auto(int x) { + return __builtin_bswapg(x); +} + +void test_decltype_auto_check() { + int x = 42; + auto result = test_decltype_auto(x); + static_assert(__is_same(int, decltype(result)), ""); +} + +template<auto Value> +struct ValueTemplateTypeTest { + using value_type = decltype(Value); + using result_type = decltype(__builtin_bswapg(Value)); + + static constexpr bool type_matches = __is_same(value_type, result_type); + static_assert(type_matches, "Value template bswapg should preserve type"); + + static constexpr auto swapped_value = __builtin_bswapg(Value); +}; + +template<auto... Values> +void test_template_pack_types() { + static_assert((__is_same(decltype(Values), decltype(__builtin_bswapg(Values))) && ...), "All pack elements should preserve type"); +} + +template struct ValueTemplateTypeTest<0x1234>; +template struct ValueTemplateTypeTest<0x12345678UL>; +template struct ValueTemplateTypeTest<(short)0x1234>; +template struct ValueTemplateTypeTest<(char)0x12>; + +template<typename T> +void test_invalid_type() { + __builtin_bswapg(T{}); // #invalid_type_use +} + +void test_basic_errors() { + test_invalid_type<float>(); + // expected-note@-1 {{in instantiation of function template specialization 'test_invalid_type<float>' requested here}} + // expected-error@#invalid_type_use {{1st argument must be a scalar integer type (was 'float')}} + + test_invalid_type<double>(); + // expected-note@-1 {{in instantiation of function template specialization 'test_invalid_type<double>' requested here}} + // expected-error@#invalid_type_use {{1st argument must be a scalar integer type (was 'double')}} + + test_invalid_type<void*>(); + // expected-note@-1 {{in instantiation of function template specialization 'test_invalid_type<void *>' requested here}} + // expected-error@#invalid_type_use {{1st argument must be a scalar integer type (was 'void *')}} +} + +template<typename T> +auto test_dependent_context(T value) -> decltype(__builtin_bswapg(value)) { // #dependent_use + return __builtin_bswapg(value); +} + +void test_dependent_errors() { + test_dependent_context(1.0f); + // expected-error@-1 {{no matching function for call to 'test_dependent_context'}} + // expected-note@#dependent_use {{candidate template ignored: substitution failure [with T = float]: 1st argument must be a scalar integer type (was 'float')}} + test_dependent_context(1.0l); + // expected-error@-1 {{no matching function for call to 'test_dependent_context'}} + // expected-note@#dependent_use {{candidate template ignored: substitution failure [with T = long double]: 1st argument must be a scalar integer type (was 'long double')}} + test_dependent_context("hello"); + // expected-error@-1 {{no matching function for call to 'test_dependent_context'}} + // expected-note@#dependent_use {{candidate template ignored: substitution failure [with T = const char *]: 1st argument must be a scalar integer type (was 'const char *')}} +} + +void test_lambda_errors() { + auto lambda = [](auto x) { + return __builtin_bswapg(x); // #lambda_use + }; + + lambda(1.0f); + // expected-error@#lambda_use {{1st argument must be a scalar integer type (was 'float')}} + // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(anonymous class)::operator()<float>' requested here}} + lambda(1.0l); + // expected-error@#lambda_use {{1st argument must be a scalar integer type (was 'long double')}} + // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(anonymous class)::operator()<long double>' requested here}} + lambda("hello"); + // expected-error@#lambda_use {{1st argument must be a scalar integer type (was 'const char *')}} + // expected-note@-2 {{in instantiation of function template specialization 'test_lambda_errors()::(anonymous class)::operator()<const char *>' requested here}} +} + +template <class... Args> void test_variadic_template_argument_count(Args... args) { + int result = __builtin_bswapg(args...); // #arg_use +} +void test_variadic_template_args() { + test_variadic_template_argument_count(); + // expected-error@#arg_use {{too few arguments to function call, expected 1, have 0}} + // expected-note@-2 {{in instantiation of function template specialization 'test_variadic_template_argument_count<>' requested here}} + test_variadic_template_argument_count(1); + test_variadic_template_argument_count(1, 2); + // expected-error@#arg_use {{too many arguments to function call, expected 1, have 2}} + // expected-note@-2 {{in instantiation of function template specialization 'test_variadic_template_argument_count<int, int>' requested here}} +} + +void test_lvalue_reference(int& a) { + auto result = __builtin_bswapg(a); + static_assert(__is_same(int, decltype(result)), "Should decay reference to value type"); +} + +void test_const_lvalue_reference(const int& a) { + auto result = __builtin_bswapg(a); + static_assert(__is_same(int, decltype(result)), "Should decay const reference to value type"); +} + +void test_rvalue_reference(int&& a) { + auto result = __builtin_bswapg(a); + static_assert(__is_same(int, decltype(result)), "Should decay rvalue reference to value type"); +} + +void test_const_rvalue_reference(const int&& a) { + auto result = __builtin_bswapg(a); + static_assert(__is_same(int, decltype(result)), "Should decay const rvalue reference to value type"); +} + +void test_array() { + int arr[4] = {0x12, 0x34, 0x56, 0x78}; + __builtin_bswapg(arr); + // expected-error@-1 {{1st argument must be a scalar integer type (was 'int[4]')}} +} + +void test_pointer() { + int x = 0x12345678; + int *ptr = &x; + __builtin_bswapg(ptr); + // expected-error@-1 {{1st argument must be a scalar integer type (was 'int *')}} +} + +enum BasicEnum { + ENUM_VALUE1 = 0x1234, + ENUM_VALUE2 = 0x34120000 +}; + +void test_enum() { + const BasicEnum e = ENUM_VALUE1; + static_assert(__builtin_bswapg(e) == ENUM_VALUE2, ""); +} + +class testClass { +public: + int value; + testClass(int v) : value(v) {} + + int getValue() { return value; } +}; + +void test_class() { + testClass c((int)0x12345678); + __builtin_bswapg(c); + // expected-error@-1 {{1st argument must be a scalar integer type (was 'testClass')}} +} + +void test_nullptr() { + __builtin_bswapg(nullptr); + // expected-error@-1 {{1st argument must be a scalar integer type (was 'std::nullptr_t')}} +} + +void test_bitint() { + static_assert(__builtin_bswapg((_BitInt(8))0x12) == (_BitInt(8))0x12, ""); + static_assert(__builtin_bswapg((_BitInt(16))0x1234) == (_BitInt(16))0x3412, ""); + static_assert(__builtin_bswapg((_BitInt(32))0x00001234) == (_BitInt(32))0x34120000, ""); + static_assert(__builtin_bswapg((_BitInt(64))0x0000000000001234) == (_BitInt(64))0x3412000000000000, ""); + static_assert(__builtin_bswapg(~(_BitInt(128))0) == (~(_BitInt(128))0), ""); + static_assert(__builtin_bswapg((_BitInt(24))0x1234) == (_BitInt(24))0x3412, ""); + // expected-error@-1 {{_BitInt type '_BitInt(24)' (24 bits) must be a multiple of 16 bits for byte swapping}} +} diff --git a/clang/test/SemaCXX/constant-expression-p2280r4.cpp b/clang/test/SemaCXX/constant-expression-p2280r4.cpp index 5cbfaff..21283c0 100644 --- a/clang/test/SemaCXX/constant-expression-p2280r4.cpp +++ b/clang/test/SemaCXX/constant-expression-p2280r4.cpp @@ -278,11 +278,13 @@ namespace dropped_note { namespace dynamic { struct A {virtual ~A();}; struct B : A {}; - void f(A& a) { + void f(A& a) { // interpreter-note 2{{declared here}} constexpr B* b = dynamic_cast<B*>(&a); // expected-error {{must be initialized by a constant expression}} \ - // nointerpreter-note {{dynamic_cast applied to object 'a' whose dynamic type is not constant}} + // nointerpreter-note {{dynamic_cast applied to object 'a' whose dynamic type is not constant}} \ + // interpreter-note {{pointer to 'a' is not a constant expression}} constexpr void* b2 = dynamic_cast<void*>(&a); // expected-error {{must be initialized by a constant expression}} \ - // nointerpreter-note {{dynamic_cast applied to object 'a' whose dynamic type is not constant}} + // nointerpreter-note {{dynamic_cast applied to object 'a' whose dynamic type is not constant}} \ + // interpreter-note {{pointer to 'a' is not a constant expression}} } } @@ -415,9 +417,7 @@ namespace InvalidConstexprFn { }; constexpr int virtual_call(const PolyBase& b) { return b.get(); } constexpr auto* type(const PolyBase& b) { return &typeid(b); } - // FIXME: Intepreter doesn't support constexpr dynamic_cast yet. - constexpr const void* dyncast(const PolyBase& b) { return dynamic_cast<const void*>(&b); } // interpreter-error {{constexpr function never produces a constant expression}} \ - // interpreter-note 2 {{subexpression not valid in a constant expression}} + constexpr const void* dyncast(const PolyBase& b) { return dynamic_cast<const void*>(&b); } constexpr int sub(const int (&a)[], const int (&b)[]) { return a-b; } constexpr const int* add(const int &a) { return &a+3; } @@ -427,7 +427,7 @@ namespace InvalidConstexprFn { static_assert(get_derived_member(Derived{}) == 0); static_assert(virtual_call(PolyDerived{}) == 1); static_assert(type(PolyDerived{}) != nullptr); - static_assert(dyncast(PolyDerived{}) != nullptr); // interpreter-error {{static assertion expression is not an integral constant expression}} interpreter-note {{in call}} + static_assert(dyncast(PolyDerived{}) != nullptr); static_assert(sub(arr, arr) == 0); static_assert(add(arr[0]) == &arr[3]); } diff --git a/clang/test/SemaCXX/constexpr-x86-avx-builtins.cpp b/clang/test/SemaCXX/constexpr-x86-avx-builtins.cpp new file mode 100644 index 0000000..724aff3 --- /dev/null +++ b/clang/test/SemaCXX/constexpr-x86-avx-builtins.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++20 -ffreestanding -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown -target-feature +avx -verify %s + +#include <immintrin.h> +#include "../CodeGen/X86/builtin_test_helpers.h" + +namespace Test_mm256_cvtpd_ps { +namespace OK { +constexpr __m256d a = { 0.0, -1.0, +2.0, +3.5 }; +TEST_CONSTEXPR(match_m128(_mm256_cvtpd_ps(a), 0.0f, -1.0f, +2.0f, +3.5f)); +} +namespace Inexact { +constexpr __m256d a = { 1.0000000000000002, 0.0, 0.0, 0.0 }; +constexpr __m128 r = _mm256_cvtpd_ps(a); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avxintrin.h:* {{compile time floating point arithmetic suppressed in strict evaluation modes}} +// expected-note@-3 {{in call to '_mm256_cvtpd_ps({1.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00})'}} +} +} diff --git a/clang/test/SemaCXX/constexpr-x86-avx512f-builtins.cpp b/clang/test/SemaCXX/constexpr-x86-avx512f-builtins.cpp new file mode 100644 index 0000000..0d2a82c --- /dev/null +++ b/clang/test/SemaCXX/constexpr-x86-avx512f-builtins.cpp @@ -0,0 +1,230 @@ +// RUN: %clang_cc1 -std=c++20 -ffreestanding -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown -target-feature +avx512f -verify %s + +#include <immintrin.h> +#include "../CodeGen/X86/builtin_test_helpers.h" + +namespace Test_mm_mask_cvtsd_ss { +namespace OK { +constexpr __m128 src = { 9.0f, 5.0f, 6.0f, 7.0f }; +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b = { -1.0, 42.0 }; +TEST_CONSTEXPR(match_m128(_mm_mask_cvtsd_ss(src, 0x1, a, b), -1.0f, 2.0f, 3.0f, 4.0f)); +} +namespace MaskOff { +constexpr __m128 src = { 9.0f, 5.0f, 6.0f, 7.0f }; +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b = { -1.0, 42.0 }; +TEST_CONSTEXPR(match_m128(_mm_mask_cvtsd_ss(src, 0x0, a, b), 9.0f, 2.0f, 3.0f, 4.0f)); +} +namespace MaskOffInexact { +constexpr __m128 src = { 9.0f, 5.0f, 6.0f, 7.0f }; +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b_inexact = { 1.0000000000000002, 0.0 }; +constexpr __m128 r = _mm_mask_cvtsd_ss(src, 0x0, a, b_inexact); +TEST_CONSTEXPR(match_m128(r, 9.0f, 2.0f, 3.0f, 4.0f)); +} +namespace MaskOnInexact { +constexpr __m128 src = { 9.0f, 5.0f, 6.0f, 7.0f }; +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b_inexact = { 1.0000000000000002, 0.0 }; +constexpr __m128 r = _mm_mask_cvtsd_ss(src, 0x1, a, b_inexact); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{compile time floating point arithmetic suppressed in strict evaluation modes}} +// expected-note@-3 {{in call to '_mm_mask_cvtsd_ss({9.000000e+00, 5.000000e+00, 6.000000e+00, 7.000000e+00}, 1, {1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00}, {1.000000e+00, 0.000000e+00})'}} +} +namespace MaskOnInf { +constexpr __m128 src = { 9.0f, 5.0f, 6.0f, 7.0f }; +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b_inf = { __builtin_huge_val(), 0.0 }; +constexpr __m128 r = _mm_mask_cvtsd_ss(src, 0x1, a, b_inf); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@-3 {{in call to '_mm_mask_cvtsd_ss({9.000000e+00, 5.000000e+00, 6.000000e+00, 7.000000e+00}, 1, {1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00}, {INF, 0.000000e+00})'}} +} +namespace MaskOnNaN { +constexpr __m128 src = { 9.0f, 5.0f, 6.0f, 7.0f }; +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b_nan = { __builtin_nan(""), 0.0 }; +constexpr __m128 r = _mm_mask_cvtsd_ss(src, 0x1, a, b_nan); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@-3 {{in call to '_mm_mask_cvtsd_ss({9.000000e+00, 5.000000e+00, 6.000000e+00, 7.000000e+00}, 1, {1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00}, {nan, 0.000000e+00})'}} +} +namespace MaskOnSubnormal { +constexpr __m128 src = { 9.0f, 5.0f, 6.0f, 7.0f }; +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b_sub = { 1e-310, 0.0 }; +constexpr __m128 r = _mm_mask_cvtsd_ss(src, 0x1, a, b_sub); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{compile time floating point arithmetic suppressed in strict evaluation modes}} +// expected-note@-3 {{in call to '_mm_mask_cvtsd_ss({9.000000e+00, 5.000000e+00, 6.000000e+00, 7.000000e+00}, 1, {1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00}, {1.000000e-310, 0.000000e+00})'}} +} +} + +namespace Test_mm_maskz_cvtsd_ss { +namespace OK { +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b = { -1.0, 42.0 }; +TEST_CONSTEXPR(match_m128(_mm_maskz_cvtsd_ss(0x1, a, b), -1.0f, 2.0f, 3.0f, 4.0f)); +} +namespace MaskOff { +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b = { -1.0, 42.0 }; +TEST_CONSTEXPR(match_m128(_mm_maskz_cvtsd_ss(0x0, a, b), 0.0f, 2.0f, 3.0f, 4.0f)); +} +namespace MaskOffInexact { +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b_inexact = { 1.0000000000000002, 0.0 }; +TEST_CONSTEXPR(match_m128(_mm_maskz_cvtsd_ss(0x0, a, b_inexact), 0.0f, 2.0f, 3.0f, 4.0f)); +} +namespace MaskOnInf { +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b_inf = { __builtin_huge_val(), 0.0 }; +constexpr __m128 r = _mm_maskz_cvtsd_ss(0x1, a, b_inf); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@-3 {{in call to '_mm_maskz_cvtsd_ss(1, {1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00}, {INF, 0.000000e+00})'}} +} +namespace MaskOnNaN { +constexpr __m128 a = { 1.0f, 2.0f, 3.0f, 4.0f }; +constexpr __m128d b_nan = { __builtin_nan(""), 0.0 }; +constexpr __m128 r = _mm_maskz_cvtsd_ss(0x1, a, b_nan); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@-3 {{in call to '_mm_maskz_cvtsd_ss(1, {1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00}, {nan, 0.000000e+00})'}} +} +} + +namespace Test_mm512_cvtpd_ps { +namespace OK { +constexpr __m512d a = { -1.0, +2.0, +4.0, +8.0, +16.0, +32.0, +64.0, +128.0 }; +TEST_CONSTEXPR(match_m256(_mm512_cvtpd_ps(a), -1.0f, +2.0f, +4.0f, +8.0f, +16.0f, +32.0f, +64.0f, +128.0f)); +} +namespace Inexact { +constexpr __m512d a = { 1.0000000000000002, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; +constexpr __m256 r = _mm512_cvtpd_ps(a); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{compile time floating point arithmetic suppressed in strict evaluation modes}} +// expected-note@-3 {{in call to '_mm512_cvtpd_ps({1.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00, 0.000000e+00})'}} +} +} + +namespace Test_mm512_mask_cvtpd_ps { +namespace OK { +constexpr __m256 src = { 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a = { -1.0, +2.0, +4.0, +8.0, +16.0, +32.0, +64.0, +128.0 }; +TEST_CONSTEXPR(match_m256(_mm512_mask_cvtpd_ps(src, 0x05, a), -1.0f, 9.0f, +4.0f, 9.0f, 9.0f, 9.0f, 9.0f, 9.0f)); +} +namespace MaskOffInexact { +constexpr __m256 src = { 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a_inexact = { -1.0, +2.0, +4.0, +8.0, +16.0, 1.0000000000000002, +64.0, +128.0 }; +TEST_CONSTEXPR(match_m256(_mm512_mask_cvtpd_ps(src, 0b11011111, a_inexact), -1.0f, +2.0f, +4.0f, +8.0f, +16.0f, 9.0f, +64.0f, +128.0f)); +} +namespace MaskOffInf { +constexpr __m256 src = { 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a_inf = { -1.0, +2.0, +4.0, +8.0, +16.0, __builtin_huge_val(), +64.0, +128.0 }; +TEST_CONSTEXPR(match_m256(_mm512_mask_cvtpd_ps(src, 0x1F, a_inf), -1.0f, +2.0f, +4.0f, +8.0f, +16.0f, 9.0f, 9.0f, 9.0f)); +} +namespace MaskOffNaN { +constexpr __m256 src = { 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a_nan = { -1.0, +2.0, +4.0, +8.0, +16.0, __builtin_nan(""), +64.0, +128.0 }; +TEST_CONSTEXPR(match_m256(_mm512_mask_cvtpd_ps(src, 0x1F, a_nan), -1.0f, +2.0f, +4.0f, +8.0f, +16.0f, 9.0f, 9.0f, 9.0f)); +} +namespace MaskOnInf { +constexpr __m256 src = { 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a_inf = { -1.0, +2.0, +4.0, __builtin_huge_val(), +16.0, +32.0, +64.0, +128.0 }; +constexpr __m256 r = _mm512_mask_cvtpd_ps(src, 0x08, a_inf); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@-3 {{in call to '_mm512_mask_cvtpd_ps({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 8, {-1.000000e+00, 2.000000e+00, 4.000000e+00, INF, 1.600000e+01, 3.200000e+01, 6.400000e+01, 1.280000e+02})'}} +} +namespace MaskOnNaN { +constexpr __m256 src = { 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a_nan = { -1.0, +2.0, +4.0, __builtin_nan(""), +16.0, +32.0, +64.0, +128.0 }; +constexpr __m256 r = _mm512_mask_cvtpd_ps(src, 0x08, a_nan); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@-3 {{in call to '_mm512_mask_cvtpd_ps({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 8, {-1.000000e+00, 2.000000e+00, 4.000000e+00, nan, 1.600000e+01, 3.200000e+01, 6.400000e+01, 1.280000e+02})'}} +} +} + +namespace Test_mm512_maskz_cvtpd_ps { +namespace OK { +constexpr __m512d a = { -1.0, +2.0, +4.0, +8.0, +16.0, +32.0, +64.0, +128.0 }; +TEST_CONSTEXPR(match_m256(_mm512_maskz_cvtpd_ps(0x81, a), -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, +128.0f)); +} +namespace MaskOffInexact { +constexpr __m512d a_inexact = { -1.0, +2.0, +4.0, +8.0, +16.0, 1.0000000000000002, +64.0, +128.0 }; +TEST_CONSTEXPR(match_m256(_mm512_maskz_cvtpd_ps(0b11011111, a_inexact), -1.0f, +2.0f, +4.0f, +8.0f, +16.0f, 0.0f, +64.0f, +128.0f)); +} +namespace MaskOffInf { +constexpr __m512d a_inf = { -1.0, +2.0, +4.0, +8.0, +16.0, __builtin_huge_val(), +64.0, +128.0 }; +TEST_CONSTEXPR(match_m256(_mm512_maskz_cvtpd_ps(0x1F, a_inf), -1.0f, +2.0f, +4.0f, +8.0f, +16.0f, 0.0f, 0.0f, 0.0f)); +} +namespace MaskOffNaN { +constexpr __m512d a_nan = { -1.0, +2.0, +4.0, +8.0, +16.0, __builtin_nan(""), +64.0, +128.0 }; +TEST_CONSTEXPR(match_m256(_mm512_maskz_cvtpd_ps(0x1F, a_nan), -1.0f, +2.0f, +4.0f, +8.0f, +16.0f, 0.0f, 0.0f, 0.0f)); +} +namespace MaskOnInf { +constexpr __m512d a_inf = { -1.0, +2.0, +4.0, __builtin_huge_val(), +16.0, +32.0, +64.0, +128.0 }; +constexpr __m256 r = _mm512_maskz_cvtpd_ps(0x08, a_inf); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@-3 {{in call to '_mm512_maskz_cvtpd_ps(8, {-1.000000e+00, 2.000000e+00, 4.000000e+00, INF, 1.600000e+01, 3.200000e+01, 6.400000e+01, 1.280000e+02})'}} +} +namespace MaskOnNaN { +constexpr __m512d a_nan = { -1.0, +2.0, +4.0, __builtin_nan(""), +16.0, +32.0, +64.0, +128.0 }; +constexpr __m256 r = _mm512_maskz_cvtpd_ps(0x08, a_nan); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@-3 {{in call to '_mm512_maskz_cvtpd_ps(8, {-1.000000e+00, 2.000000e+00, 4.000000e+00, nan, 1.600000e+01, 3.200000e+01, 6.400000e+01, 1.280000e+02})'}} +} +} + +namespace Test_mm512_cvtpd_pslo { +namespace OK { +constexpr __m512d a = { -1.0, +2.0, +4.0, +8.0, +16.0, +32.0, +64.0, +128.0 }; +TEST_CONSTEXPR(match_m512(_mm512_cvtpd_pslo(a), -1.0f, +2.0f, +4.0f, +8.0f, +16.0f, +32.0f, +64.0f, +128.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); +} +} + +namespace Test_mm512_mask_cvtpd_pslo { +namespace OK { +constexpr __m512 src = (__m512){ 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f, + 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a = { -1.0, +2.0, +4.0, +8.0, +16.0, +32.0, +64.0, +128.0 }; +TEST_CONSTEXPR(match_m512(_mm512_mask_cvtpd_pslo(src, 0x3, a), -1.0f, +2.0f, 9.0f, 9.0f, 9.0f, 9.0f, 9.0f, 9.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); +} +namespace MaskOffInf { +constexpr __m512 src = (__m512){ 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f, + 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a_inf = { -1.0, +2.0, __builtin_huge_val(), +8.0, +16.0, +32.0, +64.0, +128.0 }; +TEST_CONSTEXPR(match_m512(_mm512_mask_cvtpd_pslo(src, 0x3, a_inf), -1.0f, +2.0f, 9.0f, 9.0f, 9.0f, 9.0f, 9.0f, 9.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); +} +namespace MaskOffNaN { +constexpr __m512 src = (__m512){ 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f, + 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a_nan = { -1.0, +2.0, +4.0, __builtin_nan(""), +16.0, +32.0, +64.0, +128.0 }; +TEST_CONSTEXPR(match_m512(_mm512_mask_cvtpd_pslo(src, 0x7, a_nan), -1.0f, +2.0f, +4.0f, 9.0f, 9.0f, 9.0f, 9.0f, 9.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f)); +} +namespace MaskOnInf { +constexpr __m512 src = (__m512){ 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f, + 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a_inf = { -1.0, +2.0, __builtin_huge_val(), +8.0, +16.0, +32.0, +64.0, +128.0 }; +constexpr __m512 r = _mm512_mask_cvtpd_pslo(src, 0x4, a_inf); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@avx512fintrin.h:* {{in call to '_mm512_mask_cvtpd_ps({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 4, {-1.000000e+00, 2.000000e+00, INF, 8.000000e+00, 1.600000e+01, 3.200000e+01, 6.400000e+01, 1.280000e+02})'}} +// expected-note@-4 {{in call to '_mm512_mask_cvtpd_pslo({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 4, {-1.000000e+00, 2.000000e+00, INF, 8.000000e+00, 1.600000e+01, 3.200000e+01, 6.400000e+01, 1.280000e+02})'}} +} +namespace MaskOnNaN { +constexpr __m512 src = (__m512){ 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f, + 9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f,9.0f }; +constexpr __m512d a_nan = { -1.0, +2.0, __builtin_nan(""), +8.0, +16.0, +32.0, +64.0, +128.0 }; +constexpr __m512 r = _mm512_mask_cvtpd_pslo(src, 0x4, a_nan); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512fintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@avx512fintrin.h:* {{in call to '_mm512_mask_cvtpd_ps({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 4, {-1.000000e+00, 2.000000e+00, nan, 8.000000e+00, 1.600000e+01, 3.200000e+01, 6.400000e+01, 1.280000e+02})'}} +// expected-note@-4 {{in call to '_mm512_mask_cvtpd_pslo({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 4, {-1.000000e+00, 2.000000e+00, nan, 8.000000e+00, 1.600000e+01, 3.200000e+01, 6.400000e+01, 1.280000e+02})'}} +} +} diff --git a/clang/test/SemaCXX/constexpr-x86-avx512vl-builtins.cpp b/clang/test/SemaCXX/constexpr-x86-avx512vl-builtins.cpp new file mode 100644 index 0000000..bdce60a --- /dev/null +++ b/clang/test/SemaCXX/constexpr-x86-avx512vl-builtins.cpp @@ -0,0 +1,120 @@ +// RUN: %clang_cc1 -std=c++20 -ffreestanding -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown -target-feature +avx512f -target-feature +avx512vl -verify %s + +#include <immintrin.h> +#include "../CodeGen/X86/builtin_test_helpers.h" + +namespace Test_mm_mask_cvtpd_ps { +namespace OK { +constexpr __m128 src = { 9.0f, 9.0f, 9.0f, 9.0f }; +constexpr __m128d a = { -1.0, +2.0 }; +TEST_CONSTEXPR(match_m128(_mm_mask_cvtpd_ps(src, 0x3, a), -1.0f, +2.0f, 9.0f, 9.0f)); +} +namespace Partial { +constexpr __m128 src = { 9.0f, 9.0f, 9.0f, 9.0f }; +constexpr __m128d a = { -1.0, +2.0 }; +TEST_CONSTEXPR(match_m128(_mm_mask_cvtpd_ps(src, 0x1, a), -1.0f, 9.0f, 9.0f, 9.0f)); +} +namespace MaskOffInexact { +constexpr __m128 src = { 9.0f, 9.0f, 9.0f, 9.0f }; +constexpr __m128d a_inexact = { -1.0, 1.0000000000000002 }; +TEST_CONSTEXPR(match_m128(_mm_mask_cvtpd_ps(src, 0x1, a_inexact), -1.0f, 9.0f, 9.0f, 9.0f)); +} +namespace MaskOnInexact { +constexpr __m128 src = { 9.0f, 9.0f, 9.0f, 9.0f }; +constexpr __m128d a_inexact = { -1.0, 1.0000000000000002 }; +constexpr __m128 r = _mm_mask_cvtpd_ps(src, 0x2, a_inexact); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512vlintrin.h:* {{compile time floating point arithmetic suppressed in strict evaluation modes}} +// expected-note@-3 {{in call to '_mm_mask_cvtpd_ps({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 2, {-1.000000e+00, 1.000000e+00})'}} +} +namespace MaskOnInf { +constexpr __m128 src = { 9.0f, 9.0f, 9.0f, 9.0f }; +constexpr __m128d a_inf = { -1.0, __builtin_huge_val() }; +constexpr __m128 r = _mm_mask_cvtpd_ps(src, 0x2, a_inf); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512vlintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@-3 {{in call to '_mm_mask_cvtpd_ps({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 2, {-1.000000e+00, INF})'}} +} +namespace MaskOnNaN { +constexpr __m128 src = { 9.0f, 9.0f, 9.0f, 9.0f }; +constexpr __m128d a_nan = { -1.0, __builtin_nan("") }; +constexpr __m128 r = _mm_mask_cvtpd_ps(src, 0x2, a_nan); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512vlintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@-3 {{in call to '_mm_mask_cvtpd_ps({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 2, {-1.000000e+00, nan})'}} +} +} + +namespace Test_mm_maskz_cvtpd_ps { +namespace OK { +constexpr __m128d a = { -1.0, +2.0 }; +TEST_CONSTEXPR(match_m128(_mm_maskz_cvtpd_ps(0x1, a), -1.0f, 0.0f, 0.0f, 0.0f)); +} +namespace MaskOffInexact { +constexpr __m128d a_inexact = { -1.0, 1.0000000000000002 }; +TEST_CONSTEXPR(match_m128(_mm_maskz_cvtpd_ps(0x1, a_inexact), -1.0f, 0.0f, 0.0f, 0.0f)); +} +namespace MaskOnInf { +constexpr __m128d a_inf = { -1.0, __builtin_huge_val() }; +constexpr __m128 r = _mm_maskz_cvtpd_ps(0x2, a_inf); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512vlintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@-3 {{in call to '_mm_maskz_cvtpd_ps(2, {-1.000000e+00, INF})'}} +} +namespace MaskOnNaN { +constexpr __m128d a_nan = { -1.0, __builtin_nan("") }; +constexpr __m128 r = _mm_maskz_cvtpd_ps(0x2, a_nan); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avx512vlintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@-3 {{in call to '_mm_maskz_cvtpd_ps(2, {-1.000000e+00, nan})'}} +} +} + +namespace Test_mm256_mask_cvtpd_ps { +namespace OK { +constexpr __m128 src = { 9.0f, 9.0f, 9.0f, 9.0f }; +constexpr __m256d a = { 0.0, -1.0, +2.0, +3.5 }; +TEST_CONSTEXPR(match_m128(_mm256_mask_cvtpd_ps(src, 0xF, a), 0.0f, -1.0f, +2.0f, +3.5f)); +} +namespace MaskOffInf { +constexpr __m128 src = { 9.0f, 9.0f, 9.0f, 9.0f }; +constexpr __m256d a_inf = { -1.0, +2.0, __builtin_huge_val(), +8.0 }; +constexpr __m128 r = _mm256_mask_cvtpd_ps(src, 0x3, a_inf); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avxintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@avx512vlintrin.h:* {{in call to '_mm256_cvtpd_ps({-1.000000e+00, 2.000000e+00, INF, 8.000000e+00})'}} +// expected-note@-4 {{in call to '_mm256_mask_cvtpd_ps({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 3, {-1.000000e+00, 2.000000e+00, INF, 8.000000e+00})'}} +} +namespace MaskOffNaN { +constexpr __m128 src = { 9.0f, 9.0f, 9.0f, 9.0f }; +constexpr __m256d a_nan = { -1.0, +2.0, +4.0, __builtin_nan("") }; +constexpr __m128 r = _mm256_mask_cvtpd_ps(src, 0x7, a_nan); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avxintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@avx512vlintrin.h:* {{in call to '_mm256_cvtpd_ps({-1.000000e+00, 2.000000e+00, 4.000000e+00, nan})'}} +// expected-note@-4 {{in call to '_mm256_mask_cvtpd_ps({9.000000e+00, 9.000000e+00, 9.000000e+00, 9.000000e+00}, 7, {-1.000000e+00, 2.000000e+00, 4.000000e+00, nan})'}} +} +} + +namespace Test_mm256_maskz_cvtpd_ps { +namespace OK { +constexpr __m256d a = { 0.0, -1.0, +2.0, +3.5 }; +TEST_CONSTEXPR(match_m128(_mm256_maskz_cvtpd_ps(0x5, a), 0.0f, 0.0f, +2.0f, 0.0f)); +} +namespace MaskOffInf { +constexpr __m256d a_inf = { -1.0, +2.0, __builtin_huge_val(), +8.0 }; +constexpr __m128 r = _mm256_maskz_cvtpd_ps(0x3, a_inf); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avxintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@avx512vlintrin.h:* {{in call to '_mm256_cvtpd_ps({-1.000000e+00, 2.000000e+00, INF, 8.000000e+00})'}} +// expected-note@-4 {{in call to '_mm256_maskz_cvtpd_ps(3, {-1.000000e+00, 2.000000e+00, INF, 8.000000e+00})'}} +} +namespace MaskOffNaN { +constexpr __m256d a_nan = { -1.0, +2.0, +4.0, __builtin_nan("") }; +constexpr __m128 r = _mm256_maskz_cvtpd_ps(0x7, a_nan); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@avxintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@avx512vlintrin.h:* {{in call to '_mm256_cvtpd_ps({-1.000000e+00, 2.000000e+00, 4.000000e+00, nan})'}} +// expected-note@-4 {{in call to '_mm256_maskz_cvtpd_ps(7, {-1.000000e+00, 2.000000e+00, 4.000000e+00, nan})'}} +} +} diff --git a/clang/test/SemaCXX/constexpr-x86-sse2-builtins.cpp b/clang/test/SemaCXX/constexpr-x86-sse2-builtins.cpp new file mode 100644 index 0000000..319a3b0 --- /dev/null +++ b/clang/test/SemaCXX/constexpr-x86-sse2-builtins.cpp @@ -0,0 +1,79 @@ +// RUN: %clang_cc1 -std=c++20 -ffreestanding -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown -target-feature +sse2 -verify %s + +#include <immintrin.h> +#include "../CodeGen/X86/builtin_test_helpers.h" + +namespace Test_mm_cvtsd_ss { +namespace OK { +constexpr __m128 a = { 9.0f, 5.0f, 6.0f, 7.0f }; +constexpr __m128d b = { -1.0, 42.0 }; +TEST_CONSTEXPR(match_m128(_mm_cvtsd_ss(a, b), -1.0f, 5.0f, 6.0f, 7.0f)); +} +namespace Inexact { +constexpr __m128 a = { 0.0f, 1.0f, 2.0f, 3.0f }; +constexpr __m128d b = { 1.0000000000000002, 0.0 }; +constexpr __m128 r = _mm_cvtsd_ss(a, b); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@emmintrin.h:* {{compile time floating point arithmetic suppressed in strict evaluation modes}} +// expected-note@-3 {{in call to '_mm_cvtsd_ss({0.000000e+00, 1.000000e+00, 2.000000e+00, 3.000000e+00}, {1.000000e+00, 0.000000e+00})'}} +} +namespace Inf { +constexpr __m128 a = { 0.0f, 1.0f, 2.0f, 3.0f }; +constexpr __m128d b = { __builtin_huge_val(), 0.0 }; +constexpr __m128 r = _mm_cvtsd_ss(a, b); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@emmintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@-3 {{in call to '_mm_cvtsd_ss({0.000000e+00, 1.000000e+00, 2.000000e+00, 3.000000e+00}, {INF, 0.000000e+00})'}} +} +namespace NaN { +constexpr __m128 a = { 0.0f, 1.0f, 2.0f, 3.0f }; +constexpr __m128d b = { __builtin_nan(""), 0.0 }; +constexpr __m128 r = _mm_cvtsd_ss(a, b); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@emmintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@-3 {{in call to '_mm_cvtsd_ss({0.000000e+00, 1.000000e+00, 2.000000e+00, 3.000000e+00}, {nan, 0.000000e+00})'}} +} +namespace Subnormal { +constexpr __m128 a = { 0.0f, 1.0f, 2.0f, 3.0f }; +constexpr __m128d b = { 1e-310, 0.0 }; +constexpr __m128 r = _mm_cvtsd_ss(a, b); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@emmintrin.h:* {{compile time floating point arithmetic suppressed in strict evaluation modes}} +// expected-note@-3 {{in call to '_mm_cvtsd_ss({0.000000e+00, 1.000000e+00, 2.000000e+00, 3.000000e+00}, {1.000000e-310, 0.000000e+00})'}} +} +} + +namespace Test_mm_cvtpd_ps { +namespace OK { +constexpr __m128d a = { -1.0, +2.0 }; +TEST_CONSTEXPR(match_m128(_mm_cvtpd_ps(a), -1.0f, +2.0f, 0.0f, 0.0f)); +} +namespace Inexact { +constexpr __m128d a = { 1.0000000000000002, 0.0 }; +constexpr __m128 r = _mm_cvtpd_ps(a); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@emmintrin.h:* {{compile time floating point arithmetic suppressed in strict evaluation modes}} +// expected-note@-3 {{in call to '_mm_cvtpd_ps({1.000000e+00, 0.000000e+00})'}} +} +namespace Inf { +constexpr __m128d a = { __builtin_huge_val(), 0.0 }; +constexpr __m128 r = _mm_cvtpd_ps(a); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@emmintrin.h:* {{floating point arithmetic produces an infinity}} +// expected-note@-3 {{in call to '_mm_cvtpd_ps({INF, 0.000000e+00})'}} +} +namespace NaN { +constexpr __m128d a = { __builtin_nan(""), 0.0 }; +constexpr __m128 r = _mm_cvtpd_ps(a); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@emmintrin.h:* {{floating point arithmetic produces a NaN}} +// expected-note@-3 {{in call to '_mm_cvtpd_ps({nan, 0.000000e+00})'}} +} +namespace Subnormal { +constexpr __m128d a = { 1e-310, 0.0 }; +constexpr __m128 r = _mm_cvtpd_ps(a); +// expected-error@-1 {{must be initialized by a constant expression}} +// expected-note@emmintrin.h:* {{compile time floating point arithmetic suppressed in strict evaluation modes}} +// expected-note@-3 {{in call to '_mm_cvtpd_ps({1.000000e-310, 0.000000e+00})'}} +} +} diff --git a/clang/test/SemaCXX/cxx2a-consteval.cpp b/clang/test/SemaCXX/cxx2a-consteval.cpp index 1474c48..92bfa40 100644 --- a/clang/test/SemaCXX/cxx2a-consteval.cpp +++ b/clang/test/SemaCXX/cxx2a-consteval.cpp @@ -1319,6 +1319,27 @@ namespace GH139160{ B result = (B){10, get_value(make_struct())}; // expected-error {{initializer element is not a compile-time constant}} // expected-error@-1 {{call to consteval function 'GH139160::get_value' is not a constant expression}} // expected-note@-2 {{non-constexpr function 'make_struct' cannot be used in a constant expression}} -}; +} // namespace GH139160 + +namespace GH118187 { + +template <typename T> int t() { + return []<typename U>() consteval { + return [](U v) { return v; }(123); + }.template operator()<int>(); +} +int v = t<int>(); +} // namespace GH118187 +namespace GH156579 { +template <class> +auto f{[] (auto...) { + if constexpr ([] (auto) { return true; }(0)) + return 0; +}}; + +void g() { + f<int>(); +} +} // namespace GH156579 diff --git a/clang/test/SemaCXX/format-strings-0x.cpp b/clang/test/SemaCXX/format-strings-0x.cpp index 7d37f82..e0ca7a2 100644 --- a/clang/test/SemaCXX/format-strings-0x.cpp +++ b/clang/test/SemaCXX/format-strings-0x.cpp @@ -14,6 +14,7 @@ void f(char **sp, float *fp) { printf("%a", 1.0); scanf("%afoobar", fp); printf(nullptr); + // expected-warning@-1{{null passed to a callee that requires a non-null argument}} printf(*sp); // expected-warning {{not a string literal}} // expected-note@-1{{treat the string as an argument to avoid this}} @@ -32,4 +33,5 @@ void f(char **sp, float *fp) { printf("init list: %d", { 0 }); // expected-error {{cannot pass initializer list to variadic function; expected type from format string was 'int'}} printf("void: %d", f(sp, fp)); // expected-error {{cannot pass expression of type 'void' to variadic function; expected type from format string was 'int'}} printf(0, { 0 }); // expected-error {{cannot pass initializer list to variadic function}} + // expected-warning@-1{{null passed to a callee that requires a non-null argument}} } diff --git a/clang/test/SemaCXX/format-strings.cpp b/clang/test/SemaCXX/format-strings.cpp index 48cf239..5890f56 100644 --- a/clang/test/SemaCXX/format-strings.cpp +++ b/clang/test/SemaCXX/format-strings.cpp @@ -33,7 +33,7 @@ public: int scanf(const char *, ...) __attribute__((format(scanf, 2, 3))); int printf(const char *, ...) __attribute__((format(printf, 2, 3))); - int printf2(const char *, ...); + int printf2(const char *, ...); // #Foo_printf2 static const char *gettext_static(const char *fmt) __attribute__((format_arg(1))); static int printf_static(const char *fmt, ...) __attribute__((format(printf, 1, 2))); @@ -86,8 +86,8 @@ int Foo::printf(const char *fmt, ...) { int Foo::printf2(const char *fmt, ...) { va_list ap; va_start(ap,fmt); - vprintf(fmt, ap); // expected-warning{{format string is not a string literal}} - + vprintf(fmt, ap); // expected-warning{{diagnostic behavior may be improved by adding the 'format(printf, 2, 3)' attribute to the declaration of 'printf2'}} + // expected-note@#Foo_printf2 {{'printf2' declared here}} return 0; } diff --git a/clang/test/SemaCXX/no-warn-consumed-analysis.cpp b/clang/test/SemaCXX/no-warn-consumed-analysis.cpp new file mode 100644 index 0000000..59d5036 --- /dev/null +++ b/clang/test/SemaCXX/no-warn-consumed-analysis.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wconsumed -fcxx-exceptions -std=c++11 %s +// expected-no-diagnostics + +struct foo { + ~foo(); +}; +struct bar : foo {}; +struct baz : bar {}; +baz foobar(baz a) { return a; } diff --git a/clang/test/SemaCXX/no-warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/no-warn-thread-safety-analysis.cpp new file mode 100644 index 0000000..5b19643 --- /dev/null +++ b/clang/test/SemaCXX/no-warn-thread-safety-analysis.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-pointer -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=0 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wthread-safety -Wthread-safety-pointer -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=1 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wthread-safety -Wthread-safety-pointer -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=0 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wthread-safety -Wthread-safety-pointer -Wthread-safety-beta -Wno-thread-safety-negative -fcxx-exceptions -DUSE_CAPABILITY=1 %s +// expected-no-diagnostics + +struct foo { + ~foo(); +}; +struct bar : foo {}; +struct baz : bar {}; +baz foobar(baz a) { return a; } diff --git a/clang/test/SemaCXX/return.cpp b/clang/test/SemaCXX/return.cpp index 796c9ae..92be66c 100644 --- a/clang/test/SemaCXX/return.cpp +++ b/clang/test/SemaCXX/return.cpp @@ -1,4 +1,5 @@ // RUN: %clang_cc1 %s -std=c++11 -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify +// RUN: %clang_cc1 %s -std=c++14 -fcxx-exceptions -fexceptions -fsyntax-only -Wignored-qualifiers -verify int test1() { throw; @@ -132,3 +133,27 @@ void cxx_unresolved_expr() { // expr doesn't assert. return int(undeclared, 4; // expected-error {{use of undeclared identifier 'undeclared'}} } + +#if __cplusplus >= 201402L +namespace GH43054 { +struct S{}; +const auto foo() { return 0; } // expected-warning {{'const' type qualifier on return type has no effect}} +const auto bar() { return S{}; } +template <typename T> +const auto baz() { return T{}; } + +void test() { + baz<int>(); + baz<S>(); + + []() -> const auto { // expected-warning {{'const' type qualifier on return type has no effect}} + return 0; + }(); + + []() -> const auto { + return S{}; + }(); +} +} + +#endif diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp index 0e91639..7cb416d 100644 --- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -1849,6 +1849,43 @@ struct TestScopedLockable { } }; +namespace test_function_param_lock_unlock { +class A { + public: + A() EXCLUSIVE_LOCK_FUNCTION(mu_) { mu_.Lock(); } + ~A() UNLOCK_FUNCTION(mu_) { mu_.Unlock(); } + private: + Mutex mu_; +}; +int do_something(A a) { return 0; } + +// Unlock in dtor without lock in ctor. +// FIXME: We cannot detect that we are releasing a lock that was never held! +class B { + public: + B() {} + B(int) {} + ~B() UNLOCK_FUNCTION(mu_) { mu_.Unlock(); } + private: + Mutex mu_; +}; +int do_something(B b) { return 0; } + +class SCOPED_LOCKABLE MutexWrapper { +public: + MutexWrapper(Mutex *mu) : mu_(mu) {} + ~MutexWrapper() UNLOCK_FUNCTION(mu_) { mu_->Unlock(); } + void Lock() EXCLUSIVE_LOCK_FUNCTION(mu_) { mu_->Lock(); } + + Mutex *mu_; +}; +// FIXME: This is a false-positive as the lock is released by the dtor. +void do_something(MutexWrapper mw) { + mw.Lock(); // expected-note {{mutex acquired here}} +} // expected-warning {{mutex 'mw.mu_' is still held at the end of function}} + +} // namespace test_function_param_lock_unlock + } // end namespace test_scoped_lockable diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fold-conditional.cpp b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fold-conditional.cpp new file mode 100644 index 0000000..b4f30b53 --- /dev/null +++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fold-conditional.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -fsyntax-only -Wno-all -Wunsafe-buffer-usage -verify %s -std=c++20 +// RUN: %clang_cc1 -fsyntax-only -Wno-all -Wunsafe-buffer-usage -verify %s -x c +// expected-no-diagnostics + +typedef struct {} FILE; +int fprintf( FILE* stream, const char* format, ... ); +FILE * stderr; + +#define DEBUG_ASSERT_MESSAGE(name, assertion, label, message, file, line, value) \ + fprintf(stderr, "AssertMacros: %s, %s file: %s, line: %d, value: %lld\n", \ + assertion, (message!=0) ? message : "", file, line, (long long) (value)); + + +#define Require(assertion, exceptionLabel) \ + do \ + { \ + if ( __builtin_expect(!(assertion), 0) ) { \ + DEBUG_ASSERT_MESSAGE( \ + "DEBUG_ASSERT_COMPONENT_NAME_STRING", \ + #assertion, #exceptionLabel, 0, __FILE__, __LINE__, 0); \ + goto exceptionLabel; \ + } \ + } while ( 0 ) + + +void f(int x, int y) { + Require(x == y, L1); + L1: + return; +} + diff --git a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp index 06db972..2520c97 100644 --- a/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp +++ b/clang/test/SemaCXX/wmissing-noreturn-suggestion.cpp @@ -53,3 +53,26 @@ int gnu_throws() { int cxx11_throws() { throw 0; } + +namespace GH167247 { +struct S1 { + virtual ~S1() = default; + virtual void m() { + throw std::runtime_error("This method always throws"); + } +}; + +struct S2 { + virtual ~S2() = default; + + virtual void m() final { // expected-warning {{function 'm' could be declared with attribute 'noreturn'}} + throw std::runtime_error("This method always throws"); + } +}; + +struct S3 final : S1 { + void m() { // expected-warning {{function 'm' could be declared with attribute 'noreturn'}} + throw std::runtime_error("This method always throws"); + } +}; +} diff --git a/clang/test/SemaCXX/zero-length-arrays.cpp b/clang/test/SemaCXX/zero-length-arrays.cpp index 0802ec7..6bfc7a5 100644 --- a/clang/test/SemaCXX/zero-length-arrays.cpp +++ b/clang/test/SemaCXX/zero-length-arrays.cpp @@ -1,6 +1,7 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s class Foo { ~Foo(); @@ -19,7 +20,7 @@ class Bar { Foo foos3[2][0]; public: - Bar(): foo_count(0) { } + Bar(): foo_count(0) { } ~Bar() { } }; @@ -33,3 +34,17 @@ void testBar() { #endif b = b2; } + +namespace GH170040 { +#if __cplusplus >= 202002L +template <int N> struct Foo { + operator int() const requires(N == 2); + template <int I = 0, char (*)[(I)] = nullptr> operator long() const; +}; + +void test () { + Foo<2> foo; + long bar = foo; +} +#endif +} |
