Skip to content

Commit 6b3470b

Browse files
committed
Revert "[CUDA][HIP] make trivial ctor/dtor host device (#72394)"
This reverts commit 27e6e4a. This patch is reverted due to regression. A testcase is: `template <class T> struct ptr { ~ptr() { static int x = 1;} }; template <class T> struct Abc : ptr<T> { public: Abc(); ~Abc() {} }; template class Abc<int>; `
1 parent 0e5da2e commit 6b3470b

10 files changed

+8
-71
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13466,10 +13466,6 @@ class Sema final {
1346613466
void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD,
1346713467
const LookupResult &Previous);
1346813468

13469-
/// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to a
13470-
/// trivial cotr/dtor that does not have host and device attributes.
13471-
void maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FunctionDecl *FD);
13472-
1347313469
/// May add implicit CUDAConstantAttr attribute to VD, depending on VD
1347413470
/// and current compilation settings.
1347513471
void MaybeAddCUDAConstantAttr(VarDecl *VD);

clang/lib/Sema/SemaCUDA.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -772,22 +772,6 @@ void Sema::maybeAddCUDAHostDeviceAttrs(FunctionDecl *NewD,
772772
NewD->addAttr(CUDADeviceAttr::CreateImplicit(Context));
773773
}
774774

775-
// If a trivial ctor/dtor has no host/device
776-
// attributes, make it implicitly host device function.
777-
void Sema::maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FunctionDecl *FD) {
778-
bool IsTrivialCtor = false;
779-
if (auto *CD = dyn_cast<CXXConstructorDecl>(FD))
780-
IsTrivialCtor = isEmptyCudaConstructor(SourceLocation(), CD);
781-
bool IsTrivialDtor = false;
782-
if (auto *DD = dyn_cast<CXXDestructorDecl>(FD))
783-
IsTrivialDtor = isEmptyCudaDestructor(SourceLocation(), DD);
784-
if ((IsTrivialCtor || IsTrivialDtor) && !FD->hasAttr<CUDAHostAttr>() &&
785-
!FD->hasAttr<CUDADeviceAttr>()) {
786-
FD->addAttr(CUDAHostAttr::CreateImplicit(Context));
787-
FD->addAttr(CUDADeviceAttr::CreateImplicit(Context));
788-
}
789-
}
790-
791775
// TODO: `__constant__` memory may be a limited resource for certain targets.
792776
// A safeguard may be needed at the end of compilation pipeline if
793777
// `__constant__` memory usage goes beyond limit.

clang/lib/Sema/SemaDecl.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16255,9 +16255,6 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1625516255
if (FD && !FD->isDeleted())
1625616256
checkTypeSupport(FD->getType(), FD->getLocation(), FD);
1625716257

16258-
if (LangOpts.CUDA)
16259-
maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FD);
16260-
1626116258
return dcl;
1626216259
}
1626316260

clang/test/SemaCUDA/call-host-fn-from-device.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" void host_fn() {}
1212
struct Dummy {};
1313

1414
struct S {
15-
S() { static int nontrivial_ctor = 1; }
15+
S() {}
1616
// expected-note@-1 2 {{'S' declared here}}
1717
~S() { host_fn(); }
1818
// expected-note@-1 {{'~S' declared here}}

clang/test/SemaCUDA/default-ctor.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ __device__ void fd() {
2525
InD ind;
2626
InH inh; // expected-error{{no matching constructor for initialization of 'InH'}}
2727
InHD inhd;
28-
Out out;
28+
Out out; // expected-error{{no matching constructor for initialization of 'Out'}}
2929
OutD outd;
3030
OutH outh; // expected-error{{no matching constructor for initialization of 'OutH'}}
3131
OutHD outhd;

clang/test/SemaCUDA/implicit-member-target-collision-cxx11.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Test 1: collision between two bases
77

88
struct A1_with_host_ctor {
9-
A1_with_host_ctor() { static int nontrivial_ctor = 1; }
9+
A1_with_host_ctor() {}
1010
};
1111

1212
struct B1_with_device_ctor {

clang/test/SemaCUDA/implicit-member-target-collision.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Test 1: collision between two bases
77

88
struct A1_with_host_ctor {
9-
A1_with_host_ctor() { static int nontrivial_ctor = 1; }
9+
A1_with_host_ctor() {}
1010
};
1111

1212
struct B1_with_device_ctor {

clang/test/SemaCUDA/implicit-member-target-inherited.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Test 1: infer inherited default ctor to be host.
77

88
struct A1_with_host_ctor {
9-
A1_with_host_ctor() { static int nontrivial_ctor = 1; }
9+
A1_with_host_ctor() {}
1010
};
1111
// expected-note@-3 {{candidate constructor (the implicit copy constructor) not viable}}
1212
// expected-note@-4 {{candidate constructor (the implicit move constructor) not viable}}
@@ -83,7 +83,7 @@ void hostfoo3() {
8383
// Test 4: infer inherited default ctor from a field, not a base
8484

8585
struct A4_with_host_ctor {
86-
A4_with_host_ctor() { static int nontrivial_ctor = 1; }
86+
A4_with_host_ctor() {}
8787
};
8888

8989
struct B4_with_inherited_host_ctor : A4_with_host_ctor{

clang/test/SemaCUDA/implicit-member-target.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Test 1: infer default ctor to be host.
77

88
struct A1_with_host_ctor {
9-
A1_with_host_ctor() { static int nontrivial_ctor = 1; }
9+
A1_with_host_ctor() {}
1010
};
1111

1212
// The implicit default constructor is inferred to be host because it only needs
@@ -75,7 +75,7 @@ void hostfoo3() {
7575
// Test 4: infer default ctor from a field, not a base
7676

7777
struct A4_with_host_ctor {
78-
A4_with_host_ctor() { static int nontrivial_ctor = 1; }
78+
A4_with_host_ctor() {}
7979
};
8080

8181
struct B4_with_implicit_default_ctor {

clang/test/SemaCUDA/trivial-ctor-dtor.cu

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)