diff options
Diffstat (limited to 'clang/test/Sema')
-rw-r--r-- | clang/test/Sema/aarch64-sme-attrs-without-sve.cpp | 56 | ||||
-rw-r--r-- | clang/test/Sema/attr-nonstring.c | 8 | ||||
-rw-r--r-- | clang/test/Sema/builtins-arm-exclusive-124.c | 26 | ||||
-rw-r--r-- | clang/test/Sema/builtins-arm-exclusive-4.c | 22 | ||||
-rw-r--r-- | clang/test/Sema/builtins-arm-exclusive-none.c | 22 | ||||
-rw-r--r-- | clang/test/Sema/builtins-arm-exclusive.c | 8 | ||||
-rw-r--r-- | clang/test/Sema/builtins-wasm.c | 24 | ||||
-rw-r--r-- | clang/test/Sema/constexpr-void-cast.c | 7 | ||||
-rw-r--r-- | clang/test/Sema/implicit-special-member-deprecated.cpp | 24 | ||||
-rw-r--r-- | clang/test/Sema/unsupported-arm-streaming.cpp | 3 | ||||
-rw-r--r-- | clang/test/Sema/warn-unreachable_crash.cpp | 41 |
11 files changed, 226 insertions, 15 deletions
diff --git a/clang/test/Sema/aarch64-sme-attrs-without-sve.cpp b/clang/test/Sema/aarch64-sme-attrs-without-sve.cpp new file mode 100644 index 0000000..cc6a841 --- /dev/null +++ b/clang/test/Sema/aarch64-sme-attrs-without-sve.cpp @@ -0,0 +1,56 @@ +// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s + +// REQUIRES: aarch64-registered-target + +#include <arm_sme.h> + +void test_streaming(svint32_t *out, svint32_t *in) __arm_streaming { + *out = *in; +} + +void test_non_streaming(svint32_t *out, svint32_t *in) { + *out = *in; // expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}} \ + expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}} +} + +// This previously led to a diagnostic that '&a' could not be used in a non-streaming function, +// even though all functions are streaming. +void test_both_streaming(int32_t *out) __arm_streaming { + svint32_t a; + [&a, &out]() __arm_streaming { + a = svdup_s32(1); + svst1(svptrue_b32(), out, a); + }(); +} + +void test_lambda_streaming(int32_t *out) { + svint32_t a; // expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}} + [&a, &out]() __arm_streaming { + a = 1; + svst1(svptrue_b32(), out, a); + }(); +} + +void test_lambda_non_streaming_capture_do_nothing() __arm_streaming { + svint32_t a; + [&a] { + // Do nothing. + }(); +} + +// Error: Non-streaming function attempts to dereference capture: +void test_lambda_non_streaming_capture_return_vector() __arm_streaming { + svint32_t a; + [&a] { + return a; // expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}} + }(); +} + +// By reference capture, only records and uses the address of `a`: +// FIXME: This should be okay. +void test_lambda_non_streaming_capture_return_address() __arm_streaming { + svint32_t a; + [&a] { + return &a; // expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}} + }(); +} diff --git a/clang/test/Sema/attr-nonstring.c b/clang/test/Sema/attr-nonstring.c index 3838aa3..fe7b6d2 100644 --- a/clang/test/Sema/attr-nonstring.c +++ b/clang/test/Sema/attr-nonstring.c @@ -229,3 +229,11 @@ struct Outer o2[] = { } } }; + +// The attribute also works with a pointer type, not just an array type. +__attribute__((nonstring)) char *ptr1; +__attribute__((nonstring)) const unsigned char *ptr2; +struct GH150951 { + __attribute__((nonstring)) char *ptr1; + __attribute__((nonstring)) const unsigned char *ptr2; +}; diff --git a/clang/test/Sema/builtins-arm-exclusive-124.c b/clang/test/Sema/builtins-arm-exclusive-124.c new file mode 100644 index 0000000..013ae3f --- /dev/null +++ b/clang/test/Sema/builtins-arm-exclusive-124.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple armv7m -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple armv8m.main -fsyntax-only -verify %s +// RUN: %clang_cc1 -triple armv8.1m.main -fsyntax-only -verify %s + +// All these architecture versions provide 1-, 2- or 4-byte exclusive accesses, +// but don't have the LDREXD instruction which takes two operand registers and +// performs an 8-byte exclusive access. So the calls with a pointer to long +// long are rejected. + +int test_ldrex(char *addr) { + int sum = 0; + sum += __builtin_arm_ldrex(addr); + sum += __builtin_arm_ldrex((short *)addr); + sum += __builtin_arm_ldrex((int *)addr); + sum += __builtin_arm_ldrex((long long *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 1,2 or 4 byte type}} + return sum; +} + +int test_strex(char *addr) { + int res = 0; + res |= __builtin_arm_strex(4, addr); + res |= __builtin_arm_strex(42, (short *)addr); + res |= __builtin_arm_strex(42, (int *)addr); + res |= __builtin_arm_strex(42, (long long *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 1,2 or 4 byte type}} + return res; +} diff --git a/clang/test/Sema/builtins-arm-exclusive-4.c b/clang/test/Sema/builtins-arm-exclusive-4.c new file mode 100644 index 0000000..68f01f5 --- /dev/null +++ b/clang/test/Sema/builtins-arm-exclusive-4.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -triple armv6 -fsyntax-only -verify %s + +// Armv6 (apart from Armv6-M) provides 4-byte exclusive accesses, but not any +// other size. So only the calls with a pointer to a 32-bit type are accepted. + +int test_ldrex(char *addr) { + int sum = 0; + sum += __builtin_arm_ldrex(addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 4 byte type}} + sum += __builtin_arm_ldrex((short *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 4 byte type}} + sum += __builtin_arm_ldrex((int *)addr); + sum += __builtin_arm_ldrex((long long *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 4 byte type}} + return sum; +} + +int test_strex(char *addr) { + int res = 0; + res |= __builtin_arm_strex(4, addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 4 byte type}} + res |= __builtin_arm_strex(42, (short *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 4 byte type}} + res |= __builtin_arm_strex(42, (int *)addr); + res |= __builtin_arm_strex(42, (long long *)addr); // expected-error {{address argument to load or store exclusive builtin must be a pointer to 4 byte type}} + return res; +} diff --git a/clang/test/Sema/builtins-arm-exclusive-none.c b/clang/test/Sema/builtins-arm-exclusive-none.c new file mode 100644 index 0000000..76d327f --- /dev/null +++ b/clang/test/Sema/builtins-arm-exclusive-none.c @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -triple armv6m -fsyntax-only -verify %s + +// Armv6-M does not support exclusive loads/stores at all, so all uses of +// __builtin_arm_ldrex and __builtin_arm_strex is forbidden. + +int test_ldrex(char *addr) { + int sum = 0; + sum += __builtin_arm_ldrex(addr); // expected-error {{load and store exclusive builtins are not available on this architecture}} + sum += __builtin_arm_ldrex((short *)addr); // expected-error {{load and store exclusive builtins are not available on this architecture}} + sum += __builtin_arm_ldrex((int *)addr); // expected-error {{load and store exclusive builtins are not available on this architecture}} + sum += __builtin_arm_ldrex((long long *)addr); // expected-error {{load and store exclusive builtins are not available on this architecture}} + return sum; +} + +int test_strex(char *addr) { + int res = 0; + res |= __builtin_arm_strex(4, addr); // expected-error {{load and store exclusive builtins are not available on this architecture}} + res |= __builtin_arm_strex(42, (short *)addr); // expected-error {{load and store exclusive builtins are not available on this architecture}} + res |= __builtin_arm_strex(42, (int *)addr); // expected-error {{load and store exclusive builtins are not available on this architecture}} + res |= __builtin_arm_strex(42, (long long *)addr); // expected-error {{load and store exclusive builtins are not available on this architecture}} + return res; +} diff --git a/clang/test/Sema/builtins-arm-exclusive.c b/clang/test/Sema/builtins-arm-exclusive.c index 68457d2..49aea15 100644 --- a/clang/test/Sema/builtins-arm-exclusive.c +++ b/clang/test/Sema/builtins-arm-exclusive.c @@ -1,5 +1,13 @@ // RUN: %clang_cc1 -triple armv7 -fsyntax-only -verify %s +// General tests of __builtin_arm_ldrex and __builtin_arm_strex error checking. +// +// This test is compiled for Armv7-A, which provides exclusive load/store +// instructions for 1-, 2-, 4- and 8-byte quantities. Other Arm architecture +// versions provide subsets of those, requiring different error reporting. +// Those are tested in builtins-arm-exclusive-124.c, builtins-arm-exclusive-4.c +// and builtins-arm-exclusive-none.c. + struct Simple { char a, b; }; diff --git a/clang/test/Sema/builtins-wasm.c b/clang/test/Sema/builtins-wasm.c index 31e5291..a3486b1 100644 --- a/clang/test/Sema/builtins-wasm.c +++ b/clang/test/Sema/builtins-wasm.c @@ -54,3 +54,27 @@ void test_table_copy(int dst_idx, int src_idx, int nelem) { __builtin_wasm_table_copy(table, table, dst_idx, src_idx, table); // expected-error {{5th argument must be an integer}} __builtin_wasm_table_copy(table, table, dst_idx, src_idx, nelem); } + +typedef void (*F1)(void); +typedef int (*F2)(int); +typedef int (*F3)(__externref_t); +typedef __externref_t (*F4)(int); + +void test_function_pointer_signature() { + // Test argument count validation + (void)__builtin_wasm_test_function_pointer_signature(); // expected-error {{too few arguments to function call, expected 1, have 0}} + (void)__builtin_wasm_test_function_pointer_signature((F1)0, (F2)0); // expected-error {{too many arguments to function call, expected 1, have 2}} + + // // Test argument type validation - should require function pointer + (void)__builtin_wasm_test_function_pointer_signature((void*)0); // expected-error {{used type 'void *' where function pointer is required}} + (void)__builtin_wasm_test_function_pointer_signature((int)0); // expected-error {{used type 'int' where function pointer is required}} + (void)__builtin_wasm_test_function_pointer_signature((F3)0); // expected-error {{not supported for function pointers with a reference type parameter}} + (void)__builtin_wasm_test_function_pointer_signature((F4)0); // expected-error {{not supported for function pointers with a reference type return value}} + + // // Test valid usage + int res = __builtin_wasm_test_function_pointer_signature((F1)0); + res = __builtin_wasm_test_function_pointer_signature((F2)0); + + // Test return type + _Static_assert(EXPR_HAS_TYPE(__builtin_wasm_test_function_pointer_signature((F1)0), int), ""); +} diff --git a/clang/test/Sema/constexpr-void-cast.c b/clang/test/Sema/constexpr-void-cast.c index 2ffc59f..cac671e 100644 --- a/clang/test/Sema/constexpr-void-cast.c +++ b/clang/test/Sema/constexpr-void-cast.c @@ -4,15 +4,16 @@ // RUN: %clang_cc1 -x c -fsyntax-only %s -pedantic -verify=c-pedantic -std=c11 -fexperimental-new-constant-interpreter // // RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify=cxx -// RUN: %clang_cc1 -x c++ -fsyntax-only %s -pedantic -verify=cxx-pedantic +// RUN: %clang_cc1 -x c++ -fsyntax-only %s -pedantic -verify=cxx,cxx-pedantic // RUN: %clang_cc1 -x c++ -fsyntax-only %s -verify=cxx -fexperimental-new-constant-interpreter -// RUN: %clang_cc1 -x c++ -fsyntax-only %s -pedantic -verify=cxx-pedantic -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -x c++ -fsyntax-only %s -pedantic -verify=cxx,cxx-pedantic -fexperimental-new-constant-interpreter // c-no-diagnostics -// cxx-no-diagnostics void f(void); struct S {char c;} s; _Static_assert(&s != (void *)&f, ""); // c-pedantic-warning {{not an integer constant expression}} \ // c-pedantic-note {{this conversion is not allowed in a constant expression}} \ + // cxx-error {{static assertion expression is not an integral constant expression}} \ + // cxx-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}} \ // cxx-pedantic-warning {{'_Static_assert' is a C11 extension}} diff --git a/clang/test/Sema/implicit-special-member-deprecated.cpp b/clang/test/Sema/implicit-special-member-deprecated.cpp new file mode 100644 index 0000000..8e23404 --- /dev/null +++ b/clang/test/Sema/implicit-special-member-deprecated.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -std=c++20 -Wdeprecated-declarations -verify %s + +struct A { + [[deprecated("use something else")]] int x = 42; // expected-note {{marked deprecated here}} +}; + +A makeDefaultA() { return {}; } // ctor is implicit → no warn +A copyA(const A &a) { return a; } // copy-ctor implicit → no warn + +void assignA() { + A a, b; + a = b; // copy-assign implicit → no warn +} + +void useA() { + A a; + (void)a.x; // expected-warning {{is deprecated}} +} + +// Explicitly-defaulted ctor – now silent +struct B { + [[deprecated]] int y; + B() = default; // no warning under new policy +}; diff --git a/clang/test/Sema/unsupported-arm-streaming.cpp b/clang/test/Sema/unsupported-arm-streaming.cpp new file mode 100644 index 0000000..8693dd6 --- /dev/null +++ b/clang/test/Sema/unsupported-arm-streaming.cpp @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -x c -triple x86_64-pc-linux-gnu -fsyntax-only -verify %s + +void arm_streaming(void) __arm_streaming {} // expected-error {{'__arm_streaming' is not supported on this target}} diff --git a/clang/test/Sema/warn-unreachable_crash.cpp b/clang/test/Sema/warn-unreachable_crash.cpp index 628abcc..1955c2c 100644 --- a/clang/test/Sema/warn-unreachable_crash.cpp +++ b/clang/test/Sema/warn-unreachable_crash.cpp @@ -1,16 +1,33 @@ -// RUN: %clang_cc1 -verify -Wunreachable-code %s +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -verify -Wunreachable-code %s +// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -target-feature +fullfp16 -verify -Wunreachable-code %s +// REQUIRES: aarch64-registered-target -// Previously this test will crash -static void test(__fp16& x) { - if (x != 0 || x != 1.0) { // expected-note{{}} no-crash - x = 0.9; - } else - x = 0.8; // expected-warning{{code will never be executed}} +// ======= __fp16 version ======= +static void test_fp16(__fp16 &x) { + if (x != 0 || x != 1.0) { // expected-note {{}} no-crash + x = 0.9; + } else + x = 0.8; // expected-warning{{code will never be executed}} } -static void test2(__fp16& x) { - if (x != 1 && x == 1.0) { // expected-note{{}} no-crash - x = 0.9; // expected-warning{{code will never be executed}} - } else - x = 0.8; +static void test_fp16_b(__fp16 &x) { + if (x != 1 && x == 1.0) { // expected-note {{}} no-crash + x = 0.9; // expected-warning{{code will never be executed}} + } else + x = 0.8; +} + +// ======= _Float16 version ======= +static void test_f16(_Float16 &x) { + if (x != 0 || x != 1.0) { // expected-note {{}} no-crash + x = 0.9; + } else + x = 0.8; // expected-warning{{code will never be executed}} +} + +static void test_f16_b(_Float16 &x) { + if (x != 1 && x == 1.0) { // expected-note {{}} no-crash + x = 0.9; // expected-warning{{code will never be executed}} + } else + x = 0.8; } |