Skip to content

Commit aa35161

Browse files
authored
[SYCL] Ignore 'used' attribute when emitting sycl device code (#1729)
Signed-off-by: Premanand M Rao <[email protected]>
1 parent e0f59e3 commit aa35161

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10446,14 +10446,14 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
1044610446
if (D->hasAttr<WeakRefAttr>())
1044710447
return false;
1044810448

10449-
// Aliases and used decls are required.
10450-
if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>())
10451-
return true;
10452-
1045310449
if (LangOpts.SYCLIsDevice && !D->hasAttr<OpenCLKernelAttr>() &&
1045410450
!D->hasAttr<SYCLDeviceAttr>())
1045510451
return false;
1045610452

10453+
// Aliases and used decls are required.
10454+
if (D->hasAttr<AliasAttr>() || D->hasAttr<UsedAttr>())
10455+
return true;
10456+
1045710457
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
1045810458
// Forward declarations aren't required.
1045910459
if (!FD->doesThisDeclarationHaveABody())
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
2+
// Test that the 'used' attribute does not force the emission of globals on sycl device
3+
4+
// CHECK-NOT: @_ZN1hI1aE1iE
5+
// CHECK-NOT: @_ZGVN1hI1aE1iE
6+
// CHECK-NOT: @__dso_handle
7+
// CHECK-NOT: @llvm.global_ctors
8+
// CHECK-NOT: @llvm.used
9+
10+
// CHECK-NOT: {{.*}} void @_ZN1fI1aEC2Ev(%struct._ZTS1fI1aE.f* %this)
11+
12+
// CHECK-NOT: {{.*}} void @__cxx_global_var_init()
13+
// CHECK-NOT: {{.*}} void @_ZN1gD1Ev(%class._ZTS1g.g*) unnamed_addr #2
14+
// CHECK-NOT: {{.*}} i32 @__cxa_atexit(void (i8*)*, i8*, i8*)
15+
// CHECK-NOT: {{.*}} void @_ZN1fI1aEC1Ev(%struct._ZTS1fI1aE.f* %this)
16+
17+
struct a;
18+
class g {
19+
public:
20+
int c;
21+
~g();
22+
};
23+
template <class>
24+
class h {
25+
public:
26+
static const void k();
27+
static g i;
28+
};
29+
template <class j>
30+
const void h<j>::k() { i.c = 0; }
31+
template <class j>
32+
g h<j>::i;
33+
template <class>
34+
struct f { f() __attribute__((used)); };
35+
template <class j>
36+
f<j>::f() { h<j>::k(); }
37+
template struct f<a>;

0 commit comments

Comments
 (0)