Skip to content

Commit 8c85c82

Browse files
committed
pr-feedback
1 parent 1252466 commit 8c85c82

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

clang/lib/AST/Type.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5170,9 +5170,6 @@ bool Type::isHLSLIntangibleType() const {
51705170
CXXRecordDecl *RD = RT->getAsCXXRecordDecl();
51715171
assert(RD != nullptr &&
51725172
"all HLSL structs and classes should be CXXRecordDecl");
5173-
5174-
if (!RD->isCompleteDefinition())
5175-
return false;
51765173
assert(RD->isCompleteDefinition() && "expecting complete type");
51775174
return RD->isHLSLIntangible();
51785175
}

clang/lib/Sema/SemaDecl.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6900,6 +6900,16 @@ void Sema::deduceHLSLAddressSpace(VarDecl *Decl) {
69006900
if (Type->isSamplerT() || Type->isVoidType())
69016901
return;
69026902

6903+
// Template instantiations can lack definition. In such case,
6904+
// we cannot deduce the AS.
6905+
// FIXME: figure out why RWBuffer<float> yields such declaration.
6906+
if (const RecordType *RT =
6907+
dyn_cast<RecordType>(Type->getUnqualifiedDesugaredType())) {
6908+
CXXRecordDecl *RD = Type->getAsCXXRecordDecl();
6909+
if (RD && !RD->isCompleteDefinition())
6910+
return;
6911+
}
6912+
69036913
// Resource handles.
69046914
if (Type->isHLSLIntangibleType())
69056915
return;
@@ -7802,9 +7812,6 @@ NamedDecl *Sema::ActOnVariableDeclarator(
78027812
NewVD = VarDecl::Create(Context, DC, D.getBeginLoc(),
78037813
D.getIdentifierLoc(), II, R, TInfo, SC);
78047814

7805-
if (getLangOpts().HLSL)
7806-
deduceHLSLAddressSpace(NewVD);
7807-
78087815
// If this is supposed to be a variable template, create it as such.
78097816
if (IsVariableTemplate) {
78107817
NewTemplate =
@@ -7989,9 +7996,6 @@ NamedDecl *Sema::ActOnVariableDeclarator(
79897996
}
79907997
}
79917998

7992-
if (getLangOpts().HLSL)
7993-
deduceHLSLAddressSpace(NewVD);
7994-
79957999
// WebAssembly tables are always in address space 1 (wasm_var). Don't apply
79968000
// address space if the table has local storage (semantic checks elsewhere
79978001
// will produce an error anyway).
@@ -8007,8 +8011,11 @@ NamedDecl *Sema::ActOnVariableDeclarator(
80078011
// Handle attributes prior to checking for duplicates in MergeVarDecl
80088012
ProcessDeclAttributes(S, NewVD, D);
80098013

8010-
if (getLangOpts().HLSL)
8014+
if (getLangOpts().HLSL) {
80118015
HLSL().ActOnVariableDeclarator(NewVD);
8016+
deduceHLSLAddressSpace(NewVD);
8017+
}
8018+
80128019
if (getLangOpts().OpenACC)
80138020
OpenACC().ActOnVariableDeclarator(NewVD);
80148021

clang/test/AST/HLSL/private.hlsl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -ast-dump -o - %s | FileCheck %s
2+
3+
// CHECK: VarDecl {{.*}} global_scalar 'hlsl_private int' static cinit
4+
static int global_scalar = 0;
5+
6+
// CHECK: VarDecl {{.*}} global_buffer 'RWBuffer<float>':'hlsl::RWBuffer<float>' static callinit
7+
RWBuffer<float> global_buffer;
8+
9+
class A {
10+
// CHECK: VarDecl {{.*}} a 'hlsl_private int' static
11+
static int a;
12+
};
13+
14+
class B {
15+
// CHECK: VarDecl {{.*}} b 'hlsl_private int' static
16+
static int b;
17+
};
18+
19+
// CHECK: VarDecl {{.*}} b 'hlsl_private int' cinit
20+
int B::b = 0;
21+
22+
export void foo() {
23+
// CHECK: VarDecl {{.*}} local_buffer 'RWBuffer<float>':'hlsl::RWBuffer<float>' cinit
24+
RWBuffer<float> local_buffer = global_buffer;
25+
26+
// CHECK: VarDecl {{.*}} static_local_buffer 'RWBuffer<float>':'hlsl::RWBuffer<float>' static cinit
27+
static RWBuffer<float> static_local_buffer = global_buffer;
28+
29+
// CHECK: VarDecl {{.*}} local_scalar 'int' cinit
30+
int local_scalar = global_scalar;
31+
32+
// CHECK: VarDecl {{.*}} static_scalar 'hlsl_private int' static cinit
33+
static int static_scalar = 0;
34+
}

0 commit comments

Comments
 (0)