Skip to content

Commit 14cb3f7

Browse files
committed
Revert "[CUDA][HIP] make trivial ctor/dtor host device"
This reverts commit 20e8466. Change-Id: Iacae3b6a2ed9a5a66c1956d494054a034e606a6c
1 parent 22ca6fd commit 14cb3f7

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
@@ -13266,10 +13266,6 @@ class Sema final {
1326613266
void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD,
1326713267
const LookupResult &Previous);
1326813268

13269-
/// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to a
13270-
/// trivial cotr/dtor that does not have host and device attributes.
13271-
void maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FunctionDecl *FD);
13272-
1327313269
/// May add implicit CUDAConstantAttr attribute to VD, depending on VD
1327413270
/// and current compilation settings.
1327513271
void MaybeAddCUDAConstantAttr(VarDecl *VD);

clang/lib/Sema/SemaCUDA.cpp

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

733-
// If a trivial ctor/dtor has no host/device
734-
// attributes, make it implicitly host device function.
735-
void Sema::maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FunctionDecl *FD) {
736-
bool IsTrivialCtor = false;
737-
if (auto *CD = dyn_cast<CXXConstructorDecl>(FD))
738-
IsTrivialCtor = isEmptyCudaConstructor(SourceLocation(), CD);
739-
bool IsTrivialDtor = false;
740-
if (auto *DD = dyn_cast<CXXDestructorDecl>(FD))
741-
IsTrivialDtor = isEmptyCudaDestructor(SourceLocation(), DD);
742-
if ((IsTrivialCtor || IsTrivialDtor) && !FD->hasAttr<CUDAHostAttr>() &&
743-
!FD->hasAttr<CUDADeviceAttr>()) {
744-
FD->addAttr(CUDAHostAttr::CreateImplicit(Context));
745-
FD->addAttr(CUDADeviceAttr::CreateImplicit(Context));
746-
}
747-
}
748-
749733
// TODO: `__constant__` memory may be a limited resource for certain targets.
750734
// A safeguard may be needed at the end of compilation pipeline if
751735
// `__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
@@ -15974,9 +15974,6 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1597415974
if (FD && !FD->isDeleted())
1597515975
checkTypeSupport(FD->getType(), FD->getLocation(), FD);
1597615976

15977-
if (LangOpts.CUDA)
15978-
maybeAddCUDAHostDeviceAttrsToTrivialCtorDtor(FD);
15979-
1598015977
return dcl;
1598115978
}
1598215979

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)