diff options
| author | Mingming Liu <mingmingl@google.com> | 2025-09-10 15:25:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-10 15:25:31 -0700 |
| commit | 1417dafa1db9cb1b2b09438aa9f53ea5ab6e36e2 (patch) | |
| tree | 57f4b1f313c8cf74eed8819870f39c36ea263c68 /clang/test/AST/ByteCode | |
| parent | 898b813bc8a6d0276bf0f4769f5f2f64b34e632d (diff) | |
| parent | b8cefcb601ddaa18482555c4ff363c01a270c2fe (diff) | |
Merge branch 'main' into users/mingmingl-llvm/samplefdo-profile-formatusers/mingmingl-llvm/samplefdo-profile-format
Diffstat (limited to 'clang/test/AST/ByteCode')
| -rw-r--r-- | clang/test/AST/ByteCode/builtin-functions.cpp | 4 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/c.c | 21 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/cxx03.cpp | 11 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/cxx11.cpp | 2 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/cxx23.cpp | 5 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/cxx2a.cpp | 14 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/invalid.cpp | 8 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/new-delete.cpp | 22 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/openmp.cpp | 20 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/vectors.cpp | 29 |
10 files changed, 132 insertions, 4 deletions
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index 3277ef65a880..f47bc49d9a1a 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -454,6 +454,7 @@ namespace SourceLocation { } #define BITSIZE(x) (sizeof(x) * 8) +constexpr bool __attribute__((ext_vector_type(4))) v4b{}; namespace popcount { static_assert(__builtin_popcount(~0u) == __CHAR_BIT__ * sizeof(unsigned int), ""); static_assert(__builtin_popcount(0) == 0, ""); @@ -471,6 +472,7 @@ namespace popcount { static_assert(__builtin_popcountg(0ul) == 0, ""); static_assert(__builtin_popcountg(~0ull) == __CHAR_BIT__ * sizeof(unsigned long long), ""); static_assert(__builtin_popcountg(0ull) == 0, ""); + static_assert(__builtin_popcountg(v4b) == 0, ""); #ifdef __SIZEOF_INT128__ static_assert(__builtin_popcountg(~(unsigned __int128)0) == __CHAR_BIT__ * sizeof(unsigned __int128), ""); static_assert(__builtin_popcountg((unsigned __int128)0) == 0, ""); @@ -743,6 +745,7 @@ namespace clz { char clz62[__builtin_clzg((unsigned _BitInt(128))0xf) == BITSIZE(_BitInt(128)) - 4 ? 1 : -1]; char clz63[__builtin_clzg((unsigned _BitInt(128))0xf, 42) == BITSIZE(_BitInt(128)) - 4 ? 1 : -1]; #endif + char clz64[__builtin_clzg(v4b, 0) == 0 ? 1 : -1]; } namespace ctz { @@ -813,6 +816,7 @@ namespace ctz { char ctz62[__builtin_ctzg((unsigned _BitInt(128))1 << (BITSIZE(_BitInt(128)) - 1)) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1]; char ctz63[__builtin_ctzg((unsigned _BitInt(128))1 << (BITSIZE(_BitInt(128)) - 1), 42) == BITSIZE(_BitInt(128)) - 1 ? 1 : -1]; #endif + char clz64[__builtin_ctzg(v4b, 0) == 0 ? 1 : -1]; } namespace bswap { diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c index 73469d7fd6cc..b6d2a69271af 100644 --- a/clang/test/AST/ByteCode/c.c +++ b/clang/test/AST/ByteCode/c.c @@ -173,6 +173,10 @@ _Static_assert(CTB3, ""); // pedantic-ref-warning {{GNU extension}} \ // pedantic-expected-warning {{GNU extension}} +void nonComplexToComplexCast(void) { + _Complex double z = *(_Complex double *)&(struct { double r, i; }){0.0, 1.0}; +} + int t1 = sizeof(int); void test4(void) { t1 = sizeof(int); @@ -347,3 +351,20 @@ const int compared = strcmp(_str, (const char *)_str2); // all-error {{initializ const int compared2 = strcmp(strcmp, _str); // all-warning {{incompatible pointer types}} \ // all-error {{initializer element is not a compile-time constant}} + +int foo(x) // all-warning {{a function definition without a prototype is deprecated in all versions of C}} +int x; +{ + return x; +} + +void bar() { // pedantic-warning {{a function declaration without a prototype}} + int x; + x = foo(); // all-warning {{too few arguments}} +} + +int *_b = &a; +void discardedCmp(void) +{ + (*_b) = ((&a == &a) , a); // all-warning {{left operand of comma operator has no effect}} +} diff --git a/clang/test/AST/ByteCode/cxx03.cpp b/clang/test/AST/ByteCode/cxx03.cpp index 70ae4134842b..10e5232b9f87 100644 --- a/clang/test/AST/ByteCode/cxx03.cpp +++ b/clang/test/AST/ByteCode/cxx03.cpp @@ -29,3 +29,14 @@ void LambdaAccessingADummy() { int d; int a9[1] = {[d = 0] = 1}; // both-error {{is not an integral constant expression}} } + +const int p = 10; +struct B { + int a; + void *p; +}; +struct B2 : B { + void *q; +}; +_Static_assert(&(B2().a) == &p, ""); // both-error {{taking the address of a temporary object of type 'int'}} \ + // both-error {{not an integral constant expression}} diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp index 08caca03b805..72bc7622eb6d 100644 --- a/clang/test/AST/ByteCode/cxx11.cpp +++ b/clang/test/AST/ByteCode/cxx11.cpp @@ -287,6 +287,8 @@ namespace OverlappingStrings { constexpr bool may_overlap_4 = &"xfoo"[1] == &"xfoo"[1]; // both-error {{}} both-note {{addresses of potentially overlapping literals}} + /// Used to crash. + const bool x = &"ab"[0] == &"ba"[3]; } diff --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp index 2182d7c4e432..72c751d627a4 100644 --- a/clang/test/AST/ByteCode/cxx23.cpp +++ b/clang/test/AST/ByteCode/cxx23.cpp @@ -83,6 +83,11 @@ constexpr int k(int n) { } constexpr int k0 = k(0); +namespace ThreadLocalStore { + thread_local int &&a = 0; + void store() { a = 42; } +} + #if __cplusplus >= 202302L constexpr int &b = b; // all-error {{must be initialized by a constant expression}} \ // all-note {{initializer of 'b' is not a constant expression}} \ diff --git a/clang/test/AST/ByteCode/cxx2a.cpp b/clang/test/AST/ByteCode/cxx2a.cpp index 744c99eaa1e6..533173d84792 100644 --- a/clang/test/AST/ByteCode/cxx2a.cpp +++ b/clang/test/AST/ByteCode/cxx2a.cpp @@ -239,3 +239,17 @@ namespace GH150705 { constexpr const A& a = b; constexpr auto x = (a.*q)(); // both-error {{constant expression}} } + +namespace DependentRequiresExpr { + template <class T, + bool = []() -> bool { // both-error {{not a constant expression}} + if (requires { T::type; }) + return true; + return false; + }()> + struct p { + using type = void; + }; + + template <class T> using P = p<T>::type; // both-note {{while checking a default template argument}} +} diff --git a/clang/test/AST/ByteCode/invalid.cpp b/clang/test/AST/ByteCode/invalid.cpp index 2a6c2d13e846..affb40eada87 100644 --- a/clang/test/AST/ByteCode/invalid.cpp +++ b/clang/test/AST/ByteCode/invalid.cpp @@ -58,3 +58,11 @@ namespace Casts { /// Just make sure this doesn't crash. float PR9558 = reinterpret_cast<const float&>("asd"); } + + +/// This used to crash in collectBlock(). +struct S { +}; +S s; +S *sp[2] = {&s, &s}; +S *&spp = sp[1]; diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 3f0e928c7664..af747d7a15b1 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -1069,6 +1069,28 @@ namespace BaseCompare { static_assert(foo()); } + +namespace NegativeArraySize { + constexpr void f() { // both-error {{constexpr function never produces a constant expression}} + int x = -1; + int *p = new int[x]; //both-note {{cannot allocate array; evaluated array bound -1 is negative}} + } +} // namespace NegativeArraySize + +namespace NewNegSizeNothrow { + constexpr int get_neg_size() { + return -1; + } + + constexpr bool test_nothrow_neg_size() { + int x = get_neg_size(); + int* p = new (std::nothrow) int[x]; + return p == nullptr; + } + + static_assert(test_nothrow_neg_size(), "expected nullptr"); +} // namespace NewNegSizeNothrow + #else /// Make sure we reject this prior to C++20 constexpr int a() { // both-error {{never produces a constant expression}} diff --git a/clang/test/AST/ByteCode/openmp.cpp b/clang/test/AST/ByteCode/openmp.cpp index e05fbe086625..15f10a2cd262 100644 --- a/clang/test/AST/ByteCode/openmp.cpp +++ b/clang/test/AST/ByteCode/openmp.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both -fopenmp %s -// RUN: %clang_cc1 -verify=ref,both -fopenmp %s +// RUN: %clang_cc1 -verify=expected,both -fopenmp -fopenmp-version=60 %s -fexperimental-new-constant-interpreter +// RUN: %clang_cc1 -verify=ref,both -fopenmp -fopenmp-version=60 %s int test1() { int i; @@ -11,3 +11,19 @@ int test1() { for (int i = 0; i < 10; ++i); } +extern int omp_get_thread_num(void); + +#define N 64 + +int test2() { + int x = 0; + int device_result[N] = {0}; + + #pragma omp target parallel loop num_threads(strict: N) severity(warning) message("msg") + for (int i = 0; i < N; i++) { + x = omp_get_thread_num(); + device_result[i] = i + x; + } +} + + diff --git a/clang/test/AST/ByteCode/vectors.cpp b/clang/test/AST/ByteCode/vectors.cpp index 091caf8c9a27..91fec8f86f61 100644 --- a/clang/test/AST/ByteCode/vectors.cpp +++ b/clang/test/AST/ByteCode/vectors.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both -flax-vector-conversions=none %s -// RUN: %clang_cc1 -verify=ref,both -flax-vector-conversions=none %s +// RUN: %clang_cc1 -Wno-c++20-extensions -fexperimental-new-constant-interpreter -verify=expected,both -flax-vector-conversions=none %s +// RUN: %clang_cc1 -Wno-c++20-extensions -verify=ref,both -flax-vector-conversions=none %s typedef int __attribute__((vector_size(16))) VI4; constexpr VI4 A = {1,2,3,4}; @@ -143,3 +143,28 @@ namespace { constexpr __m128d v_mm_cvtps_pd = _mm_cvtps_pd(kf1); static_assert(v_mm_cvtps_pd[0] == -1.0 && v_mm_cvtps_pd[1] == +2.0); } + +namespace Assign { + constexpr int a2() { + VI a = {0, 0, 0, 0}; + VI b; + + b = {1,1,1,1}; + return b[0] + b[1] + b[2] + b[3]; + } + + static_assert(a2() == 4); + + typedef short v2int16_t __attribute__((ext_vector_type(2))); + typedef unsigned short v2int_t __attribute__((ext_vector_type(2))); + + + constexpr bool invalid() { + v2int16_t a = {0, 0}; + v2int_t b; + b = a; // both-error {{incompatible type}} + + return true; + } + static_assert(invalid()); // both-error {{not an integral constant expression}} +} |
