diff options
| author | Justin Lebar <jlebar@google.com> | 2016-10-03 16:48:23 +0000 |
|---|---|---|
| committer | Justin Lebar <jlebar@google.com> | 2016-10-03 16:48:23 +0000 |
| commit | e060feb7b1a98bcd083cf53ea3c05bc9eda432bb (patch) | |
| tree | 763f4e6edf374e0a6a50c19abd244bf1179ca13a /clang/test/SemaCUDA | |
| parent | d27a21874b3d83bf0695eea90b6ba5aa3f600c88 (diff) | |
| download | bcm5719-llvm-e060feb7b1a98bcd083cf53ea3c05bc9eda432bb.tar.gz bcm5719-llvm-e060feb7b1a98bcd083cf53ea3c05bc9eda432bb.zip | |
[CUDA] Disallow overloading destructors.
Summary:
We'd attempted to allow this, but turns out we were doing a very bad
job. :)
Making this work properly would be a giant change in clang. For
example, we'd need to make CXXRecordDecl::getDestructor()
context-sensitive, because the destructor you end up with depends on
where you're calling it from.
For now (and hopefully for ever), just disallow overloading of
destructors in CUDA.
Reviewers: rsmith
Subscribers: cfe-commits, tra
Differential Revision: https://reviews.llvm.org/D24571
llvm-svn: 283120
Diffstat (limited to 'clang/test/SemaCUDA')
| -rw-r--r-- | clang/test/SemaCUDA/call-overloaded-destructor.cu | 17 | ||||
| -rw-r--r-- | clang/test/SemaCUDA/function-overload.cu | 33 | ||||
| -rw-r--r-- | clang/test/SemaCUDA/no-destructor-overload.cu | 33 |
3 files changed, 33 insertions, 50 deletions
diff --git a/clang/test/SemaCUDA/call-overloaded-destructor.cu b/clang/test/SemaCUDA/call-overloaded-destructor.cu deleted file mode 100644 index 24b0e7d330e..00000000000 --- a/clang/test/SemaCUDA/call-overloaded-destructor.cu +++ /dev/null @@ -1,17 +0,0 @@ -// expected-no-diagnostics - -// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify %s -// RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fsyntax-only -fcuda-is-device -verify %s - -#include "Inputs/cuda.h" - -struct S { - __host__ ~S() {} - __device__ ~S() {} -}; - -__host__ __device__ void test() { - S s; - // This should not crash clang. - s.~S(); -} diff --git a/clang/test/SemaCUDA/function-overload.cu b/clang/test/SemaCUDA/function-overload.cu index ff1db14b494..6071dbb2748 100644 --- a/clang/test/SemaCUDA/function-overload.cu +++ b/clang/test/SemaCUDA/function-overload.cu @@ -210,44 +210,11 @@ struct d_h { __host__ ~d_h() {} // expected-error {{destructor cannot be redeclared}} }; -// H/D overloading is OK -struct d_dh { - __device__ ~d_dh() {} - __host__ ~d_dh() {} -}; - // HD is OK struct d_hd { __host__ __device__ ~d_hd() {} }; -// Mixing H/D and HD is not allowed. -struct d_dhhd { - __device__ ~d_dhhd() {} - __host__ ~d_dhhd() {} // expected-note {{previous declaration is here}} - __host__ __device__ ~d_dhhd() {} // expected-error {{destructor cannot be redeclared}} -}; - -struct d_hhd { - __host__ ~d_hhd() {} // expected-note {{previous declaration is here}} - __host__ __device__ ~d_hhd() {} // expected-error {{destructor cannot be redeclared}} -}; - -struct d_hdh { - __host__ __device__ ~d_hdh() {} // expected-note {{previous declaration is here}} - __host__ ~d_hdh() {} // expected-error {{destructor cannot be redeclared}} -}; - -struct d_dhd { - __device__ ~d_dhd() {} // expected-note {{previous declaration is here}} - __host__ __device__ ~d_dhd() {} // expected-error {{destructor cannot be redeclared}} -}; - -struct d_hdd { - __host__ __device__ ~d_hdd() {} // expected-note {{previous declaration is here}} - __device__ ~d_hdd() {} // expected-error {{destructor cannot be redeclared}} -}; - // Test overloading of member functions struct m_h { void operator delete(void *ptr); // expected-note {{previous declaration is here}} diff --git a/clang/test/SemaCUDA/no-destructor-overload.cu b/clang/test/SemaCUDA/no-destructor-overload.cu new file mode 100644 index 00000000000..aa6971ee8ca --- /dev/null +++ b/clang/test/SemaCUDA/no-destructor-overload.cu @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fcuda-is-device -fsyntax-only -verify %s + +#include "Inputs/cuda.h" + +// We don't allow destructors to be overloaded. Making this work would be a +// giant change to clang, and the use cases seem quite limited. + +struct A { + ~A() {} // expected-note {{previous declaration is here}} + __device__ ~A() {} // expected-error {{destructor cannot be redeclared}} +}; + +struct B { + __host__ ~B() {} // expected-note {{previous declaration is here}} + __host__ __device__ ~B() {} // expected-error {{destructor cannot be redeclared}} +}; + +struct C { + __host__ __device__ ~C() {} // expected-note {{previous declaration is here}} + __host__ ~C() {} // expected-error {{destructor cannot be redeclared}} +}; + +struct D { + __device__ ~D() {} // expected-note {{previous declaration is here}} + __host__ __device__ ~D() {} // expected-error {{destructor cannot be redeclared}} +}; + +struct E { + __host__ __device__ ~E() {} // expected-note {{previous declaration is here}} + __device__ ~E() {} // expected-error {{destructor cannot be redeclared}} +}; + |

