diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-09-04 10:57:06 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-09-04 10:57:06 +0000 |
commit | e59f3f34afdd71a752b54cf5298f3a1ddba1f5a8 (patch) | |
tree | 5c62b6a883ddbe02b06f3cf8921006b2efd58f18 /test | |
parent | a6b18af41d41c8380b4160ea7c3f46b8f5f87452 (diff) | |
download | clang-e59f3f34afdd71a752b54cf5298f3a1ddba1f5a8.tar.gz |
Revert "[Clang Interpreter] Initial patch for the constexpr interpreter"
Breaks BUILD_SHARED_LIBS build, introduces cycles in library dependency
graphs. (clangInterp depends on clangAST which depends on clangInterp)
This reverts r370839, which is an yet another recommit of D64146.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370874 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/AST/Interp/cond.cpp | 11 | ||||
-rw-r--r-- | test/SemaCXX/constant-expression-cxx2a.cpp | 119 | ||||
-rw-r--r-- | test/SemaCXX/constexpr-many-arguments.cpp | 4 | ||||
-rw-r--r-- | test/SemaCXX/shift.cpp | 5 |
4 files changed, 121 insertions, 18 deletions
diff --git a/test/AST/Interp/cond.cpp b/test/AST/Interp/cond.cpp deleted file mode 100644 index 8a5a318c21..0000000000 --- a/test/AST/Interp/cond.cpp +++ /dev/null @@ -1,11 +0,0 @@ -// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fforce-experimental-new-constant-interpreter %s -verify -// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify -// expected-no-diagnostics - -constexpr int cond_then_else(int a, int b) { - if (a < b) { - return b - a; - } else { - return a - b; - } -} diff --git a/test/SemaCXX/constant-expression-cxx2a.cpp b/test/SemaCXX/constant-expression-cxx2a.cpp index cc6b196048..dba877ff21 100644 --- a/test/SemaCXX/constant-expression-cxx2a.cpp +++ b/test/SemaCXX/constant-expression-cxx2a.cpp @@ -414,6 +414,125 @@ namespace TypeId { static_assert(side_effects()); } +namespace Union { + struct Base { + int y; // expected-note {{here}} + }; + struct A : Base { + int x; + int arr[3]; + union { int p, q; }; + }; + union B { + A a; + int b; + }; + constexpr int read_wrong_member() { // expected-error {{never produces a constant}} + B b = {.b = 1}; + return b.a.x; // expected-note {{read of member 'a' of union with active member 'b'}} + } + constexpr int change_member() { + B b = {.b = 1}; + b.a.x = 1; + return b.a.x; + } + static_assert(change_member() == 1); + constexpr int change_member_then_read_wrong_member() { // expected-error {{never produces a constant}} + B b = {.b = 1}; + b.a.x = 1; + return b.b; // expected-note {{read of member 'b' of union with active member 'a'}} + } + constexpr int read_wrong_member_indirect() { // expected-error {{never produces a constant}} + B b = {.b = 1}; + int *p = &b.a.y; + return *p; // expected-note {{read of member 'a' of union with active member 'b'}} + } + constexpr int read_uninitialized() { + B b = {.b = 1}; + int *p = &b.a.y; + b.a.x = 1; + return *p; // expected-note {{read of uninitialized object}} + } + static_assert(read_uninitialized() == 0); // expected-error {{constant}} expected-note {{in call}} + constexpr void write_wrong_member_indirect() { // expected-error {{never produces a constant}} + B b = {.b = 1}; + int *p = &b.a.y; + *p = 1; // expected-note {{assignment to member 'a' of union with active member 'b'}} + } + constexpr int write_uninitialized() { + B b = {.b = 1}; + int *p = &b.a.y; + b.a.x = 1; + *p = 1; + return *p; + } + static_assert(write_uninitialized() == 1); + constexpr int change_member_indirectly() { + B b = {.b = 1}; + b.a.arr[1] = 1; + int &r = b.a.y; + r = 123; + + b.b = 2; + b.a.y = 3; + b.a.arr[2] = 4; + return b.a.arr[2]; + } + static_assert(change_member_indirectly() == 4); + constexpr B return_uninit() { + B b = {.b = 1}; + b.a.x = 2; + return b; + } + constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}} + static_assert(return_uninit().a.x == 2); + constexpr A return_uninit_struct() { + B b = {.b = 1}; + b.a.x = 2; + return b.a; + } + // FIXME: It's unclear that this should be valid. Copying a B involves + // copying the object representation of the union, but copying an A invokes a + // copy constructor that copies the object elementwise, and reading from + // b.a.y is undefined. + static_assert(return_uninit_struct().x == 2); + constexpr B return_init_all() { + B b = {.b = 1}; + b.a.x = 2; + b.a.y = 3; + b.a.arr[0] = 4; + b.a.arr[1] = 5; + b.a.arr[2] = 6; + return b; + } + static_assert(return_init_all().a.x == 2); + static_assert(return_init_all().a.y == 3); + static_assert(return_init_all().a.arr[0] == 4); + static_assert(return_init_all().a.arr[1] == 5); + static_assert(return_init_all().a.arr[2] == 6); + static_assert(return_init_all().a.p == 7); // expected-error {{}} expected-note {{read of member 'p' of union with no active member}} + static_assert(return_init_all().a.q == 8); // expected-error {{}} expected-note {{read of member 'q' of union with no active member}} + constexpr B init_all = return_init_all(); + + constexpr bool test_no_member_change = []{ + union U { char dummy = {}; }; + U u1; + U u2; + u1 = u2; + return true; + }(); + + struct S1 { + int n; + }; + struct S2 : S1 {}; + struct S3 : S2 {}; + void f() { + S3 s; + s.n = 0; + } +} + namespace TwosComplementShifts { using uint32 = __UINT32_TYPE__; using int32 = __INT32_TYPE__; diff --git a/test/SemaCXX/constexpr-many-arguments.cpp b/test/SemaCXX/constexpr-many-arguments.cpp index e5bc1ec66c..3b5e974b33 100644 --- a/test/SemaCXX/constexpr-many-arguments.cpp +++ b/test/SemaCXX/constexpr-many-arguments.cpp @@ -12,7 +12,7 @@ struct type2 typedef type1 T; constexpr type2(T a00, T a01, T a02, T a03, T a04, T a05, T a06, T a07, T a08, T a09, T a10, T a11, T a12, T a13, T a14, T a15, T a16, T a17, T a18, T a19, - T a20, T a21, T a22) + T a20, T a21, T a22) : my_data{a00, a01, a02, a03, a04, a05, a06, a07, a08, a09, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22} @@ -32,7 +32,7 @@ constexpr type3 g {0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, {0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, {0},{0},{0} - }, + }, { {0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, {0},{0},{0},{0},{0},{0},{0},{0},{0},{0}, diff --git a/test/SemaCXX/shift.cpp b/test/SemaCXX/shift.cpp index 6c5f1c1913..f99b53e358 100644 --- a/test/SemaCXX/shift.cpp +++ b/test/SemaCXX/shift.cpp @@ -82,8 +82,3 @@ void vect_shift_2(vec16 *x, vec16 y) { *x = *x << y; } void vect_shift_3(vec16 *x, vec8 y) { *x = *x << y; // expected-error {{vector operands do not have the same number of elements}} } -static_assert(-1 >> 1 == -1); -static_assert(-1 >> 31 == -1); -static_assert(-2 >> 1 == -1); -static_assert(-3 >> 1 == -2); -static_assert(-4 >> 1 == -2); |